Explorar el Código

[http] Defer processing response code until after receiving all headers

Some headers can modify the meaning of the response code.  For
example, a WWW-Authenticate header can change the interpretation of a
401 Unauthorized response from "Access denied" to "Please
authenticate".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown hace 12 años
padre
commit
46df5c92a8
Se han modificado 1 ficheros con 10 adiciones y 6 borrados
  1. 10
    6
      src/net/tcp/httpcore.c

+ 10
- 6
src/net/tcp/httpcore.c Ver fichero

@@ -143,6 +143,8 @@ struct http_request {
143 143
 
144 144
 	/** RX state */
145 145
 	enum http_rx_state rx_state;
146
+	/** Response code */
147
+	unsigned int code;
146 148
 	/** Received length */
147 149
 	size_t rx_len;
148 150
 	/** Length remaining (or 0 if unknown) */
@@ -311,8 +313,6 @@ static int http_response_to_rc ( unsigned int response ) {
311 313
  */
312 314
 static int http_rx_response ( struct http_request *http, char *response ) {
313 315
 	char *spc;
314
-	unsigned int code;
315
-	int rc;
316 316
 
317 317
 	DBGC ( http, "HTTP %p response \"%s\"\n", http, response );
318 318
 
@@ -320,13 +320,11 @@ static int http_rx_response ( struct http_request *http, char *response ) {
320 320
 	if ( strncmp ( response, "HTTP/", 5 ) != 0 )
321 321
 		return -EINVAL_RESPONSE;
322 322
 
323
-	/* Locate and check response code */
323
+	/* Locate and store response code */
324 324
 	spc = strchr ( response, ' ' );
325 325
 	if ( ! spc )
326 326
 		return -EINVAL_RESPONSE;
327
-	code = strtoul ( spc, NULL, 10 );
328
-	if ( ( rc = http_response_to_rc ( code ) ) != 0 )
329
-		return rc;
327
+	http->code = strtoul ( spc, NULL, 10 );
330 328
 
331 329
 	/* Move to received headers */
332 330
 	http->rx_state = HTTP_RX_HEADER;
@@ -488,6 +486,12 @@ static int http_rx_header ( struct http_request *http, char *header ) {
488 486
 	/* An empty header line marks the end of this phase */
489 487
 	if ( ! header[0] ) {
490 488
 		empty_line_buffer ( &http->linebuf );
489
+
490
+		/* Handle response code */
491
+		if ( ( rc = http_response_to_rc ( http->code ) ) != 0 )
492
+			return rc;
493
+
494
+		/* Move to next state */
491 495
 		if ( ( http->rx_state == HTTP_RX_HEADER ) &&
492 496
 		     ( ! ( http->flags & HTTP_HEAD_ONLY ) ) ) {
493 497
 			DBGC ( http, "HTTP %p start of data\n", http );

Loading…
Cancelar
Guardar