[http] Ignore unrecognised "Connection" header tokens

Some HTTP/2 servers send the header "Connection: upgrade, close".  This
currently causes iPXE to fail due to the unrecognised "upgrade" token.

Fix by ignoring any unrecognised tokens in the "Connection" header.

Reported-by: Ján ONDREJ (SAL) <ondrejj@salstar.sk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2016-05-25 15:27:50 +01:00
parent 80dd6cbcc4
commit f42b2585fe

View File

@@ -189,8 +189,8 @@ char * http_token ( char **line, char **value ) {
if ( value ) if ( value )
*value = NULL; *value = NULL;
/* Skip any initial whitespace */ /* Skip any initial whitespace or commas */
while ( isspace ( **line ) ) while ( ( isspace ( **line ) ) || ( **line == ',' ) )
(*line)++; (*line)++;
/* Check for end of line and record token position */ /* Check for end of line and record token position */
@@ -201,8 +201,8 @@ char * http_token ( char **line, char **value ) {
/* Scan for end of token */ /* Scan for end of token */
while ( ( c = **line ) ) { while ( ( c = **line ) ) {
/* Terminate if we hit an unquoted whitespace */ /* Terminate if we hit an unquoted whitespace or comma */
if ( isspace ( c ) && ! quote ) if ( ( isspace ( c ) || ( c == ',' ) ) && ! quote )
break; break;
/* Terminate if we hit a closing quote */ /* Terminate if we hit a closing quote */
@@ -1315,19 +1315,17 @@ http_response_transfer_encoding __http_response_header = {
* @ret rc Return status code * @ret rc Return status code
*/ */
static int http_parse_connection ( struct http_transaction *http, char *line ) { static int http_parse_connection ( struct http_transaction *http, char *line ) {
char *token;
/* Check for known connection intentions */ /* Check for known connection intentions */
if ( strcasecmp ( line, "keep-alive" ) == 0 ) { while ( ( token = http_token ( &line, NULL ) ) ) {
http->response.flags |= HTTP_RESPONSE_KEEPALIVE; if ( strcasecmp ( token, "keep-alive" ) == 0 )
return 0; http->response.flags |= HTTP_RESPONSE_KEEPALIVE;
} if ( strcasecmp ( token, "close" ) == 0 )
if ( strcasecmp ( line, "close" ) == 0 ) { http->response.flags &= ~HTTP_RESPONSE_KEEPALIVE;
http->response.flags &= ~HTTP_RESPONSE_KEEPALIVE;
return 0;
} }
DBGC ( http, "HTTP %p unrecognised Connection \"%s\"\n", http, line ); return 0;
return -ENOTSUP_CONNECTION;
} }
/** HTTP "Connection" header */ /** HTTP "Connection" header */