lipanski / mockito

HTTP mocking for Rust!
MIT License
687 stars 59 forks source link

Allow unsetting content-length #152

Closed MaeIsBad closed 1 year ago

MaeIsBad commented 1 year ago

https://github.com/lipanski/mockito/issues/52 allows users to set a content-length, it doesn't seem like there is a way not to set it at all, without using with_body_from_fn to respond with chunked encoding.

Overwriting the content-length with an empty string might not work depending on the client. For example hyper rejects all responses with an invalid content-length header(https://github.com/hyperium/hyper/blob/8790fee74937016e6b288493bc62c61f7866c310/src/proto/h1/role.rs#L256)

lipanski commented 1 year ago

@MaeIsBad can you provide more details about what you are trying to achieve? is this specifically about HEAD requests?

MaeIsBad commented 1 year ago

I want to ensure that some download limiting code works even if the content-length is unknown and transfer-encoding is not chunked. This is technically not allowed by the http spec afaik but it is accepted by most clients, which could easily lead to weird hard to debug bugs. For my use case chunked encoding is good enough, but I struggled a bit before realizing I could use it and I think that allowing mockito to send requests without a content-length might be useful.

lipanski commented 1 year ago

@MaeIsBad thanks for the explanation. I don't have plans to support this in the near future since misusing this header can have nasty side-effects (as you said, it can lead to weird hard to debug bugs). I hope you find some other way to test this.

MaeIsBad commented 1 year ago

Understandable, thank you