Add Prototype method to Defaults

This commit is contained in:
some 2024-10-09 00:28:18 -04:00
parent c0dedb7d96
commit 0165e58ddb
Signed by: some
GPG Key ID: 65D0589220B9BFC8

View File

@ -57,6 +57,7 @@ func (e DefaultError) BodyBytes() (body []byte) {
type DefaultRequestBuilder struct { type DefaultRequestBuilder struct {
requestBuilder RequestBuilder requestBuilder RequestBuilder
prototype PrototypeRequestBuilder
allowedMethods *[]string allowedMethods *[]string
header struct { header struct {
*Header *Header
@ -72,7 +73,7 @@ type DefaultRequestBuilder struct {
} }
} }
func NewDefaultRequestBuilder(rb RequestBuilder, am *[]string, h *Header, hf header, v *Values, vf values, b *Body, bf body) DefaultRequestBuilder { func NewDefaultRequestBuilder(rb RequestBuilder, rbp PrototypeRequestBuilder, am *[]string, h *Header, hf header, v *Values, vf values, b *Body, bf body) DefaultRequestBuilder {
if am == nil { if am == nil {
amd := make([]string, 0) amd := make([]string, 0)
am = &amd am = &amd
@ -97,6 +98,7 @@ func NewDefaultRequestBuilder(rb RequestBuilder, am *[]string, h *Header, hf hea
} }
return DefaultRequestBuilder{ return DefaultRequestBuilder{
requestBuilder: rb, requestBuilder: rb,
prototype: rbp,
allowedMethods: am, allowedMethods: am,
header: struct { header: struct {
*Header *Header
@ -122,6 +124,10 @@ func NewDefaultRequestBuilder(rb RequestBuilder, am *[]string, h *Header, hf hea
} }
} }
func (rb *DefaultRequestBuilder) Prototype() PrototypeRequestBuilder {
return rb.prototype
}
func (rb *DefaultRequestBuilder) Allowed(method string) (errRes ErrorResponse) { func (rb *DefaultRequestBuilder) Allowed(method string) (errRes ErrorResponse) {
var ok bool var ok bool
for _, m := range *rb.allowedMethods { for _, m := range *rb.allowedMethods {
@ -158,8 +164,9 @@ func (rb *DefaultRequestBuilder) Values(values Values) (errRes ErrorResponse) {
} }
type DefaultResponse struct { type DefaultResponse struct {
response Response response Response
header struct { prototype PrototypeResponse
header struct {
*Header *Header
fields header fields header
} }
@ -169,7 +176,7 @@ type DefaultResponse struct {
} }
} }
func NewDefaultResponse(r Response, h *Header, hf header, b *Body, bf body) DefaultResponse { func NewDefaultResponse(r Response, rp PrototypeResponse, h *Header, hf header, b *Body, bf body) DefaultResponse {
if h == nil || hf == nil { if h == nil || hf == nil {
hd := make(Header) hd := make(Header)
h = &hd h = &hd
@ -183,7 +190,8 @@ func NewDefaultResponse(r Response, h *Header, hf header, b *Body, bf body) Defa
bf = &bfd bf = &bfd
} }
return DefaultResponse{ return DefaultResponse{
response: r, response: r,
prototype: rp,
header: struct { header: struct {
*Header *Header
fields header fields header
@ -201,6 +209,10 @@ func NewDefaultResponse(r Response, h *Header, hf header, b *Body, bf body) Defa
} }
} }
func (r *DefaultResponse) Prototype() PrototypeResponse {
return r.prototype
}
func (r *DefaultResponse) Header() (header Header) { func (r *DefaultResponse) Header() (header Header) {
if r.header.Header == nil { if r.header.Header == nil {
r.header.Header.Parse(r.header.fields) r.header.Header.Parse(r.header.fields)