mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 02:32:17 +08:00
Add GetRequest() method to Context
This allows to use the raw http.Request even when the context was only passed as an interface.
This commit is contained in:
parent
783c7ee9c1
commit
e863977fae
@ -94,6 +94,11 @@ func (c *Context) Handler() HandlerFunc {
|
|||||||
return c.handlers.Last()
|
return c.handlers.Last()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRequest returns the raw http.Request.
|
||||||
|
func (c *Context) GetRequest() *http.Request {
|
||||||
|
return c.Request
|
||||||
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
/*********** FLOW CONTROL ***********/
|
/*********** FLOW CONTROL ***********/
|
||||||
/************************************/
|
/************************************/
|
||||||
|
@ -332,6 +332,14 @@ func TestContextHandler(t *testing.T) {
|
|||||||
assert.Equal(t, reflect.ValueOf(handlerTest).Pointer(), reflect.ValueOf(c.Handler()).Pointer())
|
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) {
|
func TestContextQuery(t *testing.T) {
|
||||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||||
c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10&id=", nil)
|
c.Request, _ = http.NewRequest("GET", "http://example.com/?foo=bar&page=10&id=", nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user