mirror of
https://github.com/openziti/ziti.git
synced 2026-09-10 16:55:41 +00:00
703f74ae28
- caps buffered HTTP request bodies at 1 MiB across the client, management, fabric management, and OIDC web APIs - rejects oversized bodies with 413 REQUEST_ENTITY_TOO_LARGE before authentication - surfaces request body read errors instead of ignoring them - returns after writing the request context error response in the client API handler - adds integration coverage for oversized bodies with and without Content-Length
34 lines
958 B
Go
34 lines
958 B
Go
package env
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/openziti/ziti/v2/common/eid"
|
|
"github.com/openziti/ziti/v2/controller/api"
|
|
"github.com/openziti/ziti/v2/controller/response"
|
|
)
|
|
|
|
// NewRequestContext creates a bare request context for responses rendered outside the normal
|
|
// request pipeline. The body read is capped at api.MaxRequestBodySize; a body that exceeds the
|
|
// cap is truncated rather than rejected, since this context only renders error responses.
|
|
func NewRequestContext(rw http.ResponseWriter, r *http.Request) *response.RequestContext {
|
|
rid := eid.New()
|
|
|
|
r.Body = http.MaxBytesReader(rw, r.Body, api.MaxRequestBodySize)
|
|
body, _ := io.ReadAll(r.Body)
|
|
r.Body = io.NopCloser(bytes.NewReader(body))
|
|
|
|
requestContext := &response.RequestContext{
|
|
Id: rid,
|
|
ResponseWriter: rw,
|
|
Request: r,
|
|
Body: body,
|
|
}
|
|
|
|
requestContext.Responder = response.NewResponder(requestContext)
|
|
|
|
return requestContext
|
|
}
|