Skip to content

net/http: Inconsistent output with req.URL.RequestURI() #67666

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
namitaofficial22 opened this issue May 27, 2024 · 1 comment
Closed

net/http: Inconsistent output with req.URL.RequestURI() #67666

namitaofficial22 opened this issue May 27, 2024 · 1 comment

Comments

@namitaofficial22
Copy link

Go version

go1.22

Output of go env in your module/workspace:

Issue is seen in online editor of https://go.dev/play/.

What did you do?

Below program o/p is giving different o/p with calls to req.URL.RequestURI().
First time o/p is printing unescaped URL. But Second time call is giving escaped URL.
It should be consistent.

package main

import (
"fmt"
"net/http"
)

func main() {
// Get the full request URI
req, _ := http.NewRequest("GET", "http://example.com/a%2Fv", nil)
// Print the request URI
fmt.Println("Request URI: \n", req.URL.RequestURI())
req.URL.Path = "a%2Fv"
fmt.Println("After URI: \n", req.URL.RequestURI())
}

O/p:
Request URI:
/a%2Fv
After URI:
a%252Fv

What did you see happen?

Above sample program o/p is giving different o/p with calls to req.URL.RequestURI().
First time o/p is printing unescaped URL. But Second time call is giving escaped URL.
It should be consistent.

What did you expect to see?

Both the times calling req.URL.RequestURI() should provide same kind of URL(either escaped or unescaped).
O/p should be consistent.

O/p seen is:
Request URI:
/a%2Fv
After URI:
a%252Fv

@seankhliao
Copy link
Member

see the documentation for net/URL.URL for the expected format of the Path field.

closing as not a bug.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

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

2 participants