question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle encoding characters like `%^{}\|; for query parameters in HttpRoutes

See original GitHub issue

Description:

If we have to create route with some parameters, like:

case GET -> Root / "data" :? CodeQueryParam(code) +& ShowCurrentDataQueryParam(showCurrentData)

object ShowCurrentDataQueryParam extends OptionalQueryParamDecoderMatcher[Boolean]("showCurrentData")

object CodeQueryParam extends QueryParamDecoderMatcher[String]("code")

And call API with: http://localhost:8888/data?code=%&showCurrentData=true or http://localhost:8888/data?code=111111&showCurrentData=^

We receive 400 Bad Request with no message.

Expected result: Handle this characters properly or receive corresponding message

Actual result: 400 Bad Request with no message

Version: 1.0.0-M5

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sloshycommented, Jan 12, 2021

I left a comment here originally about a separate but similar issue, and realized it would make more sense in a new issue (#4203), sorry for any inconvenience 🙏 it’s deleted now.

1reaction
rossabakercommented, Dec 29, 2020

The valid characters are alphanumerics and: / ? : @ - . _ ~ ! $ & ' ( ) * + , ; =. Everything else needs to be percent-encoded to make a valid URI.

It’s the backends that are rejecting this.

  • Blaze just gives a 400 without explanation. We can do better here, and I’ll leave the ticket open for that.
  • Jetty lets it through to Http4sServlet, which responds with an “Invalid request target” message in the body of the 400.
  • Tomcat intercepts it and gives a (dangerously, IMO) detailed message including information from the request and a stack trace before http4s ever sees it.

Even if the http4s parser got more lenient, many servers won’t, so I’d urge you to fix the requests. But we’ll make Blaze at least as informative as Jetty here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I include special characters in query strings?
You have to encode special characters in URLs. ... You need to encode the query parameters before combining them to form a url....
Read more >
Using URL encoding to handle special characters in a ...
Consider the example where a parameter is supplied in a URL and parameter value has a special character in it, such as,.
Read more >
Unleashing the Power of HTTP Apis: The Http4s Library
Through the DSL, we build an HttpRoutes[F] using pattern matching as a sequence of ... If we have to handle more than one...
Read more >
The http4s DSL
The central concept of http4s-dsl is pattern matching. An HttpService[F] is declared as a simple series of case statements. Each case statement ...
Read more >
Using Special Characters in Query String - Caspio Online Help
This issue can be avoided by encoding the special characters using Caspio Calculated Field before using them in Query String. Prerequisites:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found