@@ -19,29 +19,24 @@ open Sexplib0.Sexp_conv
19
19
type t = Http.Request .t = {
20
20
headers : Header .t ;
21
21
meth : Code .meth ;
22
- scheme : string option ;
23
22
resource : string ;
24
23
version : Code .version ;
25
24
}
26
25
[@@ deriving sexp ]
27
26
28
- let compare { headers; meth; scheme; resource; version } y =
27
+ let compare { headers; meth; resource; version } y =
29
28
match Header. compare headers y.headers with
30
29
| 0 -> (
31
30
match Code. compare_method meth y.meth with
32
31
| 0 -> (
33
- match Option. compare String. compare scheme y.scheme with
34
- | 0 -> (
35
- match String. compare resource y.resource with
36
- | 0 -> Code. compare_version version y.version
37
- | i -> i)
32
+ match String. compare resource y.resource with
33
+ | 0 -> Code. compare_version version y.version
38
34
| i -> i)
39
35
| i -> i)
40
36
| i -> i
41
37
42
38
let headers t = t.headers
43
39
let meth t = t.meth
44
- let scheme t = t.scheme
45
40
let resource t = t.resource
46
41
let version t = t.version
47
42
let encoding t = Header. get_transfer_encoding t.headers
@@ -71,14 +66,13 @@ let make ?(meth = `GET) ?(version = `HTTP_1_1) ?encoding
71
66
Header. add_authorization headers auth
72
67
| _ , _ , _ -> headers
73
68
in
74
- let scheme = Uri. scheme uri in
75
69
let resource = Uri. path_and_query uri in
76
70
let headers =
77
71
match encoding with
78
72
| None -> headers
79
73
| Some encoding -> Header. add_transfer_encoding headers encoding
80
74
in
81
- { headers; meth; scheme; resource; version }
75
+ { headers; meth; resource; version }
82
76
83
77
let is_keep_alive t = Http.Request. is_keep_alive t
84
78
@@ -110,49 +104,42 @@ let is_valid_uri path meth =
110
104
| Some _ -> true
111
105
| None -> not (String. length path > 0 && path.[0 ] <> '/' )
112
106
113
- let uri { scheme; resource; headers; meth; _ } =
114
- let uri =
115
- match resource with
116
- | "*" -> (
117
- match Header. get headers " host" with
118
- | None -> Uri. of_string " "
119
- | Some host ->
120
- let host_uri = Uri. of_string (" //" ^ host) in
121
- Uri. (make ?host:(host host_uri ) ?port:(port host_uri) () ))
122
- | authority when meth = `CONNECT -> Uri. of_string (" //" ^ authority)
123
- | path -> (
124
- let uri = Uri. of_string path in
125
- match Uri. scheme uri with
126
- | Some _ -> (
127
- Uri. (
128
- (* we have an absoluteURI *)
129
- match path uri with "" -> with_path uri " /" | _ -> uri))
130
- | None ->
131
- let empty = Uri. of_string " " in
132
- let empty_base = Uri. of_string " ///" in
133
- let pqs =
134
- match Stringext. split ~max: 2 path ~on: '?' with
135
- | [] -> empty_base
136
- | [ path ] ->
107
+ let uri { resource; headers; meth; _ } =
108
+ match resource with
109
+ | "*" -> (
110
+ match Header. get headers " host" with
111
+ | None -> Uri. of_string " "
112
+ | Some host ->
113
+ let host_uri = Uri. of_string (" //" ^ host) in
114
+ Uri. (make ?host:(host host_uri ) ?port:(port host_uri) () ))
115
+ | authority when meth = `CONNECT -> Uri. of_string (" //" ^ authority)
116
+ | path -> (
117
+ let uri = Uri. of_string path in
118
+ match Uri. scheme uri with
119
+ | Some _ -> (
120
+ Uri. (
121
+ (* we have an absoluteURI *)
122
+ match path uri with "" -> with_path uri " /" | _ -> uri))
123
+ | None -> (
124
+ let empty = Uri. of_string " " in
125
+ let empty_base = Uri. of_string " ///" in
126
+ let pqs =
127
+ match Stringext. split ~max: 2 path ~on: '?' with
128
+ | [] -> empty_base
129
+ | [ path ] ->
130
+ Uri. resolve " http" empty_base (Uri. with_path empty path)
131
+ | path :: qs :: _ ->
132
+ let path_base =
137
133
Uri. resolve " http" empty_base (Uri. with_path empty path)
138
- | path :: qs :: _ ->
139
- let path_base =
140
- Uri. resolve " http" empty_base (Uri. with_path empty path)
141
- in
142
- Uri. with_query path_base (Uri. query_of_encoded qs)
143
- in
144
- let uri =
145
- match Header. get headers " host" with
146
- | None -> Uri. (with_scheme (with_host pqs None ) None )
147
- | Some host ->
148
- let host_uri = Uri. of_string (" //" ^ host) in
149
- let uri = Uri. with_host pqs (Uri. host host_uri) in
150
- Uri. with_port uri (Uri. port host_uri)
151
- in
152
- uri)
153
- in
154
- (* Only set the scheme if it's not already part of the URI *)
155
- match Uri. scheme uri with Some _ -> uri | None -> Uri. with_scheme uri scheme
134
+ in
135
+ Uri. with_query path_base (Uri. query_of_encoded qs)
136
+ in
137
+ match Header. get headers " host" with
138
+ | None -> Uri. (with_scheme (with_host pqs None ) None )
139
+ | Some host ->
140
+ let host_uri = Uri. of_string (" //" ^ host) in
141
+ let uri = Uri. with_host pqs (Uri. host host_uri) in
142
+ Uri. with_port uri (Uri. port host_uri)))
156
143
157
144
type tt = t
158
145
0 commit comments