Skip to content

Commit 03596c1

Browse files
committed
Remove option around client_addr
1 parent d5f783c commit 03596c1

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/Tiny_httpd_io.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ end
187187
(** A TCP server abstraction. *)
188188
module TCP_server = struct
189189
type conn_handler = {
190-
handle: ?client_addr:Unix.sockaddr -> Input.t -> Output.t -> unit; (** Handle client connection *)
190+
handle: client_addr:Unix.sockaddr -> Input.t -> Output.t -> unit; (** Handle client connection *)
191191
}
192192

193193
type t = {

src/Tiny_httpd_server.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module Request = struct
164164
type 'body t = {
165165
meth: Meth.t;
166166
host: string;
167-
client_addr: Unix.sockaddr option;
167+
client_addr: Unix.sockaddr;
168168
headers: Headers.t;
169169
http_version: int * int;
170170
path: string;
@@ -246,7 +246,7 @@ module Request = struct
246246
bad_reqf 400 "body is too short by %d bytes" size)
247247
248248
(* parse request, but not body (yet) *)
249-
let parse_req_start ?client_addr ~get_time_s ~buf (bs : byte_stream) :
249+
let parse_req_start ~client_addr ~get_time_s ~buf (bs : byte_stream) :
250250
unit t option resp_result =
251251
try
252252
let line = Byte_stream.read_line ~buf bs in
@@ -342,8 +342,8 @@ module Request = struct
342342
| e -> bad_reqf 500 "failed to read body: %s" (Printexc.to_string e)
343343
344344
module Internal_ = struct
345-
let parse_req_start ?(buf = Buf.create ()) ~get_time_s bs =
346-
parse_req_start ~get_time_s ~buf bs |> unwrap_resp_result
345+
let parse_req_start ?(buf = Buf.create ()) ~client_addr ~get_time_s bs =
346+
parse_req_start ~client_addr ~get_time_s ~buf bs |> unwrap_resp_result
347347
348348
let parse_body ?(buf = Buf.create ()) req bs : _ t =
349349
parse_body_ ~tr_stream:(fun s -> s) ~buf { req with body = bs }
@@ -1017,15 +1017,15 @@ let find_map f l =
10171017
aux f l
10181018
10191019
(* handle client on [ic] and [oc] *)
1020-
let client_handle_for (self : t) ?client_addr ic oc : unit =
1020+
let client_handle_for (self : t) ~client_addr ic oc : unit =
10211021
Pool.with_resource self.buf_pool @@ fun buf ->
10221022
Pool.with_resource self.buf_pool @@ fun buf_res ->
10231023
let is = Byte_stream.of_input ~buf_size:self.buf_size ic in
10241024
let continue = ref true in
10251025
while !continue && running self do
10261026
_debug (fun k -> k "read next request");
10271027
let (module B) = self.backend in
1028-
match Request.parse_req_start ?client_addr ~get_time_s:B.get_time_s ~buf is with
1028+
match Request.parse_req_start ~client_addr ~get_time_s:B.get_time_s ~buf is with
10291029
| Ok None -> continue := false (* client is done *)
10301030
| Error (c, s) ->
10311031
(* connection error, close *)

src/Tiny_httpd_server.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module Request : sig
6767
meth: Meth.t; (** HTTP method for this request. *)
6868
host: string;
6969
(** Host header, mandatory. It can also be found in {!headers}. *)
70-
client_addr : Unix.sockaddr option; (** Client address. Available since NEXT_RELEASE. *)
70+
client_addr : Unix.sockaddr; (** Client address. Available since NEXT_RELEASE. *)
7171
headers: Headers.t; (** List of headers. *)
7272
http_version: int * int;
7373
(** HTTP version. This should be either [1, 0] or [1, 1]. *)
@@ -162,7 +162,7 @@ module Request : sig
162162
(* for testing purpose, do not use. There is no guarantee of stability. *)
163163
module Internal_ : sig
164164
val parse_req_start :
165-
?buf:buf -> get_time_s:(unit -> float) -> byte_stream -> unit t option
165+
?buf:buf -> client_addr:Unix.sockaddr -> get_time_s:(unit -> float) -> byte_stream -> unit t option
166166

167167
val parse_body : ?buf:buf -> unit t -> byte_stream -> byte_stream t
168168
end

tests/unit/t_server.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ let () =
1010
salutationsSOMEJUNK"
1111
in
1212
let str = Tiny_httpd.Byte_stream.of_string q in
13-
let r = Request.Internal_.parse_req_start ~get_time_s:(fun _ -> 0.) str in
13+
let client_addr = Unix.(ADDR_INET (inet_addr_loopback, 1024)) in
14+
let r = Request.Internal_.parse_req_start ~client_addr ~get_time_s:(fun _ -> 0.) str in
1415
match r with
1516
| None -> failwith "should parse"
1617
| Some req ->

0 commit comments

Comments
 (0)