From 036a4ac847d590cd5c7b3f6dd0685078ae14c1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Tue, 9 Apr 2024 10:55:31 +0100 Subject: [PATCH 1/3] add WithCaptureHTTPRequest, prep for template change --- core/config/config.go | 3 +++ core/runtime/runtime.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/core/config/config.go b/core/config/config.go index de2859ca..bcdae190 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -52,6 +52,9 @@ var ( // ContextHTTPResponse holds the raw HTTP response after the request has completed. ContextHTTPResponse = contextKey("httpResponse") + + // ContextHTTPRequest holds the raw HTTP request. + ContextHTTPRequest = contextKey("httpRequest") ) // BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth diff --git a/core/runtime/runtime.go b/core/runtime/runtime.go index b6221598..3c651425 100644 --- a/core/runtime/runtime.go +++ b/core/runtime/runtime.go @@ -12,3 +12,9 @@ import ( func WithCaptureHTTPResponse(parent context.Context, resp **http.Response) context.Context { return context.WithValue(parent, config.ContextHTTPResponse, resp) } + +// WithCaptureHTTPRequest adds the raw HTTP request to the parent context. +// The req parameter will contain the raw HTTP request. +func WithCaptureHTTPRequest(parent context.Context, req **http.Request) context.Context { + return context.WithValue(parent, config.ContextHTTPRequest, req) +} From 8b6b6aff5b3a34978c590ed60863747cdb76b498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Tue, 9 Apr 2024 13:45:40 +0100 Subject: [PATCH 2/3] Update WithCaptureHTTPRequest function documentation --- core/runtime/runtime.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/runtime/runtime.go b/core/runtime/runtime.go index 3c651425..9ac33f87 100644 --- a/core/runtime/runtime.go +++ b/core/runtime/runtime.go @@ -13,8 +13,8 @@ func WithCaptureHTTPResponse(parent context.Context, resp **http.Response) conte return context.WithValue(parent, config.ContextHTTPResponse, resp) } -// WithCaptureHTTPRequest adds the raw HTTP request to the parent context. -// The req parameter will contain the raw HTTP request. +// WithCaptureHTTPRequest adds the raw HTTP request retrieval annotation to the parent context. +// The req parameter will contain the raw HTTP request made to the API. func WithCaptureHTTPRequest(parent context.Context, req **http.Request) context.Context { return context.WithValue(parent, config.ContextHTTPRequest, req) } From f812c8a653e6dfad121b3d22c72cd46edaa6a83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diogo=20Ferr=C3=A3o?= Date: Tue, 9 Apr 2024 13:54:11 +0100 Subject: [PATCH 3/3] address PR comments --- core/CHANGELOG.md | 3 +++ core/runtime/runtime.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index f0434d80..638e6c96 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,6 @@ +## v0.11.0 (2024-04-09) +- **Feature:** Add method `WithCaptureHTTPRequest` to package `runtime`, which allows capture of HTTP requests for debugging purposes. + ## v0.10.1 (2024-03-20) - **Improvement:** Update `ConfigureRegion` method to take into account global servers without a region variable diff --git a/core/runtime/runtime.go b/core/runtime/runtime.go index 9ac33f87..e499d1b6 100644 --- a/core/runtime/runtime.go +++ b/core/runtime/runtime.go @@ -14,7 +14,7 @@ func WithCaptureHTTPResponse(parent context.Context, resp **http.Response) conte } // WithCaptureHTTPRequest adds the raw HTTP request retrieval annotation to the parent context. -// The req parameter will contain the raw HTTP request made to the API. +// After the request has completed, the req parameter will contain the raw HTTP request made to the API. func WithCaptureHTTPRequest(parent context.Context, req **http.Request) context.Context { return context.WithValue(parent, config.ContextHTTPRequest, req) }