Skip to content

url/URL: problem with the leading slash of the Path property #27352

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

Closed
ilyabakhlin opened this issue Aug 29, 2018 · 4 comments
Closed

url/URL: problem with the leading slash of the Path property #27352

ilyabakhlin opened this issue Aug 29, 2018 · 4 comments

Comments

@ilyabakhlin
Copy link

ilyabakhlin commented Aug 29, 2018

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

$ /c/Go/bin/go.exe version
go version go1.10.2 windows/amd64

Does this issue reproduce with the latest release?

Yes.

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

$ /c/Go/bin/go.exe env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Ilya Bakhlin\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Ilya Bakhlin\go
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ILYABA~1\AppData\Local\Temp\go-build236770806=/tmp/go-build -gno-record-gcc-switches

What did you do?

I've created a simple HTTP POST request with the *http.Client, *http.Request and *url.URL structures. The whole script is represented here.

If you read it, everything should be working, but it's not. I've figured out the problem resides in the *url.URL's Path property - according to the official documentation, whenever the Path is defined, the leading slash (/) is not necessary. But, if you add it in the script, it will work.

What did you expect to see?

{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a key value"}

What did you see instead?

<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>
@ilyabakhlin ilyabakhlin changed the title Problem with the Leading Slash of the url.URL structure's Path Property url/URL: problem with the leading slash of the Path property Aug 29, 2018
@fraenkel
Copy link
Contributor

The docs say that the leading slash may be omitted for relative URLs. What you have is an absolute URL since you are providing a scheme and host.

@ilyabakhlin
Copy link
Author

I've just checked the documentation, and there's nothing explaining something like that.

Maybe the problem is how the documentation is redacted. The only clear thing is that it leads to misunderstanding.

@fraenkel
Copy link
Contributor

The two places I read were:
https://golang.org/pkg/net/url/#URL
https://golang.org/pkg/net/url/#Parse

If you have suggestions to improve this, please submit a documentation change.

@ilyabakhlin
Copy link
Author

Well... I guess I'm wrong.

@golang golang locked and limited conversation to collaborators Aug 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants