mirror of
https://github.com/soypat/lneto.git
synced 2026-08-21 15:09:05 +00:00
update documentation on ContentLength methods and fix bug in Form reset on empty body
This commit is contained in:
@@ -404,10 +404,9 @@ func (exch *Exchange) RequestContentType() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RequestContentLength returns the body length declared by the request's
|
// RequestContentLength returns the body length declared by the request's
|
||||||
// Content-Length field. An absent field is not a client error: such a request
|
// Content-Length field. An absent field is signalled with present=false and no error.
|
||||||
// has no body at all, RFC 9112 6.3. Check for the error to answer 411 instead.
|
|
||||||
// See [httpraw.Header.ContentLength].
|
// See [httpraw.Header.ContentLength].
|
||||||
func (exch *Exchange) RequestContentLength() (int64, bool, error) {
|
func (exch *Exchange) RequestContentLength() (_ int64, present bool, _ error) {
|
||||||
return exch.RequestHeaderRaw().ContentLength()
|
return exch.RequestHeaderRaw().ContentLength()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,8 +431,10 @@ func (exch *Exchange) RequestParseForm(dst *httpraw.Form, buf []byte) error {
|
|||||||
// wire would parse chunk sizes as form data. httpraw does not decode them.
|
// wire would parse chunk sizes as form data. httpraw does not decode them.
|
||||||
return errUnsupportedTransferCoding
|
return errUnsupportedTransferCoding
|
||||||
}
|
}
|
||||||
|
|
||||||
length, present, err := exch.RequestContentLength()
|
length, present, err := exch.RequestContentLength()
|
||||||
if !present {
|
if !present {
|
||||||
|
dst.Reset(nil)
|
||||||
return nil // No length is no body, RFC 9112 6.3.
|
return nil // No length is no body, RFC 9112 6.3.
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -395,11 +395,8 @@ func (h *Header) NormalizeKeys() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ContentLength returns the body length declared by the Content-Length field.
|
// ContentLength returns the body length declared by the Content-Length field.
|
||||||
// Fails with an error if the field is absent, which for a request means the
|
// If the field is not present then the returned bool is false. Will return error for invalid or non-integer value.
|
||||||
// message has no body at all unless a transfer coding applies, RFC 9112 6.3.
|
func (h *Header) ContentLength() (_ int64, present bool, _ error) {
|
||||||
// The value must be digits only, so a negative or list-valued field is rejected
|
|
||||||
// rather than guessed at.
|
|
||||||
func (h *Header) ContentLength() (int64, bool, error) {
|
|
||||||
value := h.GetFold(headerContentLength)
|
value := h.GetFold(headerContentLength)
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return 0, false, nil
|
return 0, false, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user