Hi again,
I'm quite stressing the net/http package ;)
I have discovered that if I set a custom HTTP header to a request, and hit a 301/302/etc. redirect, those headers are not kept. Example code:
package main
import (
"log"
"net/http"
)
func main() {
client := &http.Client{}
if err != nil {
log.Fatalln(err)
}
req.Header.Set("User-Agent", "MSIE 5.15 (MacintoshOS 9)")
log.Println("User-Agent before redirect:", req.UserAgent())
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
log.Println("User-Agent after redirect:", resp.Request.UserAgent())
}
Output:
2012/03/31 14:43:02 User-Agent before redirect: MSIE 5.15 (MacintoshOS 9)
2012/03/31 14:43:02 User-Agent after redirect:
This is what I'm getting on my nginx access.log:
93.56.194.199 - - [31/Mar/2012:14:36:59 +0200] "GET /redirect HTTP/1.1" 301 185 "-" "MSIE 5.15 (MacintoshOS 9)"
As you can see the first request had my custom header, the second one did not.
If this looks like a bug to you, I'll open a report.
Stephane