mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
resources: Add responseHeaders option to resources.GetRemote
* These response headers will be included in `.Data.Headers` if found. * The header name matching is case insensitive. * `Data.Headers` is of type `map[string][]string` * In most cases there will be only one value per header key, but e.g. `Set-Cookie` commonly has multiple values. Fixes #12521
This commit is contained in:
@@ -56,7 +56,42 @@ func TestGetRemoteHead(t *testing.T) {
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
"Head Content: .",
|
||||
"Head Data: map[ContentLength:18210 ContentType:image/png Status:200 OK StatusCode:200 TransferEncoding:[]]",
|
||||
"Head Data: map[ContentLength:18210 ContentType:image/png Headers:map[] Status:200 OK StatusCode:200 TransferEncoding:[]]",
|
||||
)
|
||||
}
|
||||
|
||||
func TestGetRemoteResponseHeaders(t *testing.T) {
|
||||
files := `
|
||||
-- config.toml --
|
||||
[security]
|
||||
[security.http]
|
||||
methods = ['(?i)GET|POST|HEAD']
|
||||
urls = ['.*gohugo\.io.*']
|
||||
-- layouts/index.html --
|
||||
{{ $url := "https://gohugo.io/img/hugo.png" }}
|
||||
{{ $opts := dict "method" "head" "responseHeaders" (slice "X-Frame-Options" "Server") }}
|
||||
{{ with try (resources.GetRemote $url $opts) }}
|
||||
{{ with .Err }}
|
||||
{{ errorf "Unable to get remote resource: %s" . }}
|
||||
{{ else with .Value }}
|
||||
Response Headers: {{ .Data.Headers }}
|
||||
{{ else }}
|
||||
{{ errorf "Unable to get remote resource: %s" $url }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
},
|
||||
)
|
||||
|
||||
b.Build()
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
"Response Headers: map[Server:[Netlify] X-Frame-Options:[DENY]]",
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user