Skip to content

Commit cf994cf

Browse files
authored
Add WithCapureHTTPResponse to core (#145)
1 parent c1fe192 commit cf994cf

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

core/config/config.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@ import (
1616
// contextKeys are used to identify the type of value in the context.
1717
// Since these are string, it is possible to get a short description of the
1818
// context key for logging and debugging using key.String().
19-
2019
type contextKey string
2120

22-
func (c contextKey) String() string {
23-
return "auth " + string(c)
24-
}
25-
2621
var (
27-
2822
// ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
2923
ContextOAuth2 = contextKey("token")
3024

@@ -51,6 +45,9 @@ var (
5145

5246
// ContextOperationServerVariables overrides a server configuration variables using operation specific values.
5347
ContextOperationServerVariables = contextKey("serverOperationVariables")
48+
49+
// ContextHTTPResponse holds the raw HTTP response after the request has completed.
50+
ContextHTTPResponse = contextKey("httpResponse")
5451
)
5552

5653
// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth
@@ -311,6 +308,12 @@ func WithCustomConfiguration(cfg *Configuration) ConfigurationOption {
311308
}
312309
}
313310

311+
// WithCaptureHTTPResponse adds the raw HTTP response retrieval annotation to the parent context.
312+
// The resp parameter will contain the raw HTTP response after the request has completed.
313+
func WithCaptureHTTPResponse(parent context.Context, resp **http.Response) context.Context {
314+
return context.WithValue(parent, ContextHTTPResponse, resp)
315+
}
316+
314317
// ServerVariable stores the information about a server variable
315318
type ServerVariable struct {
316319
Description string

0 commit comments

Comments
 (0)