diff options
author | Valery Piashchynski <[email protected]> | 2021-06-03 16:59:10 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-03 16:59:10 +0300 |
commit | 063703e96e5f7cee59139e98d446d5577fb5c224 (patch) | |
tree | e669d08cbbafaa5d809bfb870e874d3de4683dad /pkg | |
parent | 62bbde7936109d18bf1f727974719804dad4c105 (diff) |
- Add internal_error_code option
- Update tests
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/worker_handler/handler.go | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/pkg/worker_handler/handler.go b/pkg/worker_handler/handler.go index 672c5838..0ff23d9d 100644 --- a/pkg/worker_handler/handler.go +++ b/pkg/worker_handler/handler.go @@ -57,25 +57,27 @@ func (e *ResponseEvent) Elapsed() time.Duration { // Handler serves http connections to underlying PHP application using PSR-7 protocol. Context will include request headers, // parsed files and query, payload will include parsed form dataTree (if any). type Handler struct { - maxRequestSize uint64 - uploads config.Uploads - trusted config.Cidrs - log logger.Logger - pool pool.Pool - mul sync.Mutex - lsn events.Listener + maxRequestSize uint64 + uploads config.Uploads + trusted config.Cidrs + log logger.Logger + pool pool.Pool + mul sync.Mutex + lsn events.Listener + internalHTTPCode uint64 } // NewHandler return handle interface implementation -func NewHandler(maxReqSize uint64, uploads config.Uploads, trusted config.Cidrs, pool pool.Pool) (*Handler, error) { +func NewHandler(maxReqSize uint64, internalHTTPCode uint64, uploads config.Uploads, trusted config.Cidrs, pool pool.Pool) (*Handler, error) { if pool == nil { return nil, errors.E(errors.Str("pool should be initialized")) } return &Handler{ - maxRequestSize: maxReqSize * MB, - uploads: uploads, - pool: pool, - trusted: trusted, + maxRequestSize: maxReqSize * MB, + uploads: uploads, + pool: pool, + trusted: trusted, + internalHTTPCode: internalHTTPCode, }, nil } @@ -177,7 +179,7 @@ func (h *Handler) handleError(w http.ResponseWriter, r *http.Request, start time errors.Is(errors.Decode, err) || errors.Is(errors.Network, err) { // write an internal server error - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(int(h.internalHTTPCode)) h.sendEvent(ErrorEvent{Request: r, Error: errors.E(op, err), start: start, elapsed: time.Since(start)}) } } |