Skip to content

Commit

Permalink
cookie added
Browse files Browse the repository at this point in the history
  • Loading branch information
yahya077 committed Dec 23, 2024
1 parent 8cd65d3 commit 31e493f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Request struct {
Query IQuery
BodyParser IBodyParser
contextBuilder IContextBuilder
Cookies []*http.Cookie
}

// NewRequest creates a new request
Expand Down Expand Up @@ -93,6 +94,12 @@ func (r *Request) request() *http.Request {
req.Header.Set("Content-Type", r.BodyParser.ContentType())
}

if r.Cookies != nil && len(r.Cookies) > 0 {
for _, cookie := range r.Cookies {
req.AddCookie(cookie)
}
}

return req
}

Expand Down Expand Up @@ -167,3 +174,9 @@ func WithContextBuilder(contextBuilder IContextBuilder) OptionRequest {
request.contextBuilder = contextBuilder
}
}

func WithCookies(cookies ...*http.Cookie) OptionRequest {
return func(request *Request) {
request.Cookies = cookies
}
}

0 comments on commit 31e493f

Please sign in to comment.