Browse Source

[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 12 years ago
parent
commit
46df5c92a8
1 changed files with 10 additions and 6 deletions
  1. 10
    6
      src/net/tcp/httpcore.c

+ 10
- 6
src/net/tcp/httpcore.c View File

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

Loading…
Cancel
Save