/* Callback */
void (*cb)(struct evhttp_request *, void *);
void *cb_arg;
+
+ /*
+ * Chunked data callback - call for each completed chunk if
+ * specified. If not specified, all the data is delivered via
+ * the regular callback.
+ */
+ void (*chunk_cb)(struct evhttp_request *, void *);
};
/*
*/
struct evhttp_request *evhttp_request_new(
void (*cb)(struct evhttp_request *, void *), void *arg);
+void evhttp_request_set_chunked_cb(struct evhttp_request *,
+ void (*cb)(struct evhttp_request *, void *));
/* Frees the request object and removes associated events. */
void evhttp_request_free(struct evhttp_request *req);
int error;
if (p == NULL)
break;
+ /* the last chunk is on a new line? */
+ if (strlen(p) == 0)
+ continue;
req->ntoread = strtol(p, &endp, 16);
error = *p == '\0' || *endp != '\0';
free(p);
/* Last chunk */
return (1);
}
- } else if (len >= req->ntoread) {
- /* Completed chunk */
- evbuffer_add(req->input_buffer,
- EVBUFFER_DATA(buf), req->ntoread);
- evbuffer_drain(buf, req->ntoread);
- req->ntoread = -1;
- if (req->cb != NULL) {
- (*req->cb)(req, req->cb_arg);
- /* XXX(niels): not sure if i like semantics */
- evbuffer_drain(req->input_buffer,
- EVBUFFER_LENGTH(req->input_buffer));
- }
+ continue;
+ }
+
+ /* don't have enough to complete a chunk; wait for more */
+ if (len < req->ntoread)
+ return (0);
+
+ /* Completed chunk */
+ evbuffer_add(req->input_buffer,
+ EVBUFFER_DATA(buf), req->ntoread);
+ evbuffer_drain(buf, req->ntoread);
+ req->ntoread = -1;
+ if (req->chunk_cb != NULL) {
+ (*req->chunk_cb)(req, req->cb_arg);
+ evbuffer_drain(req->input_buffer,
+ EVBUFFER_LENGTH(req->input_buffer));
}
}
free(req);
}
+void
+evhttp_request_set_chunked_cb(struct evhttp_request *req,
+ void (*cb)(struct evhttp_request *, void *))
+{
+ req->chunk_cb = cb;
+}
+
/*
* Allows for inspection of the request URI
*/