Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions async/cohttp_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ module Client = struct
let pipe = pipe_of_body Response.read_body_chunk reader in
(res, pipe)

let request ?interrupt ?ssl_config ?host ?(body=`Empty) req =
let request ?interrupt ?ssl_config ?uri ?(body=`Empty) req =
(* Connect to the remote side *)
let host =
match host with
let uri =
match uri with
| Some t -> t
| None -> Request.uri req in
Net.connect_uri ?interrupt host
Net.connect_uri ?interrupt uri
>>= fun (ic,oc) ->
Request.write (fun writer -> Body.write Request.write_body body writer) req oc
>>= fun () ->
Expand Down Expand Up @@ -225,7 +225,7 @@ module Client = struct
Request.make_for_client ?headers ~chunked:true meth uri
end
in
req >>= request ?interrupt ?ssl_config ~body ~host:uri
req >>= request ?interrupt ?ssl_config ~body ~uri

let get ?interrupt ?ssl_config ?headers uri =
call ?interrupt ?ssl_config ?headers ~chunked:false `GET uri
Expand Down
2 changes: 1 addition & 1 deletion async/cohttp_async.mli
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module Client : sig
val request :
?interrupt:unit Deferred.t ->
?ssl_config:Conduit_async.Ssl.config ->
?host:Uri.t ->
?uri:Uri.t ->
?body:Body.t ->
Request.t ->
(Response.t * Body.t) Deferred.t
Expand Down
16 changes: 8 additions & 8 deletions lib/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ open Sexplib.Std
type t = {
headers: Header.t;
meth: Code.meth;
path: string;
resource: string;
version: Code.version;
encoding: Transfer.encoding;
} [@@deriving fields, sexp]
Expand Down Expand Up @@ -51,7 +51,7 @@ let make ?(meth=`GET) ?(version=`HTTP_1_1) ?encoding ?headers uri =
Header.add_authorization headers auth
| _, _, _ -> headers in
let encoding = guess_encoding ?encoding headers in
{ meth; version; headers; path=(Uri.path_and_query uri); encoding }
{ meth; version; headers; resource=(Uri.path_and_query uri); encoding }

let is_keep_alive { version; headers; _ } =
not (version = `HTTP_1_0 ||
Expand Down Expand Up @@ -82,8 +82,8 @@ let is_valid_uri path meth =
| Some _ -> true
| None -> not (String.length path > 0 && path.[0] <> '/'))

let uri { path ; headers ; meth ; _ } =
match path with
let uri { resource ; headers ; meth ; _ } =
match resource with
| "*" ->
begin match Header.get headers "host" with
| None -> Uri.of_string ""
Expand Down Expand Up @@ -151,11 +151,11 @@ module Make(IO : S.IO) = struct
parse_request_fst_line ic >>= function
| `Eof -> return `Eof
| `Invalid reason as r -> return r
| `Ok (meth, path, version) ->
if is_valid_uri path meth then
| `Ok (meth, resource, version) ->
if is_valid_uri resource meth then
Header_IO.parse ic >>= fun headers ->
let encoding = Header.get_transfer_encoding headers in
return (`Ok { headers; meth; path; version; encoding })
return (`Ok { headers; meth; resource; version; encoding })
else
return (`Invalid "bad request URI")

Expand All @@ -173,7 +173,7 @@ module Make(IO : S.IO) = struct
let fst_line =
Printf.sprintf "%s %s %s\r\n"
(Code.string_of_method req.meth)
(if req.path = "" then "/" else req.path)
(if req.resource = "" then "/" else req.resource)
(Code.string_of_version req.version) in
let headers = req.headers in
let headers =
Expand Down
2 changes: 1 addition & 1 deletion lib/s.mli
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module type Request = sig
type t = {
headers: Header.t; (** HTTP request headers *)
meth: Code.meth; (** HTTP request method *)
path: string; (** Request path and query *)
resource: string; (** Request path and query *)
version: Code.version; (** HTTP version, usually 1.1 *)
encoding: Transfer.encoding; (** transfer encoding of this HTTP request *)
} [@@deriving fields, sexp]
Expand Down