package httpbinding
import (
)
const (
contentLengthHeader = "Content-Length"
floatNaN = "NaN"
floatInfinity = "Infinity"
floatNegInfinity = "-Infinity"
)
type Encoder struct {
path, rawPath, pathBuffer []byte
query url.Values
header http.Header
}
func (, string, http.Header) (*Encoder, error) {
, := url.ParseQuery()
if != nil {
return nil, fmt.Errorf("failed to parse query string: %w", )
}
:= &Encoder{
path: []byte(),
rawPath: []byte(),
query: ,
header: .Clone(),
}
return , nil
}
func ( *Encoder) ( *http.Request) (*http.Request, error) {
.URL.Path, .URL.RawPath = string(.path), string(.rawPath)
.URL.RawQuery = .query.Encode()
if := .header.Get(contentLengthHeader); len() > 0 {
, := strconv.ParseInt(, 10, 64)
if != nil {
return nil,
}
.ContentLength =
.header.Del(contentLengthHeader)
}
.Header = .header
return , nil
}
func ( *Encoder) ( string) HeaderValue {
return newHeaderValue(.header, , true)
}
func ( *Encoder) ( string) HeaderValue {
return newHeaderValue(.header, , false)
}
func ( *Encoder) ( string) Headers {
return Headers{
header: .header,
prefix: strings.TrimSpace(),
}
}
func ( Encoder) ( string) bool {
return len(.header[]) != 0
}
func ( *Encoder) ( string) URIValue {
return newURIValue(&.path, &.rawPath, &.pathBuffer, )
}
func ( *Encoder) ( string) QueryValue {
return NewQueryValue(.query, , false)
}
func ( *Encoder) ( string) QueryValue {
return NewQueryValue(.query, , true)
}
func ( *Encoder) ( string) bool {
return len(.query.Get()) != 0
}