Browse Source

[http] Send authentication information whenever username is present

Send authentication information if the username is present, even if
the password is empty.
tags/v0.9.7
Michael Brown 15 years ago
parent
commit
54840039f6
1 changed files with 8 additions and 9 deletions
  1. 8
    9
      src/net/tcp/http.c

+ 8
- 9
src/net/tcp/http.c View File

391
 	const char *host = http->uri->host;
391
 	const char *host = http->uri->host;
392
 	const char *query = http->uri->query;
392
 	const char *query = http->uri->query;
393
 	const char *user = http->uri->user;
393
 	const char *user = http->uri->user;
394
-	const char *password = http->uri->password;
395
-	size_t user_pw_len = ( ( user && password ) ?
396
-			       ( strlen ( user ) + 1 /* ":" */ +
397
-				 strlen ( password ) ) : 0 );
394
+	const char *password =
395
+		( http->uri->password ? http->uri->password : "" );
396
+	size_t user_pw_len = ( user ? ( strlen ( user ) + 1 /* ":" */ +
397
+					strlen ( password ) ) : 0 );
398
 	size_t user_pw_base64_len = base64_encoded_len ( user_pw_len );
398
 	size_t user_pw_base64_len = base64_encoded_len ( user_pw_len );
399
 	char user_pw[ user_pw_len + 1 /* NUL */ ];
399
 	char user_pw[ user_pw_len + 1 /* NUL */ ];
400
 	char user_pw_base64[ user_pw_base64_len + 1 /* NUL */ ];
400
 	char user_pw_base64[ user_pw_base64_len + 1 /* NUL */ ];
406
 		process_del ( &http->process );
406
 		process_del ( &http->process );
407
 
407
 
408
 		/* Construct authorisation, if applicable */
408
 		/* Construct authorisation, if applicable */
409
-		if ( user_pw_len ) {
409
+		if ( user ) {
410
 			char *buf = user_pw;
410
 			char *buf = user_pw;
411
 			ssize_t remaining = sizeof ( user_pw );
411
 			ssize_t remaining = sizeof ( user_pw );
412
 			size_t len;
412
 			size_t len;
435
 					  ( path ? path : "/" ),
435
 					  ( path ? path : "/" ),
436
 					  ( query ? "?" : "" ),
436
 					  ( query ? "?" : "" ),
437
 					  ( query ? query : "" ),
437
 					  ( query ? query : "" ),
438
-					  ( user_pw_len ?
438
+					  ( user ?
439
 					    "Authorization: Basic " : "" ),
439
 					    "Authorization: Basic " : "" ),
440
-					  ( user_pw_len ?
441
-					    user_pw_base64 : "" ),
442
-					  ( user_pw_len ? "\r\n" : "" ),
440
+					  ( user ? user_pw_base64 : "" ),
441
+					  ( user ? "\r\n" : "" ),
443
 					  host ) ) != 0 ) {
442
 					  host ) ) != 0 ) {
444
 			http_done ( http, rc );
443
 			http_done ( http, rc );
445
 		}
444
 		}

Loading…
Cancel
Save