Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jsha
Copy link
Collaborator

@jsha jsha commented Jun 14, 2023

Previously, we treated HTTP/1.0 responses as always being close-delimited. However, that's not quite right. HTTP/1.0 responses default to Connection: close, but the server may send Connection: keep-alive, along with a Content-Length header. Update body_type to understand this.

Also, slightly reorganize body_type. has_no_body was being checked redundantly when we could just early-return when has_no_body is true. And regardless of whether we see Connection: close (on any HTTP version), we must honor Transfer-Encoding or Content-Length if they are present.

Fixes #600

@jsha jsha force-pushed the http10-may-have-content-length branch from 12916f0 to d0e9634 Compare June 14, 2023 05:06
@algesten
Copy link
Owner

This looks good. I'm just wondering about the Connection: close -> is_close being gone. Could we map out all the scenarios on some form like this?

Here's a stab:

HTTP/1.0
- no header                    => close
- content-length               => close
- content-length + keep-alive  => reuse
- connection: close + whatever => close
- te: chunked                  => error?

HTTP/1.1
- no header                    => chunked
- content-length               => reuse
- content-length + keep-alive  => reuse
- connection: close + whatever => close
- te: chunked                  => chunked

@jsha
Copy link
Collaborator Author

jsha commented Jun 14, 2023

What I concluded from my re-reading of the RFCs is that Connection: close / Connection: keep-alive should be separate from body length calculation. Body length calculation determines when we can consider a body "done." But Connection: determines what we can do with the connection once it's done:

https://datatracker.ietf.org/doc/html/rfc9112#name-tear-down

A client that receives a "close" connection option MUST cease sending requests on that connection and close the connection after reading the response message containing the "close" connection option; if additional pipelined requests had been sent on the connection, the client SHOULD NOT assume that they will be processed by the server.

So what we need is a change in the pooling code to honor Connection: close by dropping the connection; otherwise we might try sending a request on a connection that the server has closed. I'll add that to this PR.

jsha added 2 commits June 14, 2023 12:35
Previously, we treated HTTP/1.0 responses as always being
close-delimited. However, that's not quite right. HTTP/1.0 responses
_default_ to Connection: close, but the server may send Connection:
keep-alive, along with a Content-Length header. Update body_type to
understand this.

Also, slightly reorganize body_type. has_no_body was being checked
redundantly when we could just early-return when has_no_body is true.
And regardless of whether we see Connection: close (on any HTTP
version), we must honor Transfer-Encoding or Content-Length if they are
present.
@jsha jsha force-pushed the http10-may-have-content-length branch from 2dc52bb to 7bc5ea2 Compare June 14, 2023 19:35
@jsha
Copy link
Collaborator Author

jsha commented Jun 14, 2023

Alright, check out the updates for connection_option and see what you think!

Copy link
Owner

@algesten algesten left a comment

Choose a reason for hiding this comment

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

Love it!

@jsha jsha merged commit a8c0385 into algesten:main Jun 14, 2023
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.

Since 2.6.0 ureq hangs for 5 seconds in recvfrom when making GET request to local OSRM server

2 participants