- let headers =
- List.map (* lowercase header names to ease lookups before having a request
- object *)
- (fun (h,v) -> (String.lowercase h, v))
- (Http_parser.parse_headers ic) (* trailing \r\n consumed! *)
- in
- let body =
- (* TODO fallback on Transfer-Encoding if Content-Length isn't defined *)
- if meth = `POST then
- Buffer.contents
- (try (* read only Content-Length bytes *)
- let limit_raw =
- (try
- List.assoc "content-length" headers
- with Not_found -> raise Fallback)
- in
- let limit =
- (try (* TODO supports only a maximum content-length of 1Gb *)
- int_of_string limit_raw
- with Failure "int_of_string" ->
- raise (Invalid_header ("content-length: " ^ limit_raw)))
- in
- Http_misc.buf_of_inchan ~limit ic
- with Fallback -> Http_misc.buf_of_inchan ic) (* read until EOF *)
- else "" (* TODO empty body for methods other than POST, is what we want? *)
+ let (headers, body) =
+ (match version with
+ | None -> [], "" (* No version given, use request's 1st line only *)
+ | Some version -> (* Version specified, parse also headers and body *)
+ let headers =
+ List.map (* lowercase header names to ease lookups before having a
+ request object *)
+ (fun (h,v) -> (String.lowercase h, v))
+ (Http_parser.parse_headers ic) (* trailing \r\n consumed! *)
+ in
+ let body =
+ (* TODO fallback on size defined in Transfer-Encoding if
+ Content-Length isn't defined *)
+ if meth = `POST then
+ Buffer.contents
+ (try (* read only Content-Length bytes *)
+ let limit_raw =
+ (try
+ List.assoc "content-length" headers
+ with Not_found -> raise Fallback)
+ in
+ let limit =
+ (try (* TODO supports only a maximum content-length of 1Gb *)
+ int_of_string limit_raw
+ with Failure "int_of_string" ->
+ raise (Invalid_header ("content-length: " ^ limit_raw)))
+ in
+ Http_misc.buf_of_inchan ~limit ic
+ with Fallback -> Http_misc.buf_of_inchan ic) (* read until EOF *)
+ else (* TODO empty body for methods other than POST, is ok? *)
+ ""
+ in
+ (headers, body))