Skip to content

net/http: requests seem to ignore Host headers?  #29865

Closed
@toranger

Description

@toranger

What version of Go are you using (go version)?

go1.8.1 linux/amd64

What did you do?

net/http requests seem to ignore Host headers?
`package main

import "os"
import "net/http"

func main() {
req, _ := http.NewRequest("GET", "http://1.2.3.4", nil)
// I wish explicitly setting this Host header would take precedence
req.Header.Set("Host", "www.example.org")
req.Write(os.Stdout)
}
`

What did you expect to see?

I want to send to the stable nginx host, but not change the host header which different from the nginx host.

What did you see instead?

Example output:
GET / HTTP/1.1
Host: 1.2.3.4
User-Agent: Go http package
Before I go further, am I doing this correctly?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions