From 93847b5eac0ac287dea9298f394d01a51eb962bb Mon Sep 17 00:00:00 2001
From: Rob Hoes <rob.hoes@citrix.com>
Date: Thu, 7 Jul 2022 13:40:56 +0000
Subject: [PATCH 1/6] Remove unused Http_proxy.http_proxy

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
---
 ocaml/libs/http-svr/http_proxy.ml  | 54 ------------------------------
 ocaml/libs/http-svr/http_proxy.mli |  4 ---
 ocaml/libs/http-svr/http_svr.mli   |  6 ----
 3 files changed, 64 deletions(-)

diff --git a/ocaml/libs/http-svr/http_proxy.ml b/ocaml/libs/http-svr/http_proxy.ml
index 0f474576d..4d7a1d82f 100644
--- a/ocaml/libs/http-svr/http_proxy.ml
+++ b/ocaml/libs/http-svr/http_proxy.ml
@@ -53,57 +53,3 @@ let one request fromfd s =
   | m ->
       error "Proxy doesn't support: %s" (Http.string_of_method_t m) ;
       Http_svr.response_forbidden ~req:request fromfd
-
-let server = ref None
-
-let m = Mutex.create ()
-
-let http_proxy src_ip src_port transport =
-  let tcp_connection _ fromfd =
-    (* NB 'fromfd' is accepted within the server_io module and it expects us to close it *)
-    finally
-      (fun () ->
-        let bio = Buf_io.of_fd fromfd in
-        let request, _ = Http_svr.request_of_bio bio in
-        Option.iter
-          (fun request -> with_transport transport (one request fromfd))
-          request
-      )
-      (fun () -> Unix.close fromfd)
-  in
-  try
-    let addr = Unix.inet_addr_of_string src_ip in
-    let sockaddr = Unix.ADDR_INET (addr, src_port) in
-    Xapi_stdext_threads.Threadext.Mutex.execute m (fun () ->
-        (* shutdown any server which currently exists *)
-        Option.iter (fun server -> server.Server_io.shutdown ()) !server ;
-        (* Make sure we don't try to double-close the server *)
-        server := None ;
-        let handler = {Server_io.name= "http_proxy"; body= tcp_connection} in
-        let sock =
-          Unix.socket (Unix.domain_of_sockaddr sockaddr) Unix.SOCK_STREAM 0
-        in
-        ( try
-            (* Make sure exceptions cause the socket to be closed *)
-            Unix.set_close_on_exec sock ;
-            Unix.setsockopt sock Unix.SO_REUSEADDR true ;
-            ( match sockaddr with
-            | Unix.ADDR_INET _ ->
-                Xapi_stdext_unix.Unixext.set_tcp_nodelay sock true
-            | _ ->
-                ()
-            ) ;
-            Unix.bind sock sockaddr ; Unix.listen sock 128
-          with e ->
-            debug "Caught exception in Http_svr.bind (closing socket): %s"
-              (Printexc.to_string e) ;
-            Unix.close sock ;
-            raise e
-        ) ;
-        let s = Server_io.server handler sock in
-        server := Some s
-    )
-  with e ->
-    error "Caught exception setting up proxy from internal network: %s"
-      (Printexc.to_string e) ;
-    raise e
diff --git a/ocaml/libs/http-svr/http_proxy.mli b/ocaml/libs/http-svr/http_proxy.mli
index 43ef012de..a5161801d 100644
--- a/ocaml/libs/http-svr/http_proxy.mli
+++ b/ocaml/libs/http-svr/http_proxy.mli
@@ -15,7 +15,3 @@
 val one : Http.Request.t -> Unix.file_descr -> Unix.file_descr -> unit
 (** [one request input output] proxies the single HTTP request [request]
     from [input] to [output] *)
-
-val http_proxy : string -> int -> Xmlrpc_client.transport -> unit
-(** [http_proxy ip port transport] establishes an HTTP proxy on [ip]:[port]
-    which forwards all requests via [transport] *)
diff --git a/ocaml/libs/http-svr/http_svr.mli b/ocaml/libs/http-svr/http_svr.mli
index 8996e0203..6d9032ff4 100644
--- a/ocaml/libs/http-svr/http_svr.mli
+++ b/ocaml/libs/http-svr/http_svr.mli
@@ -125,9 +125,3 @@ val respond_to_options : Http.Request.t -> Unix.file_descr -> unit
 val headers : Unix.file_descr -> string list -> unit
 
 val read_body : ?limit:int -> Http.Request.t -> Buf_io.t -> string
-
-val request_of_bio :
-     ?use_fastpath:bool
-  -> ?proxy_seen:string
-  -> Buf_io.t
-  -> Http.Request.t option * string option
-- 
2.31.1

