@@ -68,12 +68,14 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
68
68
if h .NextArg () {
69
69
hasArgs = true
70
70
field := h .Val ()
71
- var value , replacement string
71
+ var value string
72
+ var replacement * string
72
73
if h .NextArg () {
73
74
value = h .Val ()
74
75
}
75
76
if h .NextArg () {
76
- replacement = h .Val ()
77
+ arg := h .Val ()
78
+ replacement = & arg
77
79
}
78
80
err := applyHeaderOp (
79
81
handler .Response .HeaderOps ,
@@ -106,12 +108,14 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
106
108
// https://caddy.community/t/v2-reverse-proxy-please-add-cors-example-to-the-docs/7349/19
107
109
field = strings .TrimSuffix (field , ":" )
108
110
109
- var value , replacement string
111
+ var value string
112
+ var replacement * string
110
113
if h .NextArg () {
111
114
value = h .Val ()
112
115
}
113
116
if h .NextArg () {
114
- replacement = h .Val ()
117
+ arg := h .Val ()
118
+ replacement = & arg
115
119
}
116
120
117
121
handlerToUse := handler
@@ -170,12 +174,14 @@ func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue,
170
174
// https://caddy.community/t/v2-reverse-proxy-please-add-cors-example-to-the-docs/7349/19
171
175
field = strings .TrimSuffix (field , ":" )
172
176
173
- var value , replacement string
177
+ var value string
178
+ var replacement * string
174
179
if h .NextArg () {
175
180
value = h .Val ()
176
181
}
177
182
if h .NextArg () {
178
- replacement = h .Val ()
183
+ arg := h .Val ()
184
+ replacement = & arg
179
185
if h .NextArg () {
180
186
return nil , h .ArgErr ()
181
187
}
@@ -200,15 +206,15 @@ func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue,
200
206
// field, value, and replacement. The field can be prefixed with
201
207
// "+" or "-" to specify adding or removing; otherwise, the value
202
208
// will be set (overriding any previous value). If replacement is
203
- // non-empty , value will be treated as a regular expression which
209
+ // non-nil , value will be treated as a regular expression which
204
210
// will be used to search and then replacement will be used to
205
211
// complete the substring replacement; in that case, any + or -
206
212
// prefix to field will be ignored.
207
- func CaddyfileHeaderOp (ops * HeaderOps , field , value , replacement string ) error {
213
+ func CaddyfileHeaderOp (ops * HeaderOps , field , value string , replacement * string ) error {
208
214
return applyHeaderOp (ops , nil , field , value , replacement )
209
215
}
210
216
211
- func applyHeaderOp (ops * HeaderOps , respHeaderOps * RespHeaderOps , field , value , replacement string ) error {
217
+ func applyHeaderOp (ops * HeaderOps , respHeaderOps * RespHeaderOps , field , value string , replacement * string ) error {
212
218
switch {
213
219
case strings .HasPrefix (field , "+" ): // append
214
220
if ops .Add == nil {
@@ -238,7 +244,7 @@ func applyHeaderOp(ops *HeaderOps, respHeaderOps *RespHeaderOps, field, value, r
238
244
}
239
245
respHeaderOps .Set .Set (field , value )
240
246
241
- case replacement != "" : // replace
247
+ case replacement != nil : // replace
242
248
// allow defer shortcut for replace syntax
243
249
if strings .HasPrefix (field , ">" ) && respHeaderOps != nil {
244
250
respHeaderOps .Deferred = true
@@ -251,7 +257,7 @@ func applyHeaderOp(ops *HeaderOps, respHeaderOps *RespHeaderOps, field, value, r
251
257
ops .Replace [field ],
252
258
Replacement {
253
259
SearchRegexp : value ,
254
- Replace : replacement ,
260
+ Replace : * replacement ,
255
261
},
256
262
)
257
263
0 commit comments