Skip to content

net/http: which not support FQDN url ( domain contains dot at the end ),it should be fixed  #67107

@zengyuxing007

Description

@zengyuxing007

Go version

go1.21.5

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GOOS='linux'
GOPATH='/root/go'
GOPROXY='https://goproxy.cn'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build391041608=/tmp/go-build -gno-record-gcc-switches'

What did you do?

package main
import (
    "bufio"
    "fmt"
    "net/http"
)
func main() {
    resp, err := http.Get("http://www.baidu.com./index.html")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    fmt.Println("Response status:", resp.Status)
    scanner := bufio.NewScanner(resp.Body)
    for i := 0; scanner.Scan() && i < 5; i++ {
        fmt.Println(scanner.Text())
    }
    if err := scanner.Err(); err != nil {
        panic(err)
    }

go run httpclient.go ,but it return 403 .

When we look at the requested http message we can see that the host field is populated with "www.baidu.com."

111.165.121.180.60696-220.181.038.150.00080: GET /index.html HTTP/1.1
Host: www.baidu.com.
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip
220.181.038.150.00080-111.165.121.180.60696: HTTP/1.1 403 Forbidden
Server: bfe
Date: Mon, 29 Apr 2024 10:50:30 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

What did you see happen?

Response status: 403 Forbidden

What did you expect to see?

http response 200

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