Skip to content

net/http: Proto when set is not used properly.  #13985

Closed
@harshavardhana

Description

@harshavardhana

For example even after setting request Proto has no affect on how http.Client sends request, it always defaults to. 'HTTP/1.1'

$ cat http-test.go
package main

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

func main() {
    req, err := http.NewRequest("GET", "https://www.google.com", nil)
    if err != nil {
        log.Fatalln(err)
    }
    req.Proto = "HTTP/1.0"
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        log.Fatalln(err)
    }
    reqTrace, err := httputil.DumpRequestOut(req, false)
    if err != nil {
        log.Fatalln(err)
    }
    respTrace, err := httputil.DumpResponse(resp, false)
    if err != nil {
        log.Fatalln(err)
    }
    fmt.Println(string(reqTrace))
    fmt.Println(string(respTrace))
}
$ go run http-test.go
GET / HTTP/1.1
Host: www.google.com
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip


HTTP/1.1 200 OK
Transfer-Encoding: chunked
Alt-Svc: quic="www.google.com:443"; ma=600; v="30,29,28,27,26,25",quic=":443"; ma=600; v="30,29,28,27,26,25"
Alternate-Protocol: 443:quic,p=1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Date: Sun, 17 Jan 2016 10:08:59 GMT
Expires: -1
P3p: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
Server: gws
Set-Cookie: NID=75=OeIomPif8UPzAt2QI2qzIOeqiJo4jvQRmsKjBHWDpaXwDGizQB5lAxi0Lb3Dw_5sCeWvZmccGoZER2Pj3zuvY2PI982WCxDQBhU62CW1cZUmMqUNeT5vv5tDA1g_646320jRqqcKxFSuQCg; expires=Mon, 18-Jul-2016 10:08:59 GMT; path=/; domain=.google.com; HttpOnly
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block

Now testing with .Proto as 'HTTP/2.0' defaults to 'HTTP/1.1'

$ cat http-test.go
package main

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

func main() {
    req, err := http.NewRequest("GET", "https://www.google.com", nil)
    if err != nil {
        log.Fatalln(err)
    }
    req.Proto = "HTTP/2.0"
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        log.Fatalln(err)
    }
    reqTrace, err := httputil.DumpRequestOut(req, false)
    if err != nil {
        log.Fatalln(err)
    }
    respTrace, err := httputil.DumpResponse(resp, false)
    if err != nil {
        log.Fatalln(err)
    }
    fmt.Println(string(reqTrace))
    fmt.Println(string(respTrace))
}
$ go run http-test.go
GET / HTTP/1.1
Host: www.google.com
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip


HTTP/1.1 200 OK
Transfer-Encoding: chunked
Alt-Svc: quic="www.google.com:443"; ma=600; v="30,29,28,27,26,25",quic=":443"; ma=600; v="30,29,28,27,26,25"
Alternate-Protocol: 443:quic,p=1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Date: Sun, 17 Jan 2016 10:11:35 GMT
Expires: -1
P3p: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
Server: gws
Set-Cookie: NID=75=zVFTFbi8WLNy04TQUSBVFJ6ioFJs-YUrYLI3Js2dZ8cIoiBLLcxAnOOd4REY9Lns3TPZtPjXE5Cdb7C40vqk4HnbDWdSkSp3j0mMc1Z83pFWR22KMvJcofKJJjOVeKv9GZsJ66MRF1vlxGQ; expires=Mon, 18-Jul-2016 10:11:35 GMT; path=/; domain=.google.com; HttpOnly
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block

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