Skip to content

net/http: miss host header when serve as forward proxy. #16265

Closed
@SunRunAway

Description

@SunRunAway
  1. What version of Go are you using (go version)?
    go version go1.6.2 darwin/amd64
  2. What operating system and processor architecture are you using?
    darwin/amd64
  3. What did you do?

run this program on local.

package main

import (
    "fmt"
    "net/http"
    "net/http/httputil"
)

func do(w http.ResponseWriter, req *http.Request) {
    fmt.Println("host header:", req.Host)
    b, _ := httputil.DumpRequest(req, false)
    fmt.Println(string(b))
}

func main() {
    http.HandleFunc("/", do)
    http.ListenAndServe(":12306", nil)
}

on another terminal, run:

curl -v 'http://www.qiniu.com/' -H 'Host: haha' -x 'http://localhost:12306'
*   Trying ::1...
* Connected to localhost (::1) port 12306 (#0)
> GET http://www.qiniu.com/ HTTP/1.1
> Host: haha
> User-Agent: curl/7.43.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 OK
< Date: Tue, 05 Jul 2016 04:02:27 GMT
< Content-Length: 0
< Content-Type: text/plain; charset=utf-8
< 
* Connection #0 to host localhost left intact
  1. What did you expect to see?

I ran sudo tcpdump -i any -A port 12306 and it prints

GET http://www.qiniu.com/ HTTP/1.1
Host: haha
User-Agent: curl/7.43.0
Accept: */*
Proxy-Connection: Keep-Alive

  1. What did you see instead?

the program prints

host header: www.qiniu.com
GET http://www.qiniu.com/ HTTP/1.1
Accept: */*
Proxy-Connection: Keep-Alive
User-Agent: curl/7.43.0


Is it right that host header should be haha

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