static ngx_int_t
ngx_http_auth_basic_set_realm(ngx_http_request_t *r, ngx_str_t *realm)
{
- size_t len;
- u_char *basic, *p;
+ size_t len;
+ u_char *basic, *p;
+ ngx_table_elt_t *h;
- r->headers_out.www_authenticate = ngx_list_push(&r->headers_out.headers);
- if (r->headers_out.www_authenticate == NULL) {
+ h = ngx_list_push(&r->headers_out.headers);
+ if (h == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
basic = ngx_pnalloc(r->pool, len);
if (basic == NULL) {
- r->headers_out.www_authenticate->hash = 0;
- r->headers_out.www_authenticate = NULL;
+ h->hash = 0;
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
p = ngx_cpymem(p, realm->data, realm->len);
*p = '"';
- r->headers_out.www_authenticate->hash = 1;
- r->headers_out.www_authenticate->next = NULL;
- ngx_str_set(&r->headers_out.www_authenticate->key, "WWW-Authenticate");
- r->headers_out.www_authenticate->value.data = basic;
- r->headers_out.www_authenticate->value.len = len;
+ h->hash = 1;
+ h->next = NULL;
+ h->value.data = basic;
+ h->value.len = len;
+
+ if (ngx_http_proxy_auth(r)) {
+ r->headers_out.proxy_authenticate = h;
+ ngx_str_set(&h->key, "Proxy-Authenticate");
+ return NGX_HTTP_PROXY_AUTH_REQUIRED;
- return NGX_HTTP_UNAUTHORIZED;
+ } else {
+ r->headers_out.www_authenticate = h;
+ ngx_str_set(&h->key, "WWW-Authenticate");
+ return NGX_HTTP_UNAUTHORIZED;
+ }
}
if (rc == NGX_OK) {
r->access_code = 0;
- for (h = r->headers_out.www_authenticate; h; h = h->next) {
+ h = ngx_http_proxy_auth(r) ? r->headers_out.proxy_authenticate
+ : r->headers_out.www_authenticate;
+
+ for ( /* void */ ; h; h = h->next) {
h->hash = 0;
}
ngx_int_t
ngx_http_auth_basic_user(ngx_http_request_t *r)
{
- ngx_str_t auth, encoded;
- ngx_uint_t len;
+ ngx_str_t auth, encoded;
+ ngx_uint_t len;
+ ngx_table_elt_t *h;
if (r->headers_in.user.len == 0 && r->headers_in.user.data != NULL) {
return NGX_DECLINED;
}
- if (r->headers_in.authorization == NULL) {
+ h = ngx_http_proxy_auth(r) ? r->headers_in.proxy_authorization
+ : r->headers_in.authorization;
+
+ if (h == NULL) {
r->headers_in.user.data = (u_char *) "";
return NGX_DECLINED;
}
- encoded = r->headers_in.authorization->value;
+ encoded = h->value;
if (encoded.len < sizeof("Basic ") - 1
|| ngx_strncasecmp(encoded.data, (u_char *) "Basic ",