Skip to content

proposal: net/http: increase verbosity of unsuccessful proxy CONNECT request #40873

@maxifom

Description

@maxifom

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

$ go version
go version go1.15 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/max/.cache/go-build"
GOENV="/home/max/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/max/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/max/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/max/go/src/www_https_detector/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build124294710=/tmp/go-build -gno-record-gcc-switches"

What did you do?

So in my environment http://antipa.hiblogger.net redirects to https://www.obozrevatel.com/blogs/

When I use direct connect without proxy, its working fine.

With Proxy it got intercepted with 302 (full response in Additional info) to my provider ban page http://blacklist.miralogic.ru and all I see in the error is "Found".

My code
package main

import (
	"net/http"
	"net/url"
)

func main() {
	// omitted my user and pass for proxy
	u, _ := url.Parse("http://<omitted>:<omitted>@zproxy.lum-superproxy.io:22225")

	c := &http.Client{
		Transport: &http.Transport{
			Proxy:             http.ProxyURL(u),
		},
	}

	_, err := c.Get("http://antipa.hiblogger.net")
	panic(err)
}

What did you expect to see?

I suggest to change the error in

return nil, errors.New(f[1])

and
return nil, errors.New("unknown status code")

from errors.New with Status Text to something more verbose to better understand the nature of the problem (It's a proxy CONNECT error).

Maybe there should be something like net.OpError like in

return &net.OpError{Op: "proxyconnect", Net: "tcp", Err: err}
?

What did you see instead?

Output:

panic: Get "https://www.obozrevatel.com/blogs/": Found

Additional info

Response from CONNECT response (variable resp in dialConn function

func (t *Transport) dialConn(ctx context.Context, cm connectMethod) (pconn *persistConn, err error) {
)

{
    "resp": {
        "Status": "302 Found",
        "StatusCode": 302,
        "Proto": "HTTP/1.1",
        "ProtoMajor": 1,
        "ProtoMinor": 1,
        "Header": {
            "Location": "http://blacklist.miralogic.ru",
            "Content-Type": "text/html; charset=utf-8",
            "Content-Length": 146
        },
        "Body": "<omitted>",
        "ContentLength": 146,
        "TransferEncoding": null,
        "Close": false,
        "Trailer": null,
        "Request": {
            "Method": "CONNECT",
            "URL": {
                "Scheme": "",
                "Opaque": "www.obozrevatel.com:443",
                "User": null,
                "Host": "",
                "Path": "",
                "RawPath": "",
                "ForceQuery": false,
                "RawQuery": "",
                "Fragment": "",
                "RawFragment": ""
            },
            "Proto": "",
            "ProtoMajor": 0,
            "ProtoMinor": 0,
            "Header": {
                "Proxy-Authorization": "Basic <omitted>"
            },
            "Body": "<omitted>",
            "GetBody": null,
            "ContentLength": 0,
            "TransferEncoding": null,
            "Close": false,
            "Host": "www.obozrevatel.com:443",
            "Form": null,
            "PostForm": null,
            "MultipartForm": null,
            "Trailer": null,
            "RemoteAddr": "",
            "RequestURI": "",
            "TLS": null,
            "Cancel": null,
            "Response": null,
            "ctx": null
        },
        "TLS": null
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions