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

Content type not set correctly for .badRequest case #345

Open
jerbeers opened this issue Oct 23, 2018 · 2 comments
Open

Content type not set correctly for .badRequest case #345

jerbeers opened this issue Oct 23, 2018 · 2 comments
Labels

Comments

@jerbeers
Copy link

If I have a test that needs to send a body with a .badRequest response, the content-type header is not set correctly. The headers() method on HttpResponse should evaluate the body of .badRequest the same way it does for .ok. It's a bit complicated by the fact that the associated data for .ok is not optional and .badRequest is optional, but if badRequest does have a body, it should be handled the same way.

@Vkt0r
Copy link
Member

Vkt0r commented Oct 24, 2018

You can always use the HttpResponse.raw and provide your own Headers. See the following example:

let statusCode = 400
let reasonPhrase = "Bad Request"
let headers = ["Content-Type": "application/json"]

let response =  HttpResponse.raw(statusCode, reasonPhrase , headers,  { writer in
    // jsonData represent your JSON string to return converted to `Data` 
    // or any other implementing `HttpResponseBodyWriter`
    try writer.write(jsonData)
})

@Vkt0r Vkt0r added the question label Oct 24, 2018
@jerbeers
Copy link
Author

Yeah, I used that as a workaround, but it still seems like the code should automatically handle the header correctly, so I filed the issue. Thanks!

@Vkt0r Vkt0r pinned this issue Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants