Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added setfile routing instruction and improved uwsgi_get_var

  • Loading branch information...
commit 4d9a88e999ba48d4b4b52b786a127edae315398c 1 parent 252e848
@unbit authored
Showing with 32 additions and 2 deletions.
  1. +26 −0 core/routing.c
  2. +6 −2 core/utils.c
View
26 core/routing.c
@@ -731,6 +731,31 @@ static int uwsgi_router_sethome(struct uwsgi_route *ur, char *arg) {
return 0;
}
+// setfile route
+static int uwsgi_router_setfile_func(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) {
+ char **subject = (char **) (((char *)(wsgi_req))+ur->subject);
+ uint16_t *subject_len = (uint16_t *) (((char *)(wsgi_req))+ur->subject_len);
+
+ struct uwsgi_buffer *ub = uwsgi_routing_translate(wsgi_req, ur, *subject, *subject_len, ur->data, ur->data_len);
+ if (!ub) return UWSGI_ROUTE_BREAK;
+ char *ptr = uwsgi_req_append(wsgi_req, "UWSGI_HOME", 10, ub->buf, ub->pos);
+ if (!ptr) {
+ uwsgi_buffer_destroy(ub);
+ return UWSGI_ROUTE_BREAK;
+ }
+ wsgi_req->file = ptr;
+ wsgi_req->file_len = ub->pos;
+ wsgi_req->dynamic = 1;
+ uwsgi_buffer_destroy(ub);
+ return UWSGI_ROUTE_NEXT;
+}
+static int uwsgi_router_setfile(struct uwsgi_route *ur, char *arg) {
+ ur->func = uwsgi_router_setfile_func;
+ ur->data = arg;
+ ur->data_len = strlen(arg);
+ return 0;
+}
+
// send route
@@ -956,6 +981,7 @@ void uwsgi_register_embedded_routers() {
uwsgi_register_router("chdir", uwsgi_router_chdir);
uwsgi_register_router("setapp", uwsgi_router_setapp);
uwsgi_register_router("sethome", uwsgi_router_sethome);
+ uwsgi_register_router("setfile", uwsgi_router_setfile);
uwsgi_register_route_condition("exists", uwsgi_route_condition_exists);
uwsgi_register_route_condition("isfile", uwsgi_route_condition_isfile);
View
8 core/utils.c
@@ -3054,18 +3054,22 @@ void http_url_decode(char *buf, uint16_t * len, char *dst) {
}
+/*
+ we have to scan the whole table as new vars could be added during the request
+*/
char *uwsgi_get_var(struct wsgi_request *wsgi_req, char *key, uint16_t keylen, uint16_t * len) {
int i;
+ char *found_ptr = NULL;
for (i = 0; i < wsgi_req->var_cnt; i += 2) {
if (!uwsgi_strncmp(key, keylen, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len)) {
*len = wsgi_req->hvec[i + 1].iov_len;
- return wsgi_req->hvec[i + 1].iov_base;
+ found_ptr = wsgi_req->hvec[i + 1].iov_base;
}
}
- return NULL;
+ return found_ptr;
}
struct uwsgi_app *uwsgi_add_app(int id, uint8_t modifier1, char *mountpoint, int mountpoint_len, void *interpreter, void *callable) {
Please sign in to comment.
Something went wrong with that request. Please try again.