Skip to content

Commit a71b1cf

Browse files
committed
add content-type to allowed headers in options
1 parent 642a451 commit a71b1cf

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/common/service.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ module IO = struct
4141
| Error e -> Error e
4242
| Ok a -> Ok (f a)
4343

44+
let is_empty : type a. a io -> bool = function
45+
| Empty -> true
46+
| _ -> false
4447
end
4548

4649
type ('args, 'input, 'output, 'error, 'security) t = {

src/server/directory.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ let options_headers dir = match MethMap.bindings dir.services with
199199
| Http {service; _} -> aux_sec acc service
200200
| Websocket {service; _} -> aux_sec acc service
201201
) StringSet.empty l in
202-
let headers = Cors.insert headers (Cors.allow_headers_name, sec_set) in
202+
let allowed_headers_set = if List.exists (fun (_, rs) -> match rs with
203+
| Http {service; _} -> IO.is_empty service.Service.input
204+
| Websocket _ -> false) l then
205+
StringSet.add "content-type" sec_set else sec_set in
206+
let headers = Cors.insert headers (Cors.allow_headers_name, allowed_headers_set) in
203207
let headers = Cors.union headers (Cors.allow_credentials_header (not (StringSet.is_empty sec_set))) in
204208
let aux_ac acc s = Cors.union acc (Service.headers s) in
205209
let headers = List.fold_left (fun acc (_,rs) -> match rs with

src/server/server_common.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ let create_server ?(name="HTTPUN") ~max_connections server_port server_kind hand
222222
EzDebug.printf "Starting %s server (port=%d, connection=%d)" name server_port max_connections;
223223
establish_server_with_client_socket
224224
~nb_max_connections:max_connections
225-
listen_address (handler s)(* fun sockaddr fd -> *)
226-
(* handler ?catch ?allow_origin ?allow_headers ?allow_methods *)
227-
(* ?allow_credentials s sockaddr fd) *) >>= fun s ->
225+
listen_address (handler s) >>= fun s ->
228226
server := Some s;
229227
Lwt.return_unit
230228

0 commit comments

Comments
 (0)