mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-29 15:36:00 -05:00
[httpd] Support assigning request methods to uri handlers
This commit is contained in:
parent
a98713ba49
commit
1379ef235c
@ -880,6 +880,7 @@ httpd_request_parse(struct evhttp_request *req, struct httpd_uri_parsed *uri_par
|
|||||||
struct httpd_request *hreq;
|
struct httpd_request *hreq;
|
||||||
struct evhttp_connection *evcon;
|
struct evhttp_connection *evcon;
|
||||||
struct evkeyvalq *headers;
|
struct evkeyvalq *headers;
|
||||||
|
int req_method;
|
||||||
int i;
|
int i;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -889,6 +890,7 @@ httpd_request_parse(struct evhttp_request *req, struct httpd_uri_parsed *uri_par
|
|||||||
hreq->req = req;
|
hreq->req = req;
|
||||||
hreq->uri_parsed = uri_parsed;
|
hreq->uri_parsed = uri_parsed;
|
||||||
hreq->query = &(uri_parsed->ev_query);
|
hreq->query = &(uri_parsed->ev_query);
|
||||||
|
req_method = 0;
|
||||||
|
|
||||||
if (req)
|
if (req)
|
||||||
{
|
{
|
||||||
@ -900,6 +902,8 @@ httpd_request_parse(struct evhttp_request *req, struct httpd_uri_parsed *uri_par
|
|||||||
evhttp_connection_get_peer(evcon, &hreq->peer_address, &hreq->peer_port);
|
evhttp_connection_get_peer(evcon, &hreq->peer_address, &hreq->peer_port);
|
||||||
else
|
else
|
||||||
DPRINTF(E_LOG, L_HTTPD, "Connection to client lost or missing\n");
|
DPRINTF(E_LOG, L_HTTPD, "Connection to client lost or missing\n");
|
||||||
|
|
||||||
|
req_method = evhttp_request_get_command(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user_agent)
|
if (user_agent)
|
||||||
@ -908,6 +912,10 @@ httpd_request_parse(struct evhttp_request *req, struct httpd_uri_parsed *uri_par
|
|||||||
// Find a handler for the path
|
// Find a handler for the path
|
||||||
for (i = 0; uri_map[i].handler; i++)
|
for (i = 0; uri_map[i].handler; i++)
|
||||||
{
|
{
|
||||||
|
// Check if handler supports the current http request method
|
||||||
|
if (uri_map[i].method && req_method && !(req_method & uri_map[i].method))
|
||||||
|
continue;
|
||||||
|
|
||||||
ret = regexec(&uri_map[i].preg, uri_parsed->path, 0, NULL, 0);
|
ret = regexec(&uri_map[i].preg, uri_parsed->path, 0, NULL, 0);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
|
@ -69,6 +69,7 @@ struct httpd_request {
|
|||||||
*/
|
*/
|
||||||
struct httpd_uri_map
|
struct httpd_uri_map
|
||||||
{
|
{
|
||||||
|
int method;
|
||||||
char *regexp;
|
char *regexp;
|
||||||
int (*handler)(struct httpd_request *hreq);
|
int (*handler)(struct httpd_request *hreq);
|
||||||
regex_t preg;
|
regex_t preg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user