diff --git a/src/connections.c b/src/connections.c index 997b2c66..f145ebb6 100644 --- a/src/connections.c +++ b/src/connections.c @@ -303,9 +303,18 @@ static int connection_handle_write_prepare(server *srv, connection *con) { case HTTP_METHOD_GET: case HTTP_METHOD_POST: case HTTP_METHOD_HEAD: - case HTTP_METHOD_OPTIONS: case HTTP_METHOD_PUT: break; + case HTTP_METHOD_OPTIONS: + if (con->uri.path->ptr[0] != '*') { + response_header_insert(srv, con, CONST_STR_LEN("Allow"), CONST_STR_LEN("OPTIONS, GET, HEAD, POST")); + + con->http_status = 200; + con->file_finished = 1; + + chunkqueue_reset(con->write_queue); + } + break; default: switch(con->http_status) { case 400: /* bad request */ @@ -395,7 +404,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) { /* fall through */ case 207: case 200: /* class: header + body */ - break; + break; case 206: /* write_queue is already prepared */ case 302: @@ -452,7 +461,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) { if (con->request.http_method == HTTP_METHOD_HEAD) { chunkqueue_reset(con->write_queue); } - + http_response_write_header(srv, con); return 0; diff --git a/src/response.c b/src/response.c index 9b3912b8..33a3c1a6 100644 --- a/src/response.c +++ b/src/response.c @@ -216,9 +216,15 @@ handler_t http_response_prepare(server *srv, connection *con) { - buffer_copy_string_buffer(srv->tmp_buf, con->uri.path_raw); - buffer_urldecode_path(srv->tmp_buf); - buffer_path_simplify(con->uri.path, srv->tmp_buf); + if (con->request.http_method == HTTP_METHOD_OPTIONS && + con->uri.path_raw->ptr[0] == '*' && con->uri.path_raw->ptr[1] == '\0') { + /* OPTIONS * ... */ + buffer_copy_string_buffer(con->uri.path, con->uri.path_raw); + } else { + buffer_copy_string_buffer(srv->tmp_buf, con->uri.path_raw); + buffer_urldecode_path(srv->tmp_buf); + buffer_path_simplify(con->uri.path, srv->tmp_buf); + } if (con->conf.log_request_handling) { log_error_write(srv, __FILE__, __LINE__, "s", "-- sanatising URI"); @@ -249,7 +255,7 @@ handler_t http_response_prepare(server *srv, connection *con) { } if (con->request.http_method == HTTP_METHOD_OPTIONS && - con->uri.path->ptr[0] == '*') { + con->uri.path->ptr[0] == '*' && con->uri.path_raw->ptr[1] == '\0') { /* option requests are handled directly without checking of the path */ response_header_insert(srv, con, CONST_STR_LEN("Allow"), CONST_STR_LEN("OPTIONS, GET, HEAD, POST"));