From d3dfdbb0ba84d8017e777b2002b18661196cd56f Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sun, 20 Jan 2013 15:34:24 +0100 Subject: [PATCH] refactoring [2] --- plugins/router_access/router_access.c | 2 +- plugins/router_basicauth/router_basicauth.c | 21 ++++----------------- plugins/router_cache/router_cache.c | 2 +- plugins/router_spnego/router_spnego.c | 3 --- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/plugins/router_access/router_access.c b/plugins/router_access/router_access.c index 99c3bb51..ba8fcc1e 100644 --- a/plugins/router_access/router_access.c +++ b/plugins/router_access/router_access.c @@ -59,7 +59,7 @@ static int uwsgi_routing_func_access(struct wsgi_request *wsgi_req, struct uwsgi forbidden: if (uwsgi_response_prepare_headers(wsgi_req, "403 Forbidden", 13)) goto end; - if (uwsgi_response_add_header(wsgi_req, "Content-Type", 12 ,"text/plain", 10)) goto end; + if (uwsgi_response_add_content_type(wsgi_req, "text/plain", 10)) goto end; uwsgi_response_write_body_do(wsgi_req, "Forbidden", 9); end: return UWSGI_ROUTE_BREAK; diff --git a/plugins/router_basicauth/router_basicauth.c b/plugins/router_basicauth/router_basicauth.c index 3803193f..a61dd8e4 100644 --- a/plugins/router_basicauth/router_basicauth.c +++ b/plugins/router_basicauth/router_basicauth.c @@ -61,20 +61,6 @@ static uint16_t htpasswd_check(char *filename, char *auth) { int uwsgi_routing_func_basicauth(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) { -/* - struct iovec iov[4]; - - if (wsgi_req->protocol_len > 0) { - iov[0].iov_base = wsgi_req->protocol; - iov[0].iov_len = wsgi_req->protocol_len; - } - else { - iov[0].iov_base = "HTTP/1.0"; - iov[0].iov_len = 8; - } -*/ - - // check for "Basic =" string at least if (wsgi_req->authorization_len > 7 && ur->data2_len > 0) { if (strncmp(wsgi_req->authorization, "Basic ", 6)) goto forbidden; @@ -114,12 +100,13 @@ int uwsgi_routing_func_basicauth(struct wsgi_request *wsgi_req, struct uwsgi_rou } forbidden: - uwsgi_response_prepare_headers(wsgi_req, "401 Authorization Required", 26); + if (uwsgi_response_prepare_headers(wsgi_req, "401 Authorization Required", 26)) goto end; char *realm = uwsgi_concat3n("Basic realm=\"", 13, ur->data, ur->data_len, "\"", 1); - uwsgi_response_add_header(wsgi_req, "WWW-Authenticate", 16, realm, 13 + ur->data_len + 1); + int ret = uwsgi_response_add_header(wsgi_req, "WWW-Authenticate", 16, realm, 13 + ur->data_len + 1); free(realm); + if (ret) goto end; uwsgi_response_write_body_do(wsgi_req, "Unauthorized", 12); - +end: return UWSGI_ROUTE_BREAK; } diff --git a/plugins/router_cache/router_cache.c b/plugins/router_cache/router_cache.c index 51a5112d..fff93a5b 100644 --- a/plugins/router_cache/router_cache.c +++ b/plugins/router_cache/router_cache.c @@ -65,7 +65,7 @@ static int uwsgi_routing_func_cache(struct wsgi_request *wsgi_req, struct uwsgi_ if (value) { if (urcc->type_num == 1) { if (uwsgi_response_prepare_headers(wsgi_req, "200 OK", 6)) goto error; - if (uwsgi_response_add_header(wsgi_req, "Content-Type", 12, urcc->content_type, urcc->content_type_len)) goto error; + if (uwsgi_response_add_content_type(wsgi_req, urcc->content_type, urcc->content_type_len)) goto error; if (uwsgi_response_add_content_length(wsgi_req, valsize)) goto error; } // body only diff --git a/plugins/router_spnego/router_spnego.c b/plugins/router_spnego/router_spnego.c index ff8289ab..7c970833 100644 --- a/plugins/router_spnego/router_spnego.c +++ b/plugins/router_spnego/router_spnego.c @@ -152,10 +152,7 @@ forbidden: } uwsgi_response_write_body(wsgi_req, "Unauthorized", 12); - end: - // for security - wsgi_req->status = 401; return UWSGI_ROUTE_BREAK; }