}
type parse_result =
- | Result of t * (* remainder *) string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
let get_parse_result state =
}
| _ -> None
- let parse state str =
- let len = String.length str in
+ let parse_substring state str ofs len =
let i = ref 0 in
- while get_parse_result state = None && !i < len do
+ let iend = ofs + len in
+ while get_parse_result state = None && !i < iend do
parse_char state str.[!i];
incr i;
state.num_bytes_parsed <- state.num_bytes_parsed + 1
done;
match get_parse_result state with
- | Some v -> Result (v, (String.sub str !i (len - !i)))
+ | Some v -> Result (v, !i - ofs)
| None -> Parse_incomplete state
+ let parse state str =
+ parse_substring state str 0 (String.length str)
+
let serialize buf req =
Buffer.add_string buf (string_of_meth req.meth);
Buffer.add_string buf " ";
}
type parse_result =
- | Result of t * (* remainder *) string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
let get_parse_result state =
}
| _ -> None
- let parse state str =
- let len = String.length str in
+ let parse_substring state str ofs len =
let i = ref 0 in
- while get_parse_result state = None && !i < len do
+ let iend = ofs + len in
+ while get_parse_result state = None && !i < iend do
parse_char state str.[!i];
incr i;
state.num_bytes_parsed <- state.num_bytes_parsed + 1
done;
match get_parse_result state with
- | Some v -> Result (v, (String.sub str !i (len - !i)))
+ | Some v -> Result (v, !i - ofs)
| None -> Parse_incomplete state
+ let parse state str =
+ parse_substring state str 0 (String.length str)
+
let serialize buf resp =
if resp.version <> HTTP09 then begin
Buffer.add_string buf (string_of_version resp.version);
}
type parse_result =
- | Result of t * (* remainder *) string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
let get_parse_result state =
}
| _ -> None
- let parse state str =
- let len = String.length str in
+ let parse_substring state str ofs len =
let i = ref 0 in
- while get_parse_result state = None && !i < len do
+ let iend = ofs + len in
+ while get_parse_result state = None && !i < iend do
parse_char state str.[!i];
incr i;
state.num_bytes_parsed <- Int64.succ state.num_bytes_parsed
done;
match get_parse_result state with
- | Some v -> Result (v, (String.sub str !i (len - !i)))
+ | Some v -> Result (v, !i - ofs)
| None -> Parse_incomplete state
+ let parse state str =
+ parse_substring state str 0 (String.length str)
+
let connection_closed state =
if state.content_length = Connection_close then
state.cursor <- Done
}
type parse_result =
- | Result of t * (* remainder *) string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
| Error of string
- let rec parse state str =
+ let rec parse_substring state str ofs len =
match state.cursor with
| In_request_header rs ->
- (match Request_header.parse rs str with
- | Request_header.Result (v, rem) ->
+ (match Request_header.parse_substring rs str ofs len with
+ | Request_header.Result (v, consumed) ->
state.s_request <- Some v;
state.num_bytes_parsed <- Int64.of_int (Request_header.num_bytes_parsed rs);
(match Payload.init_from_request v with
| Payload.No_payload ->
state.cursor <- Done;
- Result ({ request = v; payload = None }, rem)
+ Result ({ request = v; payload = None }, consumed)
| Payload.Error s ->
state.cursor <- Done;
Error s
| Payload.Payload ps ->
state.cursor <- In_payload ps;
- parse state rem (* recurse on remaining input *)
+ (* recurse on remaining input *)
+ parse_substring state str (ofs + consumed) (len - consumed)
)
| Request_header.Parse_incomplete rs ->
state.cursor <- In_request_header rs;
)
| In_payload ps ->
(match Payload.parse ps str with
- | Payload.Result (p, rem) ->
+ | Payload.Result (p, consumed) ->
state.num_bytes_parsed <- Int64.add state.num_bytes_parsed (Payload.num_bytes_parsed ps);
state.cursor <- Done;
- Result ({ request = optval state.s_request; payload = Some p }, rem)
+ Result ({ request = optval state.s_request; payload = Some p }, consumed)
| Payload.Parse_incomplete ps ->
state.cursor <- In_payload ps;
Parse_incomplete state
)
| Done -> raise_error (Internal_error "parse called on finished request!")
+ let parse state str =
+ parse_substring state str 0 (String.length str)
+
let connection_closed state =
match state.cursor with
| In_request_header _ -> ()
}
type parse_result =
- | Result of t * (* remainder *) string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
| Error of string
- let rec parse state str =
+ let rec parse_substring state str ofs len =
match state.cursor with
| In_response_header rs ->
(match Response_header.parse rs str with
- | Response_header.Result (v, rem) ->
+ | Response_header.Result (v, consumed) ->
state.s_response <- Some v;
state.num_bytes_parsed <- Int64.of_int (Response_header.num_bytes_parsed rs);
(match Payload.init_from_response v with
| Payload.No_payload ->
state.cursor <- Done;
- Result ({ response = v; payload = None }, rem)
+ Result ({ response = v; payload = None }, consumed)
| Payload.Error s ->
state.cursor <- Done;
Error s
| Payload.Payload ps ->
state.cursor <- In_payload ps;
- parse state rem (* recurse on remaining input *)
+ (* recurse on remaining input *)
+ parse_substring state str (ofs + consumed) (len - consumed)
)
| Response_header.Parse_incomplete rs ->
state.cursor <- In_response_header rs;
)
| In_payload ps ->
(match Payload.parse ps str with
- | Payload.Result (p, rem) ->
+ | Payload.Result (p, consumed) ->
state.num_bytes_parsed <- Int64.add state.num_bytes_parsed (Payload.num_bytes_parsed ps);
state.cursor <- Done;
- Result ({ response = optval state.s_response; payload = Some p }, rem)
+ Result ({ response = optval state.s_response; payload = Some p }, consumed)
| Payload.Parse_incomplete ps ->
state.cursor <- In_payload ps;
Parse_incomplete state
)
| Done -> raise_error (Internal_error "parse called on finished response!")
+ let parse state str =
+ parse_substring state str 0 (String.length str)
+
let connection_closed state =
match state.cursor with
| In_response_header _ -> ()
headers : header_fields;
}
type parse_result =
- | Result of t * (* remainder *) string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
val parse : state -> string -> parse_result
+ val parse_substring : state -> string -> (* offset *) int -> (* len *) int -> parse_result
type error
exception Http_error of error
headers : header_fields;
}
type parse_result =
- | Result of t * (* remainder *) string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
val parse : state -> string -> parse_result
+ val parse_substring : state -> string -> (* offset *) int -> (* len *) int -> parse_result
type error
exception Http_error of error
trailers : header_fields
}
type parse_result =
- | Result of t * (* remainder *) string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
val parse : state -> string -> parse_result
+ val parse_substring : state -> string -> (* offset *) int -> (* len *) int -> parse_result
val get_parse_result : state -> t option
val connection_closed : state -> unit
payload : Payload.t option
}
type parse_result =
- | Result of t * string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
| Error of string
val parse : state -> string -> parse_result
+ val parse_substring : state -> string -> (* offset *) int -> (* len *) int -> parse_result
val connection_closed : state -> unit
payload : Payload.t option
}
type parse_result =
- | Result of t * string
+ | Result of t * (* number of consumed bytes *) int
| Parse_incomplete of state
| Error of string
val parse : state -> string -> parse_result
+ val parse_substring : state -> string -> (* offset *) int -> (* len *) int -> parse_result
val connection_closed : state -> unit