Closed glyphpoch closed 3 years ago
Okay looked into implementing this, turns out it's far from being simple. The http-types
crate is too smart and doesn't allow an empty Content-Type
in its Response
at all.
Might be able to configure the MockServer
itself to strip certain headers before the response is returned 😃.
Yeah, http-types
makes a lot of things "correct by construction" which is great for the general case but less so when you want to test a degenerate scenario 😛
We could add a method to remove a header on ResponseTemplate
if that makes it viable.
I don't think changes in ResponseTemplate
will have any effect. It produces a http_types::Response
. Tried removing the Content-Type
header on that response object in the ResponseTemplate::generate_response
function and it still falls back to application/octet-stream
😃. Might have missed something though...
At one point, in mock_server/hyper.rs
, headers are converted into hyper
compatible headers so could do something "smart" there. Seems quite hacky though.
That is borderline too hacky I'd say - maybe open an issue on http_types
to see if they know of a way to make it happen by manipulating the response?
Haha, thought it might be 😄.
These are some very niche tests that we have so it looks like the simplest solution will be to just use a separate mocking library for those. Closing this for now, but will check http-types
again.
Hello!
Any chance that setting the Content-Type header could be made optional? It would probably be enough if the
ResponseTemplate::set_body_raw
function would accept and be able to deal with anOption<&str>
, although that's a breaking change...Most HTTP servers do set the content type header these days but at the same time there's nothing really preventing them from omitting it. It'd be good to have a way of testing what the HTTP client does in such cirumstances.