-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add HTTP Upgrades (based on #227) #228
Open
yiblet
wants to merge
5
commits into
inhabitedtype:master
Choose a base branch
from
yiblet:upstream-changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ module CI = struct | |
done; | ||
!equal_so_far | ||
) | ||
;; | ||
end | ||
|
||
let ci_equal = CI.equal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,21 +139,17 @@ let create ?(config=Config.default) ?(error_handler=default_error_handler) reque | |
} | ||
|
||
let shutdown_reader t = | ||
if is_active t | ||
then Reqd.close_request_body (current_reqd_exn t); | ||
Reader.force_close t.reader; | ||
wakeup_reader t | ||
if is_active t | ||
then Reqd.close_request_body (current_reqd_exn t) | ||
else wakeup_reader t | ||
|
||
let shutdown_writer t = | ||
if is_active t then ( | ||
let reqd = current_reqd_exn t in | ||
(* XXX(dpatti): I'm not sure I understand why we close the *request* body | ||
here. Maybe we can write a test such that removing this line causes it to | ||
fail? *) | ||
Reqd.close_request_body reqd; | ||
Reqd.flush_response_body reqd); | ||
if is_active t then Reqd.flush_response_body (current_reqd_exn t); | ||
Writer.close t.writer; | ||
wakeup_writer t | ||
if is_active t | ||
then Reqd.close_request_body (current_reqd_exn t) | ||
else wakeup_writer t | ||
Comment on lines
+148
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the change in ordering important here? It seems like it is doing a second |
||
|
||
let error_code t = | ||
if is_active t | ||
|
@@ -162,7 +158,9 @@ let error_code t = | |
|
||
let shutdown t = | ||
shutdown_reader t; | ||
shutdown_writer t | ||
shutdown_writer t; | ||
wakeup_reader t; | ||
wakeup_writer t | ||
|
||
let set_error_and_handle ?request t error = | ||
if is_active t then begin | ||
|
@@ -225,8 +223,10 @@ let rec _next_read_operation t = | |
) else ( | ||
let reqd = current_reqd_exn t in | ||
match Reqd.input_state reqd with | ||
| Waiting -> `Yield | ||
| Ready -> Reader.next t.reader | ||
| Complete -> _final_read_operation_for t reqd | ||
| Upgraded -> `Upgrade | ||
) | ||
|
||
and _final_read_operation_for t reqd = | ||
|
@@ -248,6 +248,7 @@ and _final_read_operation_for t reqd = | |
if Reader.is_closed t.reader | ||
then Reader.next t.reader | ||
else `Yield | ||
| Upgraded -> `Upgrade | ||
| Complete -> | ||
advance_request_queue t; | ||
_next_read_operation t; | ||
|
@@ -258,7 +259,7 @@ let next_read_operation t = | |
match _next_read_operation t with | ||
| `Error (`Parse _) -> set_error_and_handle t `Bad_request; `Close | ||
| `Error (`Bad_request request) -> set_error_and_handle ~request t `Bad_request; `Close | ||
| (`Read | `Yield | `Close) as operation -> operation | ||
| (`Read | `Yield | `Close | `Upgrade) as operation -> operation | ||
|
||
let rec read_with_more t bs ~off ~len more = | ||
let call_handler = Queue.is_empty t.request_queue in | ||
|
@@ -296,17 +297,27 @@ let rec _next_write_operation t = | |
| Ready -> | ||
Reqd.flush_response_body reqd; | ||
Writer.next t.writer | ||
| Complete -> _final_write_operation_for t reqd | ||
| Complete -> _final_write_operation_for t reqd ~upgrade:false | ||
| Upgraded -> _final_write_operation_for t reqd ~upgrade:true | ||
) | ||
|
||
and _final_write_operation_for t reqd = | ||
and _final_write_operation_for t reqd ~upgrade = | ||
let next = | ||
if not (Reqd.persistent_connection reqd) then ( | ||
if upgrade then ( | ||
if Writer.has_pending_output t.writer then | ||
(* Even in the Upgrade case, we're still responsible for writing the response | ||
header, so we might have work to do. *) | ||
Writer.next t.writer | ||
else | ||
`Upgrade | ||
) else if not (Reqd.persistent_connection reqd) then ( | ||
shutdown_writer t; | ||
Writer.next t.writer; | ||
) else ( | ||
match Reqd.input_state reqd with | ||
| Waiting -> `Yield | ||
| Ready -> Writer.next t.writer; | ||
| Upgraded -> `Upgrade | ||
| Complete -> | ||
advance_request_queue t; | ||
_next_write_operation t; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for @anmonteiro's changes has
Streaming | Upgrade
grouped together while here it isUpgrade | Fixed
https://github.com/anmonteiro/httpaf/blob/0ddc76b7599a15cf5cc71ae39acf1585f21ed8d5/lib/reqd.ml#L184-L187
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the upgrade response is more similar to the fixed response here than the streaming response.
Streaming has a different error message since you can't assume that the response has completed in this call. Upgrade and Fixed both have concrete payloads that respond in a similar manner so I'd say they both likely to have completed the response.