summaryrefslogtreecommitdiffstats
path: root/src/net/tcp/httpbasic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tcp/httpbasic.c')
-rw-r--r--src/net/tcp/httpbasic.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/net/tcp/httpbasic.c b/src/net/tcp/httpbasic.c
index 7ed7de9e..52a67063 100644
--- a/src/net/tcp/httpbasic.c
+++ b/src/net/tcp/httpbasic.c
@@ -43,13 +43,32 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
"No username available for Basic authentication" )
/**
+ * Parse HTTP "WWW-Authenticate" header for Basic authentication
+ *
+ * @v http HTTP transaction
+ * @v line Remaining header line
+ * @ret rc Return status code
+ */
+static int http_parse_basic_auth ( struct http_transaction *http,
+ char *line __unused ) {
+
+ /* Allow HTTP request to be retried if the request had not
+ * already tried authentication.
+ */
+ if ( ! http->request.auth.auth )
+ http->response.flags |= HTTP_RESPONSE_RETRY;
+
+ return 0;
+}
+
+/**
* Perform HTTP Basic authentication
*
* @v http HTTP transaction
* @ret rc Return status code
*/
static int http_basic_authenticate ( struct http_transaction *http ) {
- struct http_request_auth *req = &http->request.auth;
+ struct http_request_auth_basic *req = &http->request.auth.basic;
/* Record username and password */
if ( ! http->uri->user ) {
@@ -73,7 +92,7 @@ static int http_basic_authenticate ( struct http_transaction *http ) {
*/
static int http_format_basic_auth ( struct http_transaction *http,
char *buf, size_t len ) {
- struct http_request_auth *req = &http->request.auth;
+ struct http_request_auth_basic *req = &http->request.auth.basic;
size_t user_pw_len = ( strlen ( req->username ) + 1 /* ":" */ +
strlen ( req->password ) );
char user_pw[ user_pw_len + 1 /* NUL */ ];
@@ -93,6 +112,7 @@ static int http_format_basic_auth ( struct http_transaction *http,
/** HTTP Basic authentication scheme */
struct http_authentication http_basic_auth __http_authentication = {
.name = "Basic",
+ .parse = http_parse_basic_auth,
.authenticate = http_basic_authenticate,
.format = http_format_basic_auth,
};