mint icon indicating copy to clipboard operation
mint copied to clipboard

Reason phrase from status line ignored

Open sergiorjsd opened this issue 1 year ago • 2 comments

Hi!

To be fair I don't know why but an API that I am consuming is giving me some errors in the HTTP Status-Line at the Reason-Phrase.

Errors like this one: HTTP/1.1 400 05 Integer 12345678 exceeds maximum value of 9999999.

It's the first time I see this kind of thing and I suppose that it's not correct but I need to handle these kind of errors for my application.

To make my API requests I'm using Req and digging into the code to search for a solution I've found that it uses Finch and Mint at the end. Here is where I've found that the Reason-Phrase is parsed but also ignored at some point later.

Line where reason is present but ignored: https://github.com/elixir-mint/mint/blob/90ee9fdb27c0d52b374b8d689c54d8559b2bb57c/lib/mint/http1.ex#L647-L649

Should we propagate it? It's my first time here but I think I can make a PR if needed.

Thanks in advance!

sergiorjsd avatar Apr 22 '25 12:04 sergiorjsd

This would need digging into the HTTP/1.1 and HTTP/2 RFCs to know whether this conforms to standard or not. If it does, then we might want to introduce a new response type:

{:status_reason, response_ref, "..."}

However, to avoid issues in existing applications, we would need to make this optional IMO. We could have a new option for Mint.HTTP.connect:

optional_responses: [:status_reason]

The shape of this option would allow us to add additional optional responses in the future without having option bonanza.

@sergiorjsd would you have a chance to look into the RFCs for this? I don't have free cycles right now.

whatyouhide avatar Apr 22 '25 15:04 whatyouhide

Thanks for your quick response @whatyouhide

As I can see in the RFC 9112 for HTTP/1.1, the reason-phrase is optional.

The first line of a response message is the status-line, consisting of the protocol version, a space (SP), the status code, and another space and ending with an OPTIONAL textual phrase describing the status code.

status-line = HTTP-version SP status-code SP [ reason-phrase ]

For HTTP/2 in RFC 9113 I can't see anything referring referring to the status line. In RFC 7540 I'm seeing the start-line was deprecated in this version in favor of the pseudo headers.

sergiorjsd avatar Apr 22 '25 16:04 sergiorjsd

Hi guys, I've created a PR fixing this ☝🏻. Also, I wonder if returning structs/maps would've been better, instead of Keyword List. In that case, changes like these wouldn't be breaking maybe.

pkgodara avatar Oct 19 '25 11:10 pkgodara