mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 20:49:01 -04:00
Make http_body_rewind() public.
Also let this function reset offset and lengths for http_body_read(). Make sure of this function in the python code so req.body can be called multiple times in succession.
This commit is contained in:
parent
1f4aec43d9
commit
ec901d0339
@ -251,6 +251,7 @@ void http_request_free(struct http_request *);
|
||||
void http_request_sleep(struct http_request *);
|
||||
void http_request_wakeup(struct http_request *);
|
||||
void http_process_request(struct http_request *);
|
||||
int http_body_rewind(struct http_request *);
|
||||
ssize_t http_body_read(struct http_request *, void *, size_t);
|
||||
void http_response(struct http_request *, int, const void *, size_t);
|
||||
void http_serveable(struct http_request *, const void *,
|
||||
|
36
src/http.c
36
src/http.c
@ -42,7 +42,6 @@
|
||||
#endif
|
||||
|
||||
static int http_body_recv(struct netbuf *);
|
||||
static int http_body_rewind(struct http_request *);
|
||||
static void http_error_response(struct connection *, int);
|
||||
static void http_write_response_cookie(struct http_cookie *);
|
||||
static void http_argument_add(struct http_request *, char *, char *);
|
||||
@ -1191,6 +1190,25 @@ cleanup:
|
||||
kore_buf_free(out);
|
||||
}
|
||||
|
||||
int
|
||||
http_body_rewind(struct http_request *req)
|
||||
{
|
||||
if (req->http_body_fd != -1) {
|
||||
if (lseek(req->http_body_fd, 0, SEEK_SET) == -1) {
|
||||
kore_log(LOG_ERR, "lseek(%s) failed: %s",
|
||||
req->http_body_path, errno_s);
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
} else {
|
||||
kore_buf_reset(req->http_body);
|
||||
}
|
||||
|
||||
req->http_body_offset = 0;
|
||||
req->http_body_length = req->content_length;
|
||||
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
http_body_read(struct http_request *req, void *out, size_t len)
|
||||
{
|
||||
@ -1533,22 +1551,6 @@ http_body_recv(struct netbuf *nb)
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
http_body_rewind(struct http_request *req)
|
||||
{
|
||||
if (req->http_body_fd != -1) {
|
||||
if (lseek(req->http_body_fd, 0, SEEK_SET) == -1) {
|
||||
kore_log(LOG_ERR, "lseek(%s) failed: %s",
|
||||
req->http_body_path, errno_s);
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
} else {
|
||||
kore_buf_reset(req->http_body);
|
||||
}
|
||||
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
static void
|
||||
http_error_response(struct connection *c, int status)
|
||||
{
|
||||
|
@ -1017,6 +1017,7 @@ pyhttp_get_body(struct pyhttp_request *pyreq, void *closure)
|
||||
u_int8_t data[BUFSIZ];
|
||||
|
||||
kore_buf_init(&buf, 1024);
|
||||
http_body_rewind(pyreq->req);
|
||||
|
||||
for (;;) {
|
||||
ret = http_body_read(pyreq->req, data, sizeof(data));
|
||||
|
Loading…
x
Reference in New Issue
Block a user