mirror of
https://github.com/soypat/lneto.git
synced 2026-09-10 08:39:30 +00:00
add raw buffer access
This commit is contained in:
@@ -119,6 +119,18 @@ func (exch *Exchange) Release() {
|
|||||||
exch.used.Store(false)
|
exch.used.Store(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnsafeRawBuffer returns the contiguous buffer being used for the request and response.
|
||||||
|
// Writing to it will mangle the entire request header+body and/or any staged response headers.
|
||||||
|
// Does not return the buffer used for the response first line so can be safely
|
||||||
|
// written to and used without modifying the staged response first line.
|
||||||
|
//
|
||||||
|
// Staging headers will write to this buffer so use mindfully.
|
||||||
|
// To access only the request header buffer portion use [httpraw.Header.BufferRaw] limited
|
||||||
|
// to [httpraw.Header.BufferParsed] as returned by [Exchange.RequestHeaderRaw].
|
||||||
|
//
|
||||||
|
// In [Router] context, the size of this buffer is influenced directly by [RouterConfig] HeaderBufferSize fields.
|
||||||
|
func (exch *Exchange) UnsafeRawBuffer() []byte { return exch.rawbuf }
|
||||||
|
|
||||||
// StageHeader stages a response header field, written on the first
|
// StageHeader stages a response header field, written on the first
|
||||||
// [Exchange.FlushHeader], [Exchange.WriteHeader] or [Exchange.Write].
|
// [Exchange.FlushHeader], [Exchange.WriteHeader] or [Exchange.Write].
|
||||||
// Returns false and drops the field if the response buffer cannot fit it.
|
// Returns false and drops the field if the response buffer cannot fit it.
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ func (r *Router) awaitIdleExchangesLocked(maxWait time.Duration) error {
|
|||||||
// full, and an error when the router's goroutines have been torn down. On every
|
// full, and an error when the router's goroutines have been torn down. On every
|
||||||
// one of them conn is left untouched and unclosed for the caller to dispose of:
|
// one of them conn is left untouched and unclosed for the caller to dispose of:
|
||||||
// refusing connections is how a router with fixed memory applies backpressure.
|
// refusing connections is how a router with fixed memory applies backpressure.
|
||||||
func (r *Router) Handle(conn conn) error {
|
func (r *Router) Handle(conn io.ReadWriteCloser) error {
|
||||||
// Exchange acquisition and the configuration it is served with must be read
|
// Exchange acquisition and the configuration it is served with must be read
|
||||||
// under the same lock: [Router.Configure] may run concurrently.
|
// under the same lock: [Router.Configure] may run concurrently.
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
|
|||||||
@@ -196,6 +196,10 @@ func (h *Header) BufferParsed() int {
|
|||||||
return h.hbuf.off
|
return h.hbuf.off
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BufferRaw returns the undeerlying buffer as stored currently in memory.
|
||||||
|
// The length of the returned buffer is the used portion. Capacity of returned slice is [Header.BufferCapacity].
|
||||||
|
func (h *Header) BufferRaw() []byte { return h.hbuf.buf }
|
||||||
|
|
||||||
// BufferUsed returns the raw memory used.
|
// BufferUsed returns the raw memory used.
|
||||||
//
|
//
|
||||||
// BufferUsed + BufferFree == BufferCapacity
|
// BufferUsed + BufferFree == BufferCapacity
|
||||||
|
|||||||
Reference in New Issue
Block a user