Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
toranger opened this issue Jan 22, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@toranger
Copy link

commented Jan 22, 2019

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?

@agnivade

This comment has been minimized.

Copy link
Member

commented Jan 22, 2019

Set the Host field in https://golang.org/pkg/net/http/#Request to override the host value in the URL.

@cuonglm

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2019

Host header is ignored by Request.Write

// Headers that Request.Write handles itself and should be skipped.

@toranger

This comment has been minimized.

Copy link
Author

commented Jan 22, 2019

Set the Host field in https://golang.org/pkg/net/http/#Request to override the host value in the URL.

Set the Host field in https://golang.org/pkg/net/http/#Request to override the host value in the URL.
The scene is that I want to send the request with the s3 bucket host such like "BucketName.s3.amazonaws.com" , and send this message to the server which has nginx front which set the location such like "location ~ ^(/test/)(.*)$ ".
I can change the host header by your way, but can not send to the special program on server

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 22, 2019

@bradfitz bradfitz closed this Jan 22, 2019

@mikioh mikioh changed the title net/http requests seem to ignore Host headers? net/http: requests seem to ignore Host headers? Feb 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.