>From efe05201a5b572e78350be71e3c01ac70392985e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sun, 17 Oct 2010 20:25:49 +0200 Subject: [PATCH 4/8] Use Proxy-Authorization instead of Authorization for proxy auth When using http_proxy, the authentication header is not correctly set: it uses the same "Authorization" header as the http one. Here is a patch to adapt the behaviour with proxies (thanks to Louis Opter helping me pointing out the issue). --- stream/http.c | 18 ++++++++++++++---- stream/http.h | 1 + stream/network.c | 5 ++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/stream/http.c b/stream/http.c index 7c48bdc..d992369 100644 --- a/stream/http.c +++ b/stream/http.c @@ -603,8 +603,8 @@ http_set_uri( HTTP_header_t *http_hdr, const char *uri ) { strcpy( http_hdr->uri, uri ); } -int -http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) { +static int +http_add_authentication( HTTP_header_t *http_hdr, const char *username, const char *password, const char *auth_str ) { char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL; int encoded_len, pass_len=0, out_len; int res = -1; @@ -655,13 +655,13 @@ http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, co b64_usr_pass[out_len]='\0'; - auth = malloc(encoded_len+22); + auth = malloc(encoded_len + strlen(auth_str) + sizeof(": Basic ")); if( auth==NULL ) { mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); goto out; } - sprintf( auth, "Authorization: Basic %s", b64_usr_pass); + sprintf( auth, "%s: Basic %s", auth_str, b64_usr_pass); http_set_field( http_hdr, auth ); res = 0; @@ -675,6 +675,16 @@ out: return res; } +int +http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) { + return http_add_authentication(http_hdr, username, password, "Authorization"); +} + +int +http_add_basic_proxy_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) { + return http_add_authentication(http_hdr, username, password, "Proxy-Authorization"); +} + void http_debug_hdr( HTTP_header_t *http_hdr ) { HTTP_field_t *field; diff --git a/stream/http.h b/stream/http.h index c52b9c8..d24ec45 100644 --- a/stream/http.h +++ b/stream/http.h @@ -63,6 +63,7 @@ void http_set_field( HTTP_header_t *http_hdr, const char *field_name ); void http_set_method( HTTP_header_t *http_hdr, const char *method ); void http_set_uri( HTTP_header_t *http_hdr, const char *uri ); int http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ); +int http_add_basic_proxy_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ); void http_debug_hdr( HTTP_header_t *http_hdr ); diff --git a/stream/network.c b/stream/network.c index 4853f87..7de834f 100644 --- a/stream/network.c +++ b/stream/network.c @@ -254,7 +254,10 @@ http_send_request( URL_t *url, off_t pos ) { if (network_cookies_enabled) cookies_set( http_hdr, server_url->hostname, server_url->url ); http_set_field( http_hdr, "Connection: close"); - http_add_basic_authentication( http_hdr, url->username, url->password ); + if (proxy) + http_add_basic_proxy_authentication( http_hdr, url->username, url->password ); + else + http_add_basic_authentication( http_hdr, url->username, url->password ); if( http_build_request( http_hdr )==NULL ) { goto err_out; } -- 1.7.3.1