proxy-pool/internal/platform/httpsecurity/response.go
youfak 4de3ffb85f
Some checks are pending
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run
ci / race (push) Waiting to run
feat: add ephemeral proxy activity pool
2026-07-29 12:51:18 +08:00

37 lines
771 B
Go

package httpsecurity
import (
"errors"
"net/http"
"proxy-pool/internal/platform/httpapi"
)
func WriteProblem(writer http.ResponseWriter, requestID string, err error) bool {
var securityError *HTTPError
if !errors.As(err, &securityError) || securityError.StatusCode < 400 || securityError.StatusCode > 599 {
return false
}
for name, values := range securityError.Header {
for _, value := range values {
writer.Header().Add(name, value)
}
}
code := securityError.Code
if code == "" {
code = "SECURITY_REJECTED"
}
title := http.StatusText(securityError.StatusCode)
if title == "" {
title = "Request rejected"
}
httpapi.WriteProblem(writer, httpapi.NewProblem(
securityError.StatusCode,
code,
title,
"",
requestID,
))
return true
}