2

When I try and include a "/" by using %2F in http.NewRequest, it converts it back into "/" when it calls url.Parse(). Is there any way to prevent this? I tried converting the percent to %25, but it still doesn't work.

You can see it here: http://play.golang.org/p/YOnktREbbf

5
  • 1
    Why are you trying to have those remain as %2F -- what is your final use case? Commented Feb 15, 2015 at 2:05
  • @Dre My goal is to be able to use /'s in http.NewRequest. I just tried it to see if it would work with url.Parse(). It's supposed to serve as an ID for elasticsearch. ES unescapes it itself, just the golang side of things isn't working out for me. Commented Feb 15, 2015 at 2:23
  • It seems that as long as the data is inside an argument, it stays escaped: play.golang.org/p/m49q50JfGf -- I believe Go is actually doing the correct thing here. Commented Feb 15, 2015 at 3:50
  • ( Is that what you are trying to do? Or do you actually need to use it bare? ) Commented Feb 15, 2015 at 3:56
  • @ThunderCat I would've preferred not having to do that as the request is created in another library (elastigo). I only pass in the url. As a solution, I just wound up hashing the path as needed. Commented Feb 15, 2015 at 16:56

1 Answer 1

5

This is a flaw in the design of the Go standard library. It has been acknowledged (issue 3659), but they have decided not to fix it for backwards compatibility reasons.

Although it isn't fun, the best way is to build a URL using opaque. You can find documentation here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.