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

Do not shutdown the connection for HTTP/1.1 persistent connections #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions async/httpaf_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ module Client = struct
|> ignore;
reader_thread ()
end
| `Close when Client_connection.is_persistent conn -> ()
| `Close ->
(* Log.Global.printf "read_close(%d)%!" (Fd.to_int_exn fd); *)
Ivar.fill read_complete ();
Expand Down
13 changes: 11 additions & 2 deletions lib/client_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module Oneshot = struct
; reader : Reader.response
; writer : Writer.t
; state : state ref
; mutable is_persistent: bool
; mutable error_code : [ `Ok | error ]
}

Expand Down Expand Up @@ -81,6 +82,7 @@ module Oneshot = struct
; error_code = `Ok
; reader = Reader.response ~request_method handler
; writer
; is_persistent = false
; state }
in
Writer.write_request t.writer request;
Expand Down Expand Up @@ -152,12 +154,17 @@ module Oneshot = struct
let _next_read_operation t =
match !(t.state) with
| Awaiting_response | Closed -> Reader.next t.reader
| Received_response(_, response_body) ->
| Received_response(response, response_body) ->
if not (Body.Reader.is_closed response_body)
then Reader.next t.reader
else begin
Reader.force_close t.reader;
Reader.next t.reader
match Reader.next t.reader with
| `Read -> assert false
| `Error _ as err -> err
| `Close ->
t.is_persistent <- Response.persistent_connection response;
`Close
end
;;

Expand Down Expand Up @@ -215,4 +222,6 @@ module Oneshot = struct
Writer.report_result t.writer result

let is_closed t = Reader.is_closed t.reader && Writer.is_closed t.writer

let is_persistent t = t.is_persistent
end
3 changes: 3 additions & 0 deletions lib/httpaf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,9 @@ module Client_connection : sig

val is_closed : t -> bool

val is_persistent : t -> bool
(** [is_persistent t] is [true] if the last response indicated a keep-alive connection *)

(**/**)
val shutdown : t -> unit
(**/**)
Expand Down
1 change: 1 addition & 0 deletions lwt-unix/httpaf_lwt_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ module Client = struct
read_loop_step ()
end

| `Close when Client_connection.is_persistent connection -> Lwt.return_unit
| `Close ->
Lwt.wakeup_later notify_read_loop_exited ();
if not (Lwt_unix.state socket = Lwt_unix.Closed) then begin
Expand Down