mirror of https://github.com/ipxe/ipxe.git
[http] Support HTTP redirection
parent
323cdf8c4c
commit
272e6ddc30
|
@ -138,6 +138,8 @@ static void http_done ( struct http_request *http, int rc ) {
|
||||||
static int http_response_to_rc ( unsigned int response ) {
|
static int http_response_to_rc ( unsigned int response ) {
|
||||||
switch ( response ) {
|
switch ( response ) {
|
||||||
case 200:
|
case 200:
|
||||||
|
case 301:
|
||||||
|
case 302:
|
||||||
return 0;
|
return 0;
|
||||||
case 404:
|
case 404:
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
@ -180,6 +182,28 @@ static int http_rx_response ( struct http_request *http, char *response ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle HTTP Location header
|
||||||
|
*
|
||||||
|
* @v http HTTP request
|
||||||
|
* @v value HTTP header value
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
static int http_rx_location ( struct http_request *http, const char *value ) {
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Redirect to new location */
|
||||||
|
DBGC ( http, "HTTP %p redirecting to %s\n", http, value );
|
||||||
|
if ( ( rc = xfer_redirect ( &http->xfer, LOCATION_URI_STRING,
|
||||||
|
value ) ) != 0 ) {
|
||||||
|
DBGC ( http, "HTTP %p could not redirect: %s\n",
|
||||||
|
http, strerror ( rc ) );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle HTTP Content-Length header
|
* Handle HTTP Content-Length header
|
||||||
*
|
*
|
||||||
|
@ -222,6 +246,10 @@ struct http_header_handler {
|
||||||
|
|
||||||
/** List of HTTP header handlers */
|
/** List of HTTP header handlers */
|
||||||
static struct http_header_handler http_header_handlers[] = {
|
static struct http_header_handler http_header_handlers[] = {
|
||||||
|
{
|
||||||
|
.header = "Location",
|
||||||
|
.rx = http_rx_location,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.header = "Content-Length",
|
.header = "Content-Length",
|
||||||
.rx = http_rx_content_length,
|
.rx = http_rx_content_length,
|
||||||
|
|
Loading…
Reference in New Issue