more robust 3xx handling
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
dbe96d1482
commit
7e31f167ea
2 changed files with 11 additions and 1 deletions
|
@ -350,6 +350,7 @@ pub mod reqwest {
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
return Err(ErrorResponse::missing_location());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !resp.status().is_success() {
|
if !resp.status().is_success() {
|
||||||
|
@ -593,7 +594,7 @@ pub mod cf_worker {
|
||||||
.map_err(ErrorResponse::worker_fetch_error))
|
.map_err(ErrorResponse::worker_fetch_error))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if resp.status_code() == 301 || resp.status_code() == 302 {
|
if resp.status_code() >= 300 && resp.status_code() < 400 {
|
||||||
if let Ok(Some(location)) = resp.headers().get("location") {
|
if let Ok(Some(location)) = resp.headers().get("location") {
|
||||||
return Box::pin(self.request_upstream(
|
return Box::pin(self.request_upstream(
|
||||||
info,
|
info,
|
||||||
|
@ -604,6 +605,7 @@ pub mod cf_worker {
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
return Err(ErrorResponse::missing_location());
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.status_code() < 200 || resp.status_code() >= 300 {
|
if resp.status_code() < 200 || resp.status_code() >= 300 {
|
||||||
|
|
|
@ -596,6 +596,14 @@ impl Display for ErrorResponse {
|
||||||
impl std::error::Error for ErrorResponse {}
|
impl std::error::Error for ErrorResponse {}
|
||||||
|
|
||||||
impl ErrorResponse {
|
impl ErrorResponse {
|
||||||
|
/// Received a redirect without a location
|
||||||
|
#[must_use]
|
||||||
|
pub const fn missing_location() -> Self {
|
||||||
|
Self {
|
||||||
|
status: StatusCode::BAD_GATEWAY,
|
||||||
|
message: Cow::Borrowed("Redirect location missing"),
|
||||||
|
}
|
||||||
|
}
|
||||||
#[cfg(not(feature = "cf-worker"))]
|
#[cfg(not(feature = "cf-worker"))]
|
||||||
/// URL must be a DNS name
|
/// URL must be a DNS name
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
Loading…
Reference in a new issue