Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit 4dae120

Browse files
committed
Support ICE/1.x for SOURCE requests.
Normal clients sends "GET / HTTP/1.0" but Shoutcast clients send "SOURCE / ICE/1.0". Accept that as an alternative but only for SOURCE requests. Fixes: #410 PR-URL: #431 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Pierce Lopez <[email protected]>
1 parent 77310ee commit 4dae120

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

http_parser.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ enum state
314314
, s_req_http_HT
315315
, s_req_http_HTT
316316
, s_req_http_HTTP
317+
, s_req_http_I
318+
, s_req_http_IC
317319
, s_req_http_major
318320
, s_req_http_dot
319321
, s_req_http_minor
@@ -1084,11 +1086,17 @@ size_t http_parser_execute (http_parser *parser,
10841086

10851087
case s_req_http_start:
10861088
switch (ch) {
1089+
case ' ':
1090+
break;
10871091
case 'H':
10881092
UPDATE_STATE(s_req_http_H);
10891093
break;
1090-
case ' ':
1091-
break;
1094+
case 'I':
1095+
if (parser->method == HTTP_SOURCE) {
1096+
UPDATE_STATE(s_req_http_I);
1097+
break;
1098+
}
1099+
/* fall through */
10921100
default:
10931101
SET_ERRNO(HPE_INVALID_CONSTANT);
10941102
goto error;
@@ -1110,6 +1118,16 @@ size_t http_parser_execute (http_parser *parser,
11101118
UPDATE_STATE(s_req_http_HTTP);
11111119
break;
11121120

1121+
case s_req_http_I:
1122+
STRICT_CHECK(ch != 'C');
1123+
UPDATE_STATE(s_req_http_IC);
1124+
break;
1125+
1126+
case s_req_http_IC:
1127+
STRICT_CHECK(ch != 'E');
1128+
UPDATE_STATE(s_req_http_HTTP); /* Treat "ICE" as "HTTP". */
1129+
break;
1130+
11131131
case s_req_http_HTTP:
11141132
STRICT_CHECK(ch != '/');
11151133
UPDATE_STATE(s_req_http_major);

test.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,26 @@ const struct message requests[] =
11731173
,.headers= { { "Host", "example.com" } }
11741174
,.body= ""
11751175
}
1176+
1177+
#define SOURCE_ICE_REQUEST 42
1178+
, {.name = "source request"
1179+
,.type= HTTP_REQUEST
1180+
,.raw= "SOURCE /music/sweet/music ICE/1.0\r\n"
1181+
"Host: example.com\r\n"
1182+
"\r\n"
1183+
,.should_keep_alive= FALSE
1184+
,.message_complete_on_eof= FALSE
1185+
,.http_major= 1
1186+
,.http_minor= 0
1187+
,.method= HTTP_SOURCE
1188+
,.request_path= "/music/sweet/music"
1189+
,.request_url= "/music/sweet/music"
1190+
,.query_string= ""
1191+
,.fragment= ""
1192+
,.num_headers= 1
1193+
,.headers= { { "Host", "example.com" } }
1194+
,.body= ""
1195+
}
11761196
};
11771197

11781198
/* * R E S P O N S E S * */
@@ -4268,6 +4288,8 @@ main (void)
42684288

42694289
/// REQUESTS
42704290

4291+
test_simple("GET / IHTTP/1.0\r\n\r\n", HPE_INVALID_CONSTANT);
4292+
test_simple("GET / ICE/1.0\r\n\r\n", HPE_INVALID_CONSTANT);
42714293
test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION);
42724294
test_simple("GET / HTTP/01.1\r\n\r\n", HPE_INVALID_VERSION);
42734295
test_simple("GET / HTTP/11.1\r\n\r\n", HPE_INVALID_VERSION);

0 commit comments

Comments
 (0)