connection: New API: get_content_length
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>main^2
parent
fa6248b1f1
commit
2f12b7d434
|
@ -62,13 +62,7 @@ void echo_handler(struct uh_connection *conn, int event)
|
||||||
void upload_handler(struct uh_connection *conn, int event)
|
void upload_handler(struct uh_connection *conn, int event)
|
||||||
{
|
{
|
||||||
if (event == UH_EV_HEAD_COMPLETE) {
|
if (event == UH_EV_HEAD_COMPLETE) {
|
||||||
struct uh_str str = conn->get_header(conn, "Content-Length");
|
uint64_t content_length = conn->get_content_length(conn);
|
||||||
int content_length;
|
|
||||||
char buf[128];
|
|
||||||
|
|
||||||
sprintf(buf, "%.*s\n", (int)str.len, str.p);
|
|
||||||
|
|
||||||
content_length = atoi(buf);
|
|
||||||
|
|
||||||
if (content_length > 1024 * 1024 * 1024) {
|
if (content_length > 1024 * 1024 * 1024) {
|
||||||
conn->error(conn, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Too big");
|
conn->error(conn, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Too big");
|
||||||
|
|
|
@ -305,6 +305,13 @@ static struct uh_str conn_get_header(struct uh_connection *conn, const char *nam
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint64_t conn_get_content_length(struct uh_connection *conn)
|
||||||
|
{
|
||||||
|
struct uh_connection_internal *conni = (struct uh_connection_internal *)conn;
|
||||||
|
|
||||||
|
return conni->parser.content_length;
|
||||||
|
}
|
||||||
|
|
||||||
static struct uh_str conn_get_body(struct uh_connection *conn)
|
static struct uh_str conn_get_body(struct uh_connection *conn)
|
||||||
{
|
{
|
||||||
struct uh_connection_internal *conni = (struct uh_connection_internal *)conn;
|
struct uh_connection_internal *conni = (struct uh_connection_internal *)conn;
|
||||||
|
@ -752,6 +759,7 @@ static void conn_init_cb(struct uh_connection *conn)
|
||||||
conn->get_path = conn_get_path;
|
conn->get_path = conn_get_path;
|
||||||
conn->get_query = conn_get_query;
|
conn->get_query = conn_get_query;
|
||||||
conn->get_header = conn_get_header;
|
conn->get_header = conn_get_header;
|
||||||
|
conn->get_content_length = conn_get_content_length;
|
||||||
conn->get_body = conn_get_body;
|
conn->get_body = conn_get_body;
|
||||||
conn->extract_body = conn_extract_body;
|
conn->extract_body = conn_extract_body;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ struct uh_connection {
|
||||||
struct uh_str (*get_path)(struct uh_connection *conn);
|
struct uh_str (*get_path)(struct uh_connection *conn);
|
||||||
struct uh_str (*get_query)(struct uh_connection *conn);
|
struct uh_str (*get_query)(struct uh_connection *conn);
|
||||||
struct uh_str (*get_header)(struct uh_connection *conn, const char *name);
|
struct uh_str (*get_header)(struct uh_connection *conn, const char *name);
|
||||||
|
uint64_t (*get_content_length)(struct uh_connection *conn);
|
||||||
struct uh_str (*get_body)(struct uh_connection *conn);
|
struct uh_str (*get_body)(struct uh_connection *conn);
|
||||||
/* The remain body data will be discurd after this function called */
|
/* The remain body data will be discurd after this function called */
|
||||||
struct uh_str (*extract_body)(struct uh_connection *conn);
|
struct uh_str (*extract_body)(struct uh_connection *conn);
|
||||||
|
|
Loading…
Reference in New Issue