mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 03:12:41 +00:00
Add ability to configure CORS header (#1345)
## Issue Addressed https://github.com/sigp/lighthouse/issues/1177 ## Proposed Changes Add a command line option (`--http-allow-origin`) and a config item for configuring the `Access-Control-Allow-Origin` response header. This should unblock making XMLHttpRequests.
This commit is contained in:
@@ -11,6 +11,7 @@ pub enum ApiError {
|
||||
UnsupportedType(String),
|
||||
ImATeapot(String), // Just in case.
|
||||
ProcessingError(String), // A 202 error, for when a block/attestation cannot be processed, but still transmitted.
|
||||
InvalidHeaderValue(String),
|
||||
}
|
||||
|
||||
pub type ApiResult = Result<Response<Body>, ApiError>;
|
||||
@@ -26,6 +27,7 @@ impl ApiError {
|
||||
ApiError::UnsupportedType(desc) => (StatusCode::UNSUPPORTED_MEDIA_TYPE, desc),
|
||||
ApiError::ImATeapot(desc) => (StatusCode::IM_A_TEAPOT, desc),
|
||||
ApiError::ProcessingError(desc) => (StatusCode::ACCEPTED, desc),
|
||||
ApiError::InvalidHeaderValue(desc) => (StatusCode::INTERNAL_SERVER_ERROR, desc),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,6 +79,12 @@ impl From<std::io::Error> for ApiError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<hyper::header::InvalidHeaderValue> for ApiError {
|
||||
fn from(e: hyper::header::InvalidHeaderValue) -> ApiError {
|
||||
ApiError::InvalidHeaderValue(format!("Invalid CORS header value: {:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
impl StdError for ApiError {
|
||||
fn cause(&self) -> Option<&dyn StdError> {
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user