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

Impossible to specify "Content-Type: application/json;charset=utf-8" when using Http.jsonBody #75

Open
Janiczek opened this issue Jan 25, 2021 · 0 comments

Comments

@Janiczek
Copy link

I am developing a REPL-like application for the APL language. It uses UTF-8 characters and the server API requires me to specify the charset:

Content-Type: application/json;charset=utf-8

Otherwise I get output like:

      (+⌿÷≢),¯1+?1000 1000⍴2
NOT PERMITTED: Illegal token
      (+â �¿Ã ·â �¢), ¯1+?1000 1000 â �´2

(The last line shows the garbled output.)

I can't do

Http.request
    { method = "POST"
    , headers = [ Http.header "Content-Type" "application/json;charset=UTF-8" ]
    , url = "https://tryapl.org/Exec"
    , body = Http.jsonBody (encodeStateAndInput model.state model.input)
    , expect = Http.expectJson ReceivedResponse stateAndOutputDecoder
    , timeout = Nothing
    , tracker = Nothing
    }

because Http.jsonBody adds its own Content-Type header and this gets sent:

Content-Type: application/json;charset=UTF-8 application/json

I can't keep headers empty and send Content-Type: application/json since that will still result in the garbled output.

So far the only way to get out of this situation is to use stringBody instead of jsonBody and encode the JSON myself.

I believe the correct solution would be to check the Content-Type headers and use only the user-given one if there are multiple, instead of joining it and the jsonBody-given one into one string.

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

1 participant