diff --git a/src/client.c b/src/client.c index bfcf4844..2cd16c7d 100644 --- a/src/client.c +++ b/src/client.c @@ -103,6 +103,50 @@ int client_create(client_t **c_ptr, connection_t *con, http_parser_t *parser) return ret; } +void client_complete(client_t *client) +{ + const char *header; + long long unsigned int scannumber; + int have = 0; + + if (!have) { + if (client->parser->req_type == httpp_req_source) { + client->request_body_length = -1; /* streaming */ + have = 1; + } + } + + if (!have) { + header = httpp_getvar(client->parser, "transfer-encoding"); + if (header) { + if (strcasecmp(header, "identity") != 0) { + client->request_body_length = -1; /* streaming */ + have = 1; + } + } + } + + if (!have) { + header = httpp_getvar(client->parser, "content-length"); + if (header) { + if (sscanf(header, "%llu", &scannumber) == 1) { + client->request_body_length = scannumber; + have = 1; + } + } + } + + if (!have) { + if (client->parser->req_type == httpp_req_put) { + /* As we don't know yet, we asume this PUT is in streaming mode */ + client->request_body_length = -1; /* streaming */ + have = 1; + } + } + + ICECAST_LOG_DEBUG("Client %p has request_body_length=%zi", client, client->request_body_length); +} + static inline void client_reuseconnection(client_t *client) { connection_t *con; reuse_t reuse; diff --git a/src/client.h b/src/client.h index e3c0bb58..ce34f5e0 100644 --- a/src/client.h +++ b/src/client.h @@ -137,6 +137,7 @@ struct _client_tag { }; int client_create (client_t **c_ptr, connection_t *con, http_parser_t *parser); +void client_complete(client_t *client); void client_destroy(client_t *client); void client_send_error_by_id(client_t *client, icecast_error_id_t id); void client_send_101(client_t *client, reuse_t reuse); diff --git a/src/connection.c b/src/connection.c index 30a34a7d..ead93786 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1429,50 +1429,6 @@ static void __prepare_shoutcast_admin_cgi_request(client_t *client) global_unlock(); } -static void _update_client_request_body_length(client_t *client) -{ - const char *header; - long long unsigned int scannumber; - int have = 0; - - if (!have) { - if (client->parser->req_type == httpp_req_source) { - client->request_body_length = -1; /* streaming */ - have = 1; - } - } - - if (!have) { - header = httpp_getvar(client->parser, "transfer-encoding"); - if (header) { - if (strcasecmp(header, "identity") != 0) { - client->request_body_length = -1; /* streaming */ - have = 1; - } - } - } - - if (!have) { - header = httpp_getvar(client->parser, "content-length"); - if (header) { - if (sscanf(header, "%llu", &scannumber) == 1) { - client->request_body_length = scannumber; - have = 1; - } - } - } - - if (!have) { - if (client->parser->req_type == httpp_req_put) { - /* As we don't know yet, we asume this PUT is in streaming mode */ - client->request_body_length = -1; /* streaming */ - have = 1; - } - } - - ICECAST_LOG_DEBUG("Client %p has request_body_length=%zi", client, client->request_body_length); -} - /* Check if we need body of client */ static int _need_body(client_queue_t *node) { @@ -1537,7 +1493,7 @@ static void _handle_connection(void) client->refbuf->len = 0; /* early check if we need more data */ - _update_client_request_body_length(client); + client_complete(client); if (_need_body(node)) { /* Just calling _add_body_client() would do the job. * However, if the client only has a small body this might work without moving it between queues.