@@ -29,7 +29,7 @@ type request = { addr : Unix.sockaddr;
29
29
encoding : encoding ;
30
30
}
31
31
32
- type reply_status =
32
+ type status_code =
33
33
[ `Ok
34
34
| `Created
35
35
| `Accepted
@@ -52,9 +52,9 @@ type reply_status =
52
52
| `Internal_server_error
53
53
| `Not_implemented
54
54
| `Service_unavailable
55
- | `Version_not_supported
56
- | `Custom of string ]
55
+ | `Version_not_supported ]
57
56
57
+ type reply_status = [ status_code | `Custom of string ]
58
58
type extended_reply_status = [ reply_status | `No_reply ]
59
59
60
60
type 'status reply' = 'status * (string * string ) list * string
@@ -136,35 +136,43 @@ let status_code : reply_status -> int = function
136
136
137
137
| `Custom _ -> 999
138
138
139
- let show_http_reply : reply_status -> string = function
140
- | `Ok -> " HTTP/1.0 200 OK"
141
- | `Created -> " HTTP/1.0 201 Created"
142
- | `Accepted -> " HTTP/1.0 202 Accepted"
143
- | `No_content -> " HTTP/1.0 204 No Content"
144
-
145
- | `Moved -> " HTTP/1.0 301 Moved Permanently"
146
- | `Found -> " HTTP/1.0 302 Found"
147
-
148
- | `Bad_request -> " HTTP/1.0 400 Bad Request"
149
- | `Unauthorized -> " HTTP/1.0 401 Unauthorized"
150
- | `Payment_required -> " HTTP/1.0 402 Payment Required"
151
- | `Forbidden -> " HTTP/1.0 403 Forbidden"
152
- | `Not_found -> " HTTP/1.0 404 Not Found"
153
- | `Method_not_allowed -> " HTTP/1.0 405 Method Not Allowed"
154
- | `Not_acceptable -> " HTTP/1.0 406 Not Acceptable"
155
- | `Conflict -> " HTTP/1.0 409 Conflict"
156
- | `Length_required -> " HTTP/1.0 411 Length Required"
157
- | `Request_too_large -> " HTTP/1.0 413 Request Entity Too Large"
158
- | `I'm_a_teapot -> " HTTP/1.0 418 I'm a teapot"
159
- | `Unprocessable_content -> " HTTP/1.0 422 Unprocessable Content"
160
- | `Too_many_requests -> " HTTP/1.0 429 Too Many Requests"
161
-
162
- | `Internal_server_error -> " HTTP/1.0 500 Internal Server Error"
163
- | `Not_implemented -> " HTTP/1.0 501 Not Implemented"
164
- | `Service_unavailable -> " HTTP/1.0 503 Service Unavailable"
165
- | `Version_not_supported -> " HTTP/1.0 505 HTTP Version Not Supported"
166
-
139
+ let show_http_version = function
140
+ | `Http_1_0 -> " HTTP/1.0"
141
+ | `Http_1_1 -> " HTTP/1.1"
142
+
143
+ let show_status_code : status_code -> string = function
144
+ | `Ok -> sprintf " 200 OK"
145
+ | `Created -> sprintf " 201 Created"
146
+ | `Accepted -> sprintf " 202 Accepted"
147
+ | `No_content -> sprintf " 204 No Content"
148
+
149
+ | `Moved -> sprintf " 301 Moved Permanently"
150
+ | `Found -> sprintf " 302 Found"
151
+
152
+ | `Bad_request -> sprintf " 400 Bad Request"
153
+ | `Unauthorized -> sprintf " 401 Unauthorized"
154
+ | `Payment_required -> sprintf " 402 Payment Required"
155
+ | `Forbidden -> sprintf " 403 Forbidden"
156
+ | `Not_found -> sprintf " 404 Not Found"
157
+ | `Method_not_allowed -> sprintf " 405 Method Not Allowed"
158
+ | `Not_acceptable -> sprintf " 406 Not Acceptable"
159
+ | `Conflict -> sprintf " 409 Conflict"
160
+ | `Length_required -> sprintf " 411 Length Required"
161
+ | `Request_too_large -> sprintf " 413 Request Entity Too Large"
162
+ | `I'm_a_teapot -> sprintf " 418 I'm a teapot"
163
+ | `Unprocessable_content -> sprintf " 422 Unprocessable Content"
164
+ | `Too_many_requests -> sprintf " 429 Too Many Requests"
165
+
166
+ | `Internal_server_error -> sprintf " 500 Internal Server Error"
167
+ | `Not_implemented -> sprintf " 501 Not Implemented"
168
+ | `Service_unavailable -> sprintf " 503 Service Unavailable"
169
+ | `Version_not_supported -> sprintf " 505 HTTP Version Not Supported"
170
+
171
+ let show_http_reply : version:[ `Http_1_0 | `Http_1_1 ] -> reply_status -> string =
172
+ fun ~version reply_status ->
173
+ match reply_status with
167
174
| `Custom s -> s
175
+ | #status_code as code -> sprintf " %s %s" (show_status_code code) (show_http_version version)
168
176
169
177
(* basically allow all *)
170
178
let cors_preflight_allow_all = (`No_content , [
0 commit comments