req icon indicating copy to clipboard operation
req copied to clipboard

No way to force encoding of a segment

Open singpolyma opened this issue 1 year ago • 1 comments

I'm talking to an HTTP service which requires + in path segments to be encoded. I tried to do this:

newtype RawURLPiece = RawURLPiece Text                                                                                                                                       
                                                                                                                                                                             
instance ToHttpApiData RawURLPiece where                                                                                                                                     
  toUrlPiece (RawURLPiece txt) = txt                                                                                                                                         
  toEncodedUrlPiece (RawURLPiece txt) = byteString $ encodeUtf8 txt                                                                                                          
  toQueryParam (RawURLPiece txt) = txt                                                                                                                                       
  toEncodedQueryParam (RawURLPiece txt) = byteString $ encodeUtf8 txt 

But this still results in the %5B being encoded to %255B if I put it in manually, and of course the library does not encode + to %5B by default. What would you suggest?

singpolyma avatar May 29 '24 01:05 singpolyma

With respect to escaping we depend on encodePathSegments from http-types:

https://github.com/mrkkrp/req/blob/master/Network/HTTP/Req.hs#L1212

It does not encode +. There seems to be no solution short of using reqCb and patching paths at that level.

mrkkrp avatar May 30 '24 09:05 mrkkrp