eskimor / servant-purescript

Translate servant API to purescript code, with the help of purescript-bridge.
BSD 3-Clause "New" or "Revised" License
105 stars 44 forks source link

If the Header content is a String, quotes are added #11

Closed lthms closed 8 years ago

lthms commented 8 years ago

Regarding the Header combinator, if its content is a String, Servant reads the raw string as far as I know. Hovewer, servant generated code call the settings encodeURLPieces (see https://github.com/eskimor/servant-purescript/blob/09548d56865c9f58b4e186e083fc923f34ac7f8f/src/Servant/PureScript/CodeGen.hs#L169)

The example uses gShow (or I think I saw gDefaultEncodeURLPieces or something), but gShow adds quotes to a string. My string is a token, so you guess it is not a good idea to mess with token content…

Do you have any idea on how we can fix that? One idée could be to add the ToHttpApiData type class to mimic Servant? Then change the Generic a => a -> String to the new typeclass? It might be less flexible, though.

Thanks by advance!

eskimor commented 8 years ago

Do I understand correctly: servant has an implementation for FromHttpApiData String/Text and it does not encode with quotes there? That sucks.

I don't use plain strings as headers but my own data types - there it is easy to implement parseHeader with jsonParseHeader which is compatible with servant-purescript's encoding.

You can use this workaround in the meantime (if appropriate), while I am trying to find a good fix for this problem.

eskimor commented 8 years ago

Should be fixed with version 3.0.1 of purescript-servant-support - please try and re-open if it does not work. Best regards, Robert

eskimor commented 8 years ago

Thank you for your bug report and have a pleasant stay.

lthms commented 8 years ago

Thanks! I had a look, I fear a similar issue might happen with other prim types such as Int, for instance. Anyway, I will try it as soon as I come back home.

eskimor commented 8 years ago

Numbers and bool should be fine. Here http-api-data is compatible with our JSON encoding. There is a default encoding for time, maybe and either which are incompatible - ok - I am going to need some more special cases.

eskimor commented 8 years ago

I added a corresponding issue: https://github.com/eskimor/purescript-servant-support/issues/2

lthms commented 8 years ago

Great! Thanks a lot for that, I will try to help if I find something else (:

lthms commented 8 years ago

Okay so now I have another issue. If my String contains a special character, such as / or +, they are translated into %20 or whatever (I do not remember the exact numbers).

I am still searching in the purescript-servant-support the reason of this.