/** RX state */
enum http_rx_state rx_state;
+ /** Response code */
+ unsigned int code;
/** Received length */
size_t rx_len;
/** Length remaining (or 0 if unknown) */
*/
static int http_rx_response ( struct http_request *http, char *response ) {
char *spc;
- unsigned int code;
- int rc;
DBGC ( http, "HTTP %p response \"%s\"\n", http, response );
if ( strncmp ( response, "HTTP/", 5 ) != 0 )
return -EINVAL_RESPONSE;
- /* Locate and check response code */
+ /* Locate and store response code */
spc = strchr ( response, ' ' );
if ( ! spc )
return -EINVAL_RESPONSE;
- code = strtoul ( spc, NULL, 10 );
- if ( ( rc = http_response_to_rc ( code ) ) != 0 )
- return rc;
+ http->code = strtoul ( spc, NULL, 10 );
/* Move to received headers */
http->rx_state = HTTP_RX_HEADER;
/* An empty header line marks the end of this phase */
if ( ! header[0] ) {
empty_line_buffer ( &http->linebuf );
+
+ /* Handle response code */
+ if ( ( rc = http_response_to_rc ( http->code ) ) != 0 )
+ return rc;
+
+ /* Move to next state */
if ( ( http->rx_state == HTTP_RX_HEADER ) &&
( ! ( http->flags & HTTP_HEAD_ONLY ) ) ) {
DBGC ( http, "HTTP %p start of data\n", http );