mirror of
https://github.com/dalbodeule/hop-gate.git
synced 2025-12-09 13:25:44 +09:00
[feat](server): add 502 Bad Gateway support and improve error page handling
- Introduced handling for `502 Bad Gateway` errors with a dedicated HTML template. - Updated `writeErrorPage` logic to include 502 and other new status mappings for custom templates. - Improved error page rendering by mapping 4xx/5xx status codes to appropriate templates.
This commit is contained in:
@@ -277,8 +277,8 @@ var hopGateOwnedHeaders = map[string]struct{}{
|
||||
"Referrer-Policy": {},
|
||||
}
|
||||
|
||||
// writeErrorPage 는 주요 HTTP 에러 코드(400/404/500/525)에 대해 정적 HTML 에러 페이지를 렌더링합니다. (ko)
|
||||
// writeErrorPage renders static HTML error pages for key HTTP error codes (400/404/500/525). (en)
|
||||
// writeErrorPage 는 주요 HTTP 에러 코드(400/404/500/502/504/525)에 대해 정적 HTML 에러 페이지를 렌더링합니다. (ko)
|
||||
// writeErrorPage renders static HTML error pages for key HTTP error codes (400/404/500/502/504/525). (en)
|
||||
//
|
||||
// 템플릿 로딩 우선순위: (ko)
|
||||
// 1. HOP_ERROR_PAGES_DIR/<status>.html (또는 ./errors/<status>.html) (ko)
|
||||
@@ -294,9 +294,31 @@ func writeErrorPage(w http.ResponseWriter, r *http.Request, status int) {
|
||||
setSecurityAndIdentityHeaders(w, r)
|
||||
}
|
||||
|
||||
// Delegates actual HTML rendering to internal/errorpages. (en)
|
||||
// 실제 HTML 렌더링은 internal/errorpages 패키지에 위임합니다. (ko)
|
||||
errorpages.Render(w, r, status)
|
||||
// 4xx / 5xx 대역에 대한 템플릿 매핑 규칙: (ko)
|
||||
// - 400 series: 400.html 로 렌더링 (단, 404 는 404.html 사용) (ko)
|
||||
// - 500 series: 500.html 로 렌더링 (단, 502/504/525 는 개별 템플릿 사용) (ko)
|
||||
//
|
||||
// Mapping rules for 4xx / 5xx ranges: (en)
|
||||
// - 400 series: render using 400.html (except 404 uses 404.html). (en)
|
||||
// - 500 series: render using 500.html (except 502/504/525 which have dedicated templates). (en)
|
||||
mapped := status
|
||||
switch {
|
||||
case status >= 400 && status < 500:
|
||||
if status != http.StatusBadRequest && status != http.StatusNotFound {
|
||||
mapped = http.StatusBadRequest
|
||||
}
|
||||
case status >= 500 && status < 600:
|
||||
if status != http.StatusInternalServerError &&
|
||||
status != http.StatusBadGateway &&
|
||||
status != errorpages.StatusGatewayTimeout &&
|
||||
status != errorpages.StatusTLSHandshakeFailed {
|
||||
mapped = http.StatusInternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
// Delegates actual HTML rendering to internal/errorpages with mapped status. (en)
|
||||
// 실제 HTML 렌더링은 매핑된 상태 코드로 internal/errorpages 패키지에 위임합니다. (ko)
|
||||
errorpages.Render(w, r, mapped)
|
||||
}
|
||||
|
||||
// setSecurityAndIdentityHeaders 는 HopGate 에서 공통으로 추가하는 보안/식별 헤더를 설정합니다. (ko)
|
||||
|
||||
Reference in New Issue
Block a user