Skip to content

Commit

Permalink
CA-383987: Only include valid Hosts and Ports in tracing Host header
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Woods <steven.woods@citrix.com>
  • Loading branch information
snwoods committed Oct 26, 2023
1 parent be36265 commit 4006aed
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions ocaml/libs/tracing/tracing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -688,16 +688,26 @@ module Export = struct
let export ~url json =
try
let body = json in
(*If host or port is None it will throw a more meaningful error later, so ignore here*)
let hostname = match Uri.host url with Some h -> h | None -> "" in
let port = match Uri.port url with Some p -> p | None -> 80 in
let headers =
Cohttp.Header.of_list
[
("Content-Type", "application/json")
; ("Content-Length", string_of_int (String.length body))
; ("Host", hostname ^ ":" ^ string_of_int port)
]
([
("Content-Type", "application/json")
; ("Content-Length", string_of_int (String.length body))
]
@
match Uri.host url with
| None ->
[]
| Some h ->
let port =
match Uri.port url with
| Some p ->
":" ^ string_of_int p
| None ->
""
in
[("Host", h ^ port)]
)
in
Open_uri.with_open_uri url (fun fd ->
let request =
Expand Down

0 comments on commit 4006aed

Please sign in to comment.