mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-06-16 02:15:48 +00:00
refactoring [2]
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -152,10 +152,7 @@ forbidden:
|
||||
}
|
||||
|
||||
uwsgi_response_write_body(wsgi_req, "Unauthorized", 12);
|
||||
|
||||
end:
|
||||
// for security
|
||||
wsgi_req->status = 401;
|
||||
return UWSGI_ROUTE_BREAK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user