mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-11 05:14:46 -04:00
Allow registering callback for parsing HTTP headers
Slightly changed version of Espen Jürgensen's commit 548141e72312126fa6121f6a5f436đ251c7fb1251 for forked-daapd.
This commit is contained in:
parent
8d8decf114
commit
b0bd7fe1db
15
http.c
15
http.c
@ -2150,6 +2150,14 @@ evhttp_read_header(struct evhttp_connection *evcon,
|
|||||||
/* Disable reading for now */
|
/* Disable reading for now */
|
||||||
bufferevent_disable(evcon->bufev, EV_READ);
|
bufferevent_disable(evcon->bufev, EV_READ);
|
||||||
|
|
||||||
|
/* Callback can shut down connection with negative return value */
|
||||||
|
if (req->header_cb != NULL) {
|
||||||
|
if ((*req->header_cb)(req, req->cb_arg) < 0) {
|
||||||
|
evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Done reading headers, do the real work */
|
/* Done reading headers, do the real work */
|
||||||
switch (req->kind) {
|
switch (req->kind) {
|
||||||
case EVHTTP_REQUEST:
|
case EVHTTP_REQUEST:
|
||||||
@ -3818,6 +3826,13 @@ evhttp_request_set_chunked_cb(struct evhttp_request *req,
|
|||||||
req->chunk_cb = cb;
|
req->chunk_cb = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
evhttp_request_set_header_cb(struct evhttp_request *req,
|
||||||
|
int (*cb)(struct evhttp_request *, void *))
|
||||||
|
{
|
||||||
|
req->header_cb = cb;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
evhttp_request_set_error_cb(struct evhttp_request *req,
|
evhttp_request_set_error_cb(struct evhttp_request *req,
|
||||||
void (*cb)(enum evhttp_request_error, void *))
|
void (*cb)(enum evhttp_request_error, void *))
|
||||||
|
@ -504,6 +504,15 @@ struct evhttp_request *evhttp_request_new(
|
|||||||
void evhttp_request_set_chunked_cb(struct evhttp_request *,
|
void evhttp_request_set_chunked_cb(struct evhttp_request *,
|
||||||
void (*cb)(struct evhttp_request *, void *));
|
void (*cb)(struct evhttp_request *, void *));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register callback for additional parsing of request headers.
|
||||||
|
* @param cb will be called after receiving and parsing the full header.
|
||||||
|
* It allows analyzing the header and possibly closing the connection
|
||||||
|
* by returning a value < 0.
|
||||||
|
*/
|
||||||
|
void evhttp_request_set_header_cb(struct evhttp_request *,
|
||||||
|
int (*cb)(struct evhttp_request *, void *));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The different error types supported by evhttp
|
* The different error types supported by evhttp
|
||||||
*
|
*
|
||||||
|
@ -120,6 +120,14 @@ struct {
|
|||||||
* the regular callback.
|
* the regular callback.
|
||||||
*/
|
*/
|
||||||
void (*chunk_cb)(struct evhttp_request *, void *);
|
void (*chunk_cb)(struct evhttp_request *, void *);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Callback added for forked-daapd so they can collect ICY
|
||||||
|
* (shoutcast) metadata from the http header. If return
|
||||||
|
* int is negative the connection will be closed.
|
||||||
|
*/
|
||||||
|
int (*header_cb)(struct evhttp_request *, void *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Error callback - called when error is occured.
|
* Error callback - called when error is occured.
|
||||||
* @see evhttp_request_error for error types.
|
* @see evhttp_request_error for error types.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user