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

Allow no SP after status-code for HTTP/1.x responses #2247

Merged
merged 1 commit into from
Jun 9, 2022

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

While RFC7230, section 3.1.2
(https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2) requires a
SP before a reason-phrase, even if it's an empty phrase, many
implementations don't include that SP character. Many clients parse a
response without trailing SP character with no error. Those
implementations are:

Moreover, neither HTTP/2 nor HTTP/3 support reason-phrase. For this
reasons, many HTTP/1.x implementations (Tomcat, Rust, etc.) decided to
drop including the reason-phrase in serialized response for performance
reasons. Instead, they use the reason-phrase defined by RFC for all
known status codes and use Unknown for non-standard status codes.

Modifications:

  • HttpObjectDecoder: second SP is optional for HttpResponseDecoder;
  • Enhance tests to verify new behavior;

Result:

ServiceTalk HttpClient parses responses with no SP after status code.
Example: HTTP/1.1 200\r\n.

Motivation:

While RFC7230, section 3.1.2
(https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2) requires a
`SP` before a `reason-phrase`, even if it's an empty phrase, many
implementations don't include that `SP` character. Many clients parse a
response without trailing `SP` character with no error. Those
implementations are:
 - Apache HTTP Client
 - JDK HttpClient
 - Netty
 - Tomcat (https://bz.apache.org/bugzilla/show_bug.cgi?id=60362)
 - Go HttpClient (golang/go@d71d08a#diff-0e6945dfde3e4dcaba7cfd394a85328b8137c42e152b4486dbfb6756ad69a779R145-R146)
 - Rust HttpClient (hyperium/http#345)
 - httpd with Passenger (https://bugzilla.redhat.com/show_bug.cgi?id=1032733)

Moreover, neither HTTP/2 nor HTTP/3 support reason-phrase. For this
reasons, many HTTP/1.x implementations (Tomcat, Rust, etc.) decided to
drop including the reason-phrase in serialized response for performance
reasons. Instead, they use the reason-phrase defined by RFC for all
known status codes and use `Unknown` for non-standard status codes.

Modifications:

- `HttpObjectDecoder`: second `SP` is optional for `HttpResponseDecoder`;
- Enhance tests to verify new behavior;

Result:

ServiceTalk HttpClient parses responses with no `SP` after status code.
Example: `HTTP/1.1 200\r\n`.
@idelpivnitskiy idelpivnitskiy self-assigned this Jun 9, 2022
Copy link
Contributor

@tkountis tkountis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg

@@ -131,19 +138,14 @@ void illegalPrefaceCharacter() {

@Test
void noVersion() {
assertDecoderException("200 OK" + "\r\n", "Invalid start-line");
assertDecoderException("200 OK" + "\r\n", "Invalid HTTP version");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@idelpivnitskiy idelpivnitskiy merged commit d05e52a into apple:main Jun 9, 2022
@idelpivnitskiy idelpivnitskiy deleted the reason-phrase branch June 9, 2022 16:06
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

Successfully merging this pull request may close these issues.

2 participants