Akka Http Client - Encoding issue

115 views
Skip to first unread message

Srinaath Thyagarajan

unread,
Sep 16, 2016, 11:56:16 AM9/16/16
to Akka User List

I am trying to invoke a Rest API using akka http client using below code.

            val httpRequest = HttpRequest(
              method  = HttpMethods.GET,


          uri ="https://example.com/customers/~/profiles/dj2bQryHPCj4IVrc48xTPD%2Bhswk%2FqNWx%2BLuUA0G2T6GLnyBVD6wC231IjgDBYJnt/preferences",

              headers = List(Accept(MediaRange(MediaTypes.`application/json`.withParams(Map("v""3")))),
                RawHeader("Content-Type", "application/json;v=3"),
                RawHeader("Api-Key", "XYZ")
              )
            )
Http().singleRequest(httpRequest, GatewayHelper.connectionContext)


Before the call goes out, when i check the httprequest.uri (through debugger), there is a partial uri decoding that is happening (%2B changed to +)      "https://example.com/customers/~/profiles/dj2bQryHPCj4IVrc48xTPD+hswk%2FqNWx+LuUA0G2T6GLnyBVD6wC231IjgDBYJnt/preferences"

Because of this the API is returning an error. Unfortunately, there are bunch or APIs that has this type of path variable . So not able to invoke using akka-http . 


I also tried setting the parsing mode to Relaxed hoping that it would not tamper the path variable, but it didnt help either.


 Uri.apply("https://example.com/customers/~/profiles/dj2bQryHPCj4IVrc48xTPD%2Bhswk%2FqNWx%2BLuUA0G2T6GLnyBVD6wC231IjgDBYJnt/preferences", Uri.ParsingMode.Relaxed)


So, Is there option where we can make akka no modify this before making the httprequest? 

André

unread,
Sep 19, 2016, 8:43:11 AM9/19/16
to Akka User List
Hi Srinaath,

does it work with 

  "https://example.com/customers/~/profiles/dj2bQryHPCj4IVrc48xTPD hswk%2FqNWx LuUA0G2T6GLnyBVD6wC231IjgDBYJnt/preferences"

?

Akka should replace the spaces with a "+" while a "+" as input will get encoded as "%2B".

HTH
André

Srinaath

Srinaath Thyagarjan

unread,
Sep 28, 2016, 9:30:51 AM9/28/16
to Akka User List
Hi Andre,

Thanks for your response. I will try that and see how that works.

Thanks,
Srinaath

André

unread,
Sep 30, 2016, 4:17:49 AM9/30/16
to Akka User List
Hi Srinaath,

I was wrong. There's no way to let the renderer produce such a URI on the wire. "+" doesn't get percent encoded and "%2b" gets double encoded as "%252b". See [1] for an explanation.

However, there's Raw-Request-Uri which you can use. See [2] for an example.


Cheers
André
Reply all
Reply to author
Forward
0 new messages