@@ -183,6 +183,8 @@ func (this *SignerSuite) TestSimple() {
183
183
this .Assert ().Equal (fakePath , this .lastRequest .URL .String ())
184
184
this .Assert ().Equal (userAgent , this .lastRequest .Header .Get ("User-Agent" ))
185
185
this .Assert ().Equal ("1.1 amppkg" , this .lastRequest .Header .Get ("Via" ))
186
+ this .Assert ().Equal (`host="example.com"` , this .lastRequest .Header .Get ("Forwarded" ))
187
+ this .Assert ().Equal ("example.com" , this .lastRequest .Header .Get ("X-Forwarded-Host" ))
186
188
this .Assert ().Equal (http .StatusOK , resp .StatusCode , "incorrect status: %#v" , resp )
187
189
this .Assert ().Equal (fmt .Sprintf (`google;v="%d"` , transformer .SupportedVersions [0 ].Max ), resp .Header .Get ("AMP-Cache-Transform" ))
188
190
this .Assert ().Equal ("nosniff" , resp .Header .Get ("X-Content-Type-Options" ))
@@ -272,6 +274,25 @@ func (this *SignerSuite) TestFetchSignWithForwardedRequestHeaders() {
272
274
this .Assert ().Equal (append (payloadPrefix .Bytes (), transformedBody ... ), exchange .Payload )
273
275
}
274
276
277
+ func (this * SignerSuite ) TestForwardedHost () {
278
+ urlSets := []util.URLSet {{
279
+ Sign : & util.URLPattern {[]string {"https" }, "" , this .httpHost (), stringPtr ("/amp/.*" ), []string {}, stringPtr ("" ), false , 2000 , nil },
280
+ Fetch : & util.URLPattern {[]string {"http" }, "" , this .httpHost (), stringPtr ("/amp/.*" ), []string {}, stringPtr ("" ), false , 2000 , boolPtr (true )},
281
+ }}
282
+ header := http.Header {
283
+ "AMP-Cache-Transform" : {"google" }, "Accept" : {"application/signed-exchange;v=" + accept .AcceptedSxgVersion },
284
+ "Forwarded" : {`host="www.example.com";for=192.0.0.1` },
285
+ "X-Forwarded-For" : {"192.0.0.1" },
286
+ "X-Forwarded-Host" : {"www.example.com" }}
287
+ this .getFRH (this .T (), this .new (urlSets ),
288
+ "/priv/doc?fetch=" + url .QueryEscape (this .httpURL ()+ fakePath )+
289
+ "&sign=" + url .QueryEscape (this .httpSignURL ()+ fakePath ),
290
+ "example.com" , header )
291
+
292
+ this .Assert ().Equal (`host="example.com"` , this .lastRequest .Header .Get ("Forwarded" ))
293
+ this .Assert ().Equal ("www.example.com,example.com" , this .lastRequest .Header .Get ("X-Forwarded-Host" ))
294
+ }
295
+
275
296
func (this * SignerSuite ) TestEscapeQueryParamsInFetchAndSign () {
276
297
urlSets := []util.URLSet {{
277
298
Sign : & util.URLPattern {[]string {"https" }, "" , this .httpHost (), stringPtr ("/amp/.*" ), []string {}, stringPtr (".*" ), false , 2000 , nil },
0 commit comments