Commit c40d12a1 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Update: Moved _update_client_request_body_length() into new client_complete()

parent c0155e24
......@@ -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;
......
......@@ -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);
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment