Skip to content
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

Support query parameters without encoding #797

Closed
yangzhiw opened this issue May 16, 2024 · 8 comments · Fixed by #885
Closed

Support query parameters without encoding #797

yangzhiw opened this issue May 16, 2024 · 8 comments · Fixed by #885
Assignees
Labels
feature v2 For resty v2
Milestone

Comments

@yangzhiw
Copy link

When calling the SetQueryParam method, the request request will encode the query in the URL, for example: registry=nacos://test:6801, which will be encoded as: registry=nacos%3A%2F%2Ftest%3A6801; is there any way? To set query parameters without encoding, for example: SetQueryEscape(false)

@jeevatkm
Copy link
Member

@yangzhiw Thanks for reaching out.
Without query escape, the URL may become broken. It is not recommended to do that. Ideally, the application/service endpoint receiving this parameter should unescape first before using it.

@ahuigo
Copy link
Contributor

ahuigo commented Jun 14, 2024

try to put unencoded query to url like this:

	url := ts.URL + "/post?un-escape=nacos://test:6801"
	resp, err := req.
		EnableTrace().
		SetQueryParams(map[string]string{
			"escape":"nacos://test:6801",
		}).
		Post(url)

//  curl -X POST 'http://127.0.0.1:51301/post?unescape=nacos://test:6801&escape=nacos%3A%2F%2Ftest%3A6801'

@antixcode6
Copy link

This is unfortunately something I have ran into recently as well.

Ideally, the application/service endpoint receiving this parameter should unescape first before using it

While I agree that they should Some APIs that I've been trying to consume recently refuse to un-encode the request on their end and will only accept raw, unencoded, query params. I believe giving the package consumer/programmer the option to decide this behavior makes more sense than relying on the service (which we most likely have no control over) to do the right thing.

@jeevatkm
Copy link
Member

@antixcode6 I will add it in v3

@takanuva15
Copy link

I am interested in this functionality as well since I'm dealing with legacy servers that cannot handle escaped query parameters at the moment. Can we add a function SetEscapeQueryParams(bool b) into v2 just like we have SetJSONEscapeHTML currently? This would really help improve the flexibility of the client for different requests

@jeevatkm
Copy link
Member

@takanuva15 Is it an urgent need? As you can see, I marked this issue for v3, which is currently in development.

@takanuva15
Copy link

@jeevatkm no it's not urgent; thanks for your quick reply

@jeevatkm
Copy link
Member

@yangzhiw @antixcode6 @takanuva15 - I have implemented this in Resty v2, in the branch unescape-query-params. Can you try and share your testing feedback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature v2 For resty v2
Development

Successfully merging a pull request may close this issue.

5 participants