Skip to content

Commit

Permalink
add SetContextData and GetContextData(#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed May 28, 2024
1 parent 384ff51 commit e364972
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,18 @@ func (r *Request) SetContext(ctx context.Context) *Request {
return r
}

// SetContextData sets the key-value pair data for current Request, so you
// can access some extra context info for current Request in hook or middleware.
func (r *Request) SetContextData(key, val any) *Request {
r.ctx = context.WithValue(r.Context(), key, val)
return r
}

// GetContextData returns the context data of specified key, which set by SetContextData.
func (r *Request) GetContextData(key any) any {
return r.Context().Value(key)
}

// DisableAutoReadResponse disable read response body automatically (enabled by default).
func (r *Request) DisableAutoReadResponse() *Request {
r.disableAutoReadResponse = true
Expand Down

0 comments on commit e364972

Please sign in to comment.