commit ec901d03390396962970437d9659fd00dc3d5bfc
parent 1f4aec43d9256f76c79f789234fed8325eaacf08
Author: Joris Vink <joris@coders.se>
Date: Mon, 13 Mar 2017 11:17:55 +0100
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.
Diffstat:
3 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/includes/http.h b/includes/http.h
@@ -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 *,
diff --git a/src/http.c b/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)
{
diff --git a/src/python.c b/src/python.c
@@ -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));