remove trailing slash from url

This commit is contained in:
Corentin Leruth 2023-08-26 07:45:27 +02:00 committed by Simon Cruanes
parent e2af52ebb0
commit 883d4bb806
2 changed files with 16 additions and 2 deletions

View file

@ -93,7 +93,14 @@ end = struct
(* send the content to the remote endpoint/path *)
let send (_self : t) ~(config : Config.t) ~path ~decode (bod : string) :
('a, error) result Lwt.t =
let full_url = config.url ^ path in
let url =
let url = config.url in
if String.ends_with url ~suffix:"/" then
String.sub url 0 (String.length url - 1)
else
url
in
let full_url = url ^ path in
let uri = Uri.of_string full_url in
let open Cohttp in

View file

@ -123,7 +123,14 @@ end = struct
Pbrt.Encoder.reset encoder;
encode x encoder;
let data = Pbrt.Encoder.to_string encoder in
let url = config.Config.url ^ path in
let url =
let url = config.Config.url in
if String.ends_with url ~suffix:"/" then
String.sub url 0 (String.length url - 1)
else
url
in
let url = url ^ path in
if !debug_ || config.debug then
Printf.eprintf "opentelemetry: send http POST to %s (%dB)\n%!" url
(String.length data);