mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 20:49:01 -04:00
Kore can now do query strings without lots of dynamic handler voodoo.
Any handler can receive query strings, however if you do not specify parameters allowed in a param {} block Kore will discard them.
This commit is contained in:
parent
ef4289689f
commit
517de46790
@ -131,6 +131,7 @@ struct http_request {
|
||||
struct spdy_stream *stream;
|
||||
struct kore_buf *post_data;
|
||||
void *hdlr_extra;
|
||||
char *query_string;
|
||||
u_int8_t *multipart_body;
|
||||
struct kore_module_handle *hdlr;
|
||||
|
||||
|
@ -110,17 +110,14 @@ domain localhost {
|
||||
static /lock-test serve_lock_test
|
||||
static /validator serve_validator
|
||||
|
||||
#
|
||||
# We can use a dynamic handler to accept GET parameters.
|
||||
#
|
||||
dynamic ^/params-test(\??)[A-Z0-9a-z=&]*$ serve_params_test
|
||||
static /params-test serve_params_test
|
||||
|
||||
# Configure /params-test POST to only accept the following parameters.
|
||||
# They are automatically tested against the validator listed.
|
||||
# If the validator would fail Kore will automatically remove the
|
||||
# failing parameter, indicating something was wrong with it.
|
||||
# Any parameters not present in the params block are also filtered out.
|
||||
params post ^/params-test(\??)[A-Z0-9a-z=&]*$ {
|
||||
params post /params-test {
|
||||
validate test1 v_example
|
||||
validate test2 v_regex
|
||||
}
|
||||
@ -128,7 +125,7 @@ domain localhost {
|
||||
# Configure a GET parameter that /params-test can received. As before
|
||||
# this is validated against the validator and removed if validation
|
||||
# fails. All extra parameters in the GET query are filtered out.
|
||||
params get ^/params-test(\??)[A-Z0-9a-z=&]*$ {
|
||||
params get /params-test {
|
||||
validate arg1 v_example
|
||||
validate id v_number
|
||||
}
|
||||
|
11
src/http.c
11
src/http.c
@ -80,6 +80,7 @@ http_request_new(struct connection *c, struct spdy_stream *s, char *host,
|
||||
req->stream = s;
|
||||
req->post_data = NULL;
|
||||
req->hdlr_extra = NULL;
|
||||
req->query_string = NULL;
|
||||
req->multipart_body = NULL;
|
||||
|
||||
if ((p = strrchr(host, ':')) != NULL)
|
||||
@ -88,6 +89,9 @@ http_request_new(struct connection *c, struct spdy_stream *s, char *host,
|
||||
kore_strlcpy(req->host, host, sizeof(req->host));
|
||||
kore_strlcpy(req->path, path, sizeof(req->path));
|
||||
|
||||
if ((req->query_string = strchr(req->path, '?')) != NULL)
|
||||
*(req->query_string)++ = '\0';
|
||||
|
||||
TAILQ_INIT(&(req->resp_headers));
|
||||
TAILQ_INIT(&(req->req_headers));
|
||||
TAILQ_INIT(&(req->arguments));
|
||||
@ -516,15 +520,14 @@ http_populate_arguments(struct http_request *req)
|
||||
{
|
||||
u_int32_t len;
|
||||
int i, v, c, count;
|
||||
char *p, *query, *args[HTTP_MAX_QUERY_ARGS], *val[3];
|
||||
char *query, *args[HTTP_MAX_QUERY_ARGS], *val[3];
|
||||
|
||||
if (req->method == HTTP_METHOD_POST) {
|
||||
query = http_post_data_text(req);
|
||||
} else {
|
||||
if ((p = strchr(req->path, '?')) == NULL)
|
||||
if (req->query_string == NULL)
|
||||
return (0);
|
||||
p++;
|
||||
query = kore_strdup(p);
|
||||
query = kore_strdup(req->query_string);
|
||||
}
|
||||
|
||||
count = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user