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: Request.URL contains only path value when requested via http2 #68365

Closed
RandoMan70 opened this issue Jul 10, 2024 · 3 comments
Closed

Comments

@RandoMan70
Copy link

RandoMan70 commented Jul 10, 2024

Go version

go version go1.22.5 linux/amd64

Output of go env in your module/workspace:

O111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/xray/.cache/go-build'
GOENV='/home/xray/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/xray/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/xray/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/snap/go/10660'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/snap/go/10660/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/home/xray/tmp/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build996338008=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Sample program running on server:

package main

import (
    "fmt"
    "net/http"
)

type proxy struct {}

func (s *proxy) ServeHTTP(w http.ResponseWriter, req *http.Request) {
    fmt.Println("Requested URL:", req.URL.String())
    w.Write([]byte("OK"))
}

func main() {
    p := &proxy{}
    err := http.ListenAndServeTLS(":443", "r.fullchain.pem", "r.privkey.pem", p)
    if err != nil {
        panic("ListenAndServe")
    }
}

Then I using it as proxy with CURL:

curl -vvv --proxy-http2 -x https://example.server:443 http://remote.host/path
* Host example.server:443 was resolved.
* IPv6: (none)
* IPv4: 1.2.3.4
*   Trying 1.2.3.4:443...
* Connected to example.server (1.2.3.4) port 443
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_CHACHA20_POLY1305_SHA256 / X25519 / RSASSA-PSS
* ALPN: server accepted h2
* Proxy certificate:
*  subject: CN=example.server
*  start date: May 16 03:00:12 2024 GMT
*  expire date: Aug 14 03:00:11 2024 GMT
*  subjectAltName: host "example.server" matched cert's "example.server"
*  issuer: C=US; O=Let's Encrypt; CN=R3
*  SSL certificate verify ok.
*   Certificate level 0: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption
*   Certificate level 1: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption
*   Certificate level 2: Public key type RSA (4096/152 Bits/secBits), signed using sha256WithRSAEncryption
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* [HTTP/2] [1] OPENED stream for http://remote.host/path
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: http]
* [HTTP/2] [1] [:authority: remote.host]
* [HTTP/2] [1] [:path: /path]
* [HTTP/2] [1] [user-agent: curl/8.5.0]
* [HTTP/2] [1] [accept: */*]
> GET http://remote.host/path HTTP/2
> Host: remote.host
> User-Agent: curl/8.5.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
< HTTP/2 200 
< content-type: text/plain; charset=utf-8
< content-length: 2
< date: Wed, 10 Jul 2024 04:26:39 GMT
< 
* Connection #0 to host example.server left intact

What did you see happen?

Example program prints:

Requested URL: /path

What did you expect to see?

Example program expected to print:

Requested URL: http://remote.host/path
@seankhliao
Copy link
Member

looking at the curl logs:

* [HTTP/2] [1] OPENED stream for http://remote.host/path
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: http]
* [HTTP/2] [1] [:authority: remote.host]
* [HTTP/2] [1] [:path: /path]
* [HTTP/2] [1] [user-agent: curl/8.5.0]
* [HTTP/2] [1] [accept: */*]

and http2 debug logs

2024/07/10 15:48:25 http2: decoded hpack field header field ":method" = "GET"
2024/07/10 15:48:25 http2: decoded hpack field header field ":scheme" = "http"
2024/07/10 15:48:25 http2: decoded hpack field header field ":authority" = "remote.host"
2024/07/10 15:48:25 http2: decoded hpack field header field ":path" = "/path"
2024/07/10 15:48:25 http2: decoded hpack field header field "user-agent" = "curl/8.8.0"
2024/07/10 15:48:25 http2: decoded hpack field header field "accept" = "*/*"

I believe this is working as intended.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2024
@RandoMan70
Copy link
Author

@seankhliao , how can I extract these values in request handler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants