-
Notifications
You must be signed in to change notification settings - Fork 6
/
PR1750.diff
87 lines (85 loc) · 2.48 KB
/
PR1750.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--- a/src/ngx_pagespeed.cc 2022-07-19
+++ b/src/ngx_pagespeed.cc 2022-07-20
@@ -393,6 +396,35 @@
//
// Based on ngx_http_add_cache_control.
ngx_int_t ps_set_cache_control(ngx_http_request_t* r, char* cache_control) {
+#if defined(nginx_version) && nginx_version >= 1023000
+ ngx_table_elt_t* cc = r->headers_out.cache_control;
+
+ if (cc == NULL) {
+
+ cc = reinterpret_cast<ngx_table_elt_t*>(ngx_list_push(&r->headers_out.headers));
+ if (cc == NULL) {
+ return NGX_ERROR;
+ }
+
+ r->headers_out.cache_control = cc;
+ cc->next = NULL;
+
+ cc->hash = 1;
+ ngx_str_set(&cc->key, "Cache-Control");
+
+ } else {
+ for (cc = cc->next; cc; cc = cc->next) {
+ cc->hash = 0;
+ }
+
+ cc = r->headers_out.cache_control;
+ cc->next = NULL;
+ }
+ cc->value.len = strlen(cache_control);
+ cc->value.data =
+ reinterpret_cast<u_char*>(cache_control);
+
+#else
// First strip existing cache-control headers.
ngx_table_elt_t* header;
NgxListIterator it(&(r->headers_out.headers.part));
@@ -402,7 +434,6 @@
header->hash = 0;
}
}
-
// Now add our new cache control header.
if (r->headers_out.cache_control.elts == NULL) {
ngx_int_t rc = ngx_array_init(&r->headers_out.cache_control, r->pool,
@@ -426,7 +457,7 @@
cache_control_headers[0]->value.len = strlen(cache_control);
cache_control_headers[0]->value.data =
reinterpret_cast<u_char*>(cache_control);
-
+#endif
return NGX_OK;
}
@@ -436,6 +467,23 @@
// Use headers_out.cache_control instead of looking for Cache-Control in
// headers_out.headers, because if an upstream sent multiple Cache-Control
// headers they're already combined in headers_out.cache_control.
+#if defined(nginx_version) && nginx_version >= 1023000
+ ngx_table_elt_t* cc = r->headers_out.cache_control;
+ bool first_segment = true;
+
+ while (cc != NULL) {
+ if (cc->hash) {
+ if (first_segment) {
+ first_segment = false;
+ } else {
+ cache_control->append(", ");
+ }
+ cache_control->append(reinterpret_cast<char*>(cc->value.data),
+ cc->value.len);
+ }
+ cc = cc->next;
+ }
+#else
auto ccp = static_cast<ngx_table_elt_t**>(r->headers_out.cache_control.elts);
if (ccp == nullptr) {
return false; // Header not present.
@@ -453,6 +501,7 @@
cache_control->append(reinterpret_cast<char*>(ccp[i]->value.data),
ccp[i]->value.len);
}
+#endif
return true;
}