Skip to content

Commit

Permalink
Return proper 505 on unsupported protocol. Use proper HTTP/%s line in…
Browse files Browse the repository at this point in the history
… output.harbor response. Fixes: #3255
  • Loading branch information
toots committed Jul 25, 2023
1 parent 125a69a commit 651d59e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.2.1 (unreleased)

Fixed:

- Fixed HTTP response status in `output.harbor` (#3255)

# 2.2.0 (2023-07-21)

New:
Expand Down
15 changes: 11 additions & 4 deletions src/core/harbor/harbor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module type T = sig
exception Unknown_codec
exception Mount_taken
exception Websocket_closed
exception Protocol_not_supported of string

(* Generic *)

Expand Down Expand Up @@ -383,6 +384,8 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
log#info "ICY error: invalid password";
simple_reply "Invalid password\r\n\r\n"))

exception Protocol_not_supported of string

let parse_http_request_line r =
try
let data = Pcre.split ~rex:(Pcre.regexp "[ \t]+") r in
Expand All @@ -395,10 +398,14 @@ module Make (T : Transport_t) : T with type socket = T.socket = struct
| "HTTP/1.1" -> `Http_11
| "ICE/1.0" -> `Ice_10
| s when protocol = `Source -> `Xaudiocast_uri s
| _ -> raise Not_found )
with e ->
log#info "Invalid request line %s: %s" r (Printexc.to_string e);
simple_reply "HTTP 500 Invalid request\r\n\r\n"
| s -> raise (Protocol_not_supported s) )
with
| Protocol_not_supported p ->
log#info "Protocol not supported for request %s: %s" r p;
simple_reply "HTTP 505 Protocol Not Supported\r\n\r\n"
| e ->
log#info "Invalid request line %s: %s" r (Printexc.to_string e);
simple_reply "HTTP 500 Invalid request\r\n\r\n"

let parse_headers headers =
let split_header h l =
Expand Down
2 changes: 1 addition & 1 deletion src/core/outputs/harbor_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class output p =
extra_headers)
in
let reply =
Printf.sprintf "%s 200 OK\r\nContent-type: %s\r\n%s%s\r\n" protocol
Printf.sprintf "HTTP/%s 200 OK\r\nContent-type: %s\r\n%s%s\r\n" protocol
data.format icyheader extra_headers
in
let buffer =
Expand Down

0 comments on commit 651d59e

Please sign in to comment.