mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-14 08:15:02 -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 evhttp_connection *evcon;
|
||||
struct evkeyvalq *headers;
|
||||
int req_method;
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
@ -889,6 +890,7 @@ httpd_request_parse(struct evhttp_request *req, struct httpd_uri_parsed *uri_par
|
||||
hreq->req = req;
|
||||
hreq->uri_parsed = uri_parsed;
|
||||
hreq->query = &(uri_parsed->ev_query);
|
||||
req_method = 0;
|
||||
|
||||
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);
|
||||
else
|
||||
DPRINTF(E_LOG, L_HTTPD, "Connection to client lost or missing\n");
|
||||
|
||||
req_method = evhttp_request_get_command(req);
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
if (ret == 0)
|
||||
{
|
||||
|
@ -69,6 +69,7 @@ struct httpd_request {
|
||||
*/
|
||||
struct httpd_uri_map
|
||||
{
|
||||
int method;
|
||||
char *regexp;
|
||||
int (*handler)(struct httpd_request *hreq);
|
||||
regex_t preg;
|
||||
|
Loading…
Reference in New Issue
Block a user