From e863977faec96b2c3ef74a5390f467f168b6d1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20H=C3=A4ssig?= Date: Sun, 11 Feb 2018 14:16:08 +0100 Subject: [PATCH] Add GetRequest() method to Context This allows to use the raw http.Request even when the context was only passed as an interface. --- context.go | 5 +++++ context_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/context.go b/context.go index 90d4c6e5..d52b3bbf 100644 --- a/context.go +++ b/context.go @@ -94,6 +94,11 @@ func (c *Context) Handler() HandlerFunc { return c.handlers.Last() } +// GetRequest returns the raw http.Request. +func (c *Context) GetRequest() *http.Request { + return c.Request +} + /************************************/ /*********** FLOW CONTROL ***********/ /************************************/ diff --git a/context_test.go b/context_test.go index 9024cfc1..5c28face 100644 --- a/context_test.go +++ b/context_test.go @@ -332,6 +332,14 @@ func TestContextHandler(t *testing.T) { assert.Equal(t, reflect.ValueOf(handlerTest).Pointer(), reflect.ValueOf(c.Handler()).Pointer()) } +func TestContextGetRequest(t *testing.T) { + c, _ := CreateTestContext(httptest.NewRecorder()) + request, _ := http.NewRequest("GET", "http://example.com/?foo=bar&page=10&id=", nil) + c.Request = request + + assert.Equal(t, request, c.GetRequest()) +} + func TestContextQuery(t *testing.T) { c, _ := CreateTestContext(httptest.NewRecorder()) c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10&id=", nil)