Repository: cloudflare/cloudflare-go
Pull request #1376 (2023-08-25 16:57:48)

Add support for controlling Origin Cache Control from Rulesets API
<!-- 
Provide a general summary of your changes in the title above. You should
remove this overview, any sections and any section descriptions you
don't need below before submitting. There isn't a strict requirement to
use this template if you can structure your description and still cover
these points. 
-->

## Description

Adds support for the usage of the `read_timeout` field which has been added to the rulesets API. This allows zone to control the use of an RFC compliant version of nginx-cache.

<!--
Describe your changes in detail through motivation and context. Why is
this change required? What problem does it solve? If it fixes an open
issue, link to the issue using GitHub's closing issues keywords[1].
-->
## Has your change been tested?

Thorough testing via the API, modifications to unit tests included for the library

<!--
Explain how the change has been tested and what you ran to confirm your
change affects other parts of the code. Automated tests are generally
expected and changes without tests should explain why they aren't
required.
-->

## Screenshots (if appropriate):

## Types of changes

What sort of change does your code introduce/modify?

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [ ] This change is using publicly documented in [cloudflare/api-schemas](https://github.com/cloudflare/api-schemas) 
      and relies on stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/



Patch:
diff --git a/.changelog/1376.txt b/.changelog/1376.txt
new file mode 100644
index 000000000..d2881fce3
--- /dev/null
+++ b/.changelog/1376.txt
@@ -0,0 +1,3 @@
+```release_note:enhancement
+rulesets: Add support for Origin Cache Control configuration via the Rulesets/Cache Rules API
+```
\ No newline at end of file
diff --git a/rulesets.go b/rulesets.go
index 92cc252da..cfa725aa8 100644
--- a/rulesets.go
+++ b/rulesets.go
@@ -234,6 +234,7 @@ type RulesetRuleActionParameters struct {
 	StatusCode              uint16                                            `json:"status_code,omitempty"`
 	RespectStrongETags      *bool                                             `json:"respect_strong_etags,omitempty"`
 	CacheKey                *RulesetRuleActionParametersCacheKey              `json:"cache_key,omitempty"`
+	OriginCacheControl      *bool                                             `json:"origin_cache_control,omitempty"`
 	OriginErrorPagePassthru *bool                                             `json:"origin_error_page_passthru,omitempty"`
 	FromList                *RulesetRuleActionParametersFromList              `json:"from_list,omitempty"`
 	FromValue               *RulesetRuleActionParametersFromValue             `json:"from_value,omitempty"`


Test patch:
diff --git a/rulesets_test.go b/rulesets_test.go
index 18cdd9648..91c269f1f 100644
--- a/rulesets_test.go
+++ b/rulesets_test.go
@@ -241,6 +241,7 @@ func TestGetRuleset_SetCacheSettings(t *testing.T) {
 						}
 					}
 				},
+				"origin_cache_control": true,
 				"read_timeout": 1000,
 				"origin_error_page_passthru":true
 			},
@@ -325,6 +326,7 @@ func TestGetRuleset_SetCacheSettings(t *testing.T) {
 					},
 				},
 			},
+			OriginCacheControl:      BoolPtr(true),
 			ReadTimeout:             UintPtr(1000),
 			OriginErrorPagePassthru: BoolPtr(true),
 		},