Skip to content

Commit bd3a507

Browse files
committed
httpboot: Convert HTTP status codes to EFI status codes
This allows the caller to make a more informed decision about how to handle the error. In particular, by mapping HTTP errors to EFI_INVALID_PARAMETER and EFI_NOT_FOUND, shim will try to fetch the default second stage image like it does when loading images from disk. Note that this also changes the default to return EFI_HTTP_ERROR instead of EFI_ABORTED. This should not change any behavior as EFI_ABORTED wasn't being handled before, but letting the caller decide what to do with an unknown HTTP error is more appropriate. Signed-off-by: Dan Nicholson <[email protected]>
1 parent 4fa0495 commit bd3a507

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

httpboot.c

+46-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,51 @@ convert_http_status_code (EFI_HTTP_STATUS_CODE status_code)
5555
return 0;
5656
}
5757

58+
/* Convert an HTTP status code to an EFI status code. */
59+
static EFI_STATUS
60+
efi_status_from_http_status(EFI_HTTP_STATUS_CODE status_code)
61+
{
62+
switch (status_code) {
63+
case HTTP_STATUS_400_BAD_REQUEST:
64+
case HTTP_STATUS_411_LENGTH_REQUIRED:
65+
case HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE:
66+
case HTTP_STATUS_414_REQUEST_URI_TOO_LARGE:
67+
case HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE:
68+
case HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED:
69+
case HTTP_STATUS_417_EXPECTATION_FAILED:
70+
return EFI_INVALID_PARAMETER;
71+
case HTTP_STATUS_401_UNAUTHORIZED:
72+
case HTTP_STATUS_402_PAYMENT_REQUIRED:
73+
case HTTP_STATUS_403_FORBIDDEN:
74+
case HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED:
75+
return EFI_ACCESS_DENIED;
76+
case HTTP_STATUS_404_NOT_FOUND:
77+
case HTTP_STATUS_410_GONE:
78+
return EFI_NOT_FOUND;
79+
case HTTP_STATUS_405_METHOD_NOT_ALLOWED:
80+
case HTTP_STATUS_501_NOT_IMPLEMENTED:
81+
return EFI_UNSUPPORTED;
82+
case HTTP_STATUS_406_NOT_ACCEPTABLE:
83+
return EFI_NO_MEDIA;
84+
case HTTP_STATUS_408_REQUEST_TIME_OUT:
85+
case HTTP_STATUS_504_GATEWAY_TIME_OUT:
86+
return EFI_TIMEOUT;
87+
case HTTP_STATUS_409_CONFLICT:
88+
case HTTP_STATUS_412_PRECONDITION_FAILED:
89+
return EFI_MEDIA_CHANGED;
90+
case HTTP_STATUS_500_INTERNAL_SERVER_ERROR:
91+
case HTTP_STATUS_502_BAD_GATEWAY:
92+
return EFI_DEVICE_ERROR;
93+
case HTTP_STATUS_503_SERVICE_UNAVAILABLE:
94+
return EFI_NOT_READY;
95+
case HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED:
96+
return EFI_INCOMPATIBLE_VERSION;
97+
default:
98+
/* Use a generic HTTP error for anything else. */
99+
return EFI_HTTP_ERROR;
100+
}
101+
}
102+
58103
static EFI_DEVICE_PATH *devpath;
59104
static EFI_MAC_ADDRESS mac_addr;
60105
static IPv4_DEVICE_PATH ip4_node;
@@ -565,7 +610,7 @@ receive_http_response(EFI_HTTP_PROTOCOL *http, VOID **buffer, UINT64 *buf_size)
565610
if (http_status != HTTP_STATUS_200_OK) {
566611
perror(L"HTTP Status Code: %d\n",
567612
convert_http_status_code(http_status));
568-
efi_status = EFI_ABORTED;
613+
efi_status = efi_status_from_http_status(http_status);
569614
goto error;
570615
}
571616

0 commit comments

Comments
 (0)