handler: add new event: UH_EV_HEAD_COMPLETE
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>main
parent
0a7a38a467
commit
06e3d76dc9
|
@ -64,7 +64,21 @@ static void upload_handler(struct uh_connection *conn, int event)
|
||||||
{
|
{
|
||||||
static int fd = -1;
|
static int fd = -1;
|
||||||
|
|
||||||
if (event == UH_EV_BODY) {
|
if (event == UH_EV_HEAD_COMPLETE) {
|
||||||
|
struct uh_str str = conn->get_header(conn, "Content-Length");
|
||||||
|
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) {
|
||||||
|
conn->error(conn, HTTP_STATUS_INTERNAL_SERVER_ERROR, "Too big");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} if (event == UH_EV_BODY) {
|
||||||
struct uh_str body = conn->extract_body(conn);
|
struct uh_str body = conn->extract_body(conn);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -80,7 +94,7 @@ static void upload_handler(struct uh_connection *conn, int event)
|
||||||
close(fd);
|
close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (event == UH_EV_COMPLETE) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
|
|
|
@ -389,6 +389,11 @@ done:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn->handler(conn, UH_EV_HEAD_COMPLETE);
|
||||||
|
|
||||||
|
if (conn->flags & CONN_F_SEND_AND_CLOSE)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ struct uh_plugin {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
UH_EV_HEAD_COMPLETE,
|
||||||
UH_EV_BODY,
|
UH_EV_BODY,
|
||||||
UH_EV_COMPLETE
|
UH_EV_COMPLETE
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue