1
0
mirror of https://github.com/lammertb/libhttp.git synced 2026-01-27 08:02:47 +03:00

Moved discard_unread_request_data to own file

This commit is contained in:
Lammert Bies
2016-12-11 12:45:28 +01:00
parent 7a364b9243
commit 400922328f
3 changed files with 67 additions and 38 deletions

View File

@@ -61,6 +61,7 @@ LIB_SOURCES = src/libhttp.c \
src/httplib_consume_socket.c \
src/httplib_delete_file.c \
src/httplib_dir_scan_callback.c \
src/httplib_discard_unread_request_data.c \
src/httplib_download.c \
src/httplib_fclose_on_exec.c \
src/httplib_fgets.c \

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 2016 Lammert Bies
* Copyright (c) 2013-2016 the Civetweb developers
* Copyright (c) 2004-2013 Sergey Lyubka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "libhttp-private.h"
void XX_httplib_discard_unread_request_data( struct mg_connection *conn ) {
char buf[MG_BUF_LEN];
size_t to_read;
int nread;
if (conn == NULL) {
return;
}
to_read = sizeof(buf);
if (conn->is_chunked) {
/* Chunked encoding: 1=chunk not read completely, 2=chunk read
* completely */
while (conn->is_chunked == 1) {
nread = mg_read(conn, buf, to_read);
if (nread <= 0) {
break;
}
}
} else {
/* Not chunked: content length is known */
while (conn->consumed_content < conn->content_len) {
if (to_read
> (size_t)(conn->content_len - conn->consumed_content)) {
to_read = (size_t)(conn->content_len - conn->consumed_content);
}
nread = mg_read(conn, buf, to_read);
if (nread <= 0) break;
}
}
} /* XX_httplib_discard_unread_request_data */

View File

@@ -2835,41 +2835,3 @@ int XX_httplib_pull_all( FILE *fp, struct mg_connection *conn, char *buf, int le
return nread;
} /* XX_httplib_pull_all */
void XX_httplib_discard_unread_request_data( struct mg_connection *conn ) {
char buf[MG_BUF_LEN];
size_t to_read;
int nread;
if (conn == NULL) {
return;
}
to_read = sizeof(buf);
if (conn->is_chunked) {
/* Chunked encoding: 1=chunk not read completely, 2=chunk read
* completely */
while (conn->is_chunked == 1) {
nread = mg_read(conn, buf, to_read);
if (nread <= 0) {
break;
}
}
} else {
/* Not chunked: content length is known */
while (conn->consumed_content < conn->content_len) {
if (to_read
> (size_t)(conn->content_len - conn->consumed_content)) {
to_read = (size_t)(conn->content_len - conn->consumed_content);
}
nread = mg_read(conn, buf, to_read);
if (nread <= 0) break;
}
}
} /* XX_httplib_discard_unread_request_data */