-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
What version of Hugo are you using: hugo v0.109.0-47b12b83e636224e5e601813ff3e6790c191e371+extended windows/amd64 BuildDate=2022-12-23T10:38:11Z VendorInfo=gohugoio
Does this issue reproduce with the latest release : Yes
Hello,
I’m currently doing some work that requires me to change the user agent of the client used for resources.GetRemote
Unfortunately, it seems that I'm unable to modify the User-Agent
header, consider the following example:
{{ $opts := dict
"method" "get"
"headers" (dict
"Authorization" "test-header"
"User-Agent" "Mozilla/5.0"
)
}}
{{ with resources.GetRemote "https://127.0.0.1:8000" $opts }}
{{ . }}
{{ end }}
The server sees:
GET / HTTP/1.1
Host: 127.0.0.1:8000
User-Agent: Hugo Static Site Generator
Authorization: test-header
Accept-Encoding: gzip
From what I can read in remote.go#L98 it seems that addDefaultHeaders
is call first which sets the User-Agent
header to Hugo Static Site Generator
and then, addUserProvidedHeaders
is called.
This functions uses req.Header.Add
to add the header. The issue is that .Add
does not override an existing header. Wouldn't it be preferable to use .Set
which according to the documentation replaces any existing values associated with key
?
Samuel,