Skip to content

Commit

Permalink
cohttp-eio(client): move Host header to the font
Browse files Browse the repository at this point in the history
  • Loading branch information
bikallem committed Sep 15, 2022
1 parent 08e626c commit c98b437
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Unreleased
# cohttp-eio: ensure "Host" header is the first header in http client requests (bikallem #939)
- cohttp-eio: add Content-Length header to request/response (bikallem #929)
- cohttp-eio: add cohttp-eio client api - Cohttp_eio.Client (bikallem #879)
- http: add requires_content_length function for requests and responses (bikallem #879)
Expand Down
7 changes: 4 additions & 3 deletions cohttp-eio/src/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ let response buf_read =

let call ?meth ?version ?(headers = Http.Header.init ()) ?(body = Body.Empty)
~conn host resource_path =
let host_hdr = "Host" in
let headers =
if not (Http.Header.mem headers "Host") then
if not (Http.Header.mem headers host_hdr) then
let host =
match host with
| host, Some port -> host ^ ":" ^ string_of_int port
| host, None -> host
in
Http.Header.add headers "Host" host
else headers
Http.Header.add headers host_hdr host
else Http.Header.move_to_front headers host_hdr
in
let request = Http.Request.make ?meth ?version ~headers resource_path in
Buf_write.with_flow ~initial_size:0x1000 conn (fun writer ->
Expand Down

0 comments on commit c98b437

Please sign in to comment.