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

Skip query param encoding? #605

Open
jeaye opened this issue Dec 28, 2021 · 3 comments
Open

Skip query param encoding? #605

jeaye opened this issue Dec 28, 2021 · 3 comments

Comments

@jeaye
Copy link
Contributor

jeaye commented Dec 28, 2021

I'm using css.gg to bring in CSS for icons, as mentioned here: https://github.com/astrit/css.gg#3-collection

Currently, I'm trying to port a query from HTML to CLJ. As an HTML stylesheet link, this works fine:

<link href='https://css.gg/css?=link|bulb' rel='stylesheet'>

Note that the | is not encoded to %7C. However, if I try this in clj-http, it's always encoded, which breaks the request, since css.gg is expecting the | separator.

I've tried these forms:

(clj-http.client/get "https://css.gg/css?=link|bulb") ; requests /?=link%7Cbulb
(clj-http.client/get "https://css.gg/css" {:query-params {"" "link|bulb"}}) ; requests /?=link%7Cbulb

It may appear to be working, if you try it, but that's only because it's returning the CSS for link alone. Since it's not seeing the |, it doesn't return the CSS for bulb. Finally, note that this works just fine with curl:

$ curl "https://css.gg/css?=link|bulb"

Can I do this with clj-http?

@jeaye
Copy link
Contributor Author

jeaye commented Dec 31, 2021

After some digging through the code and tinkering, I've found that, even if I disable the URL encoding, this will ultimately result in Java-related URI parsing errors.

(with-redefs [clj-http.client/url-encode-illegal-characters identity]
  (:body (clj-http.client/get "https://css.gg/css?=link|bulb")))

; eval (current-form): (with-redefs [clj-http.client/url-encode-illegal-c...
; (err) Execution error (URISyntaxException) at java.net.URI$Parser/fail (URI.java:2913).
; (err) Illegal character in query at index 24: https://css.gg/css?=link|bulb

So it could be that this just can't be done with the java.net classes.

EDIT: (URL. "https://css.gg/css?=link|bulb") works fine. Just not if you try to run it through a parser.

@krydos
Copy link

krydos commented Jul 14, 2022

hey @jeaye
just out of curiosity, did you try to use different separator like ,

(clj-http.client/get "https://css.gg/css?=link,bulb")

this one seems like returning what's expected.

I know it's undocumented feature but I just somehow happened to find it. /, \, . seems working too btw.

@jeaye
Copy link
Contributor Author

jeaye commented Jul 14, 2022

Oh, that's amazing. Thank you!

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