Skip to content

Commit

Permalink
Rename Ctx.Request to Ctx.Req
Browse files Browse the repository at this point in the history
  • Loading branch information
nickajacks1 committed Mar 3, 2024
1 parent 1880efc commit 1b6eda4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
16 changes: 8 additions & 8 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func Test_Client_Agent_BasicAuth(t *testing.T) {
func Test_Client_Agent_BodyString(t *testing.T) {
t.Parallel()
handler := func(c Ctx) error {
return c.Send(c.Request().Body())
return c.Send(c.Req().Body())
}

wrapAgent := func(a *Agent) {
Expand All @@ -509,7 +509,7 @@ func Test_Client_Agent_BodyString(t *testing.T) {
func Test_Client_Agent_Body(t *testing.T) {
t.Parallel()
handler := func(c Ctx) error {
return c.Send(c.Request().Body())
return c.Send(c.Req().Body())
}

wrapAgent := func(a *Agent) {
Expand All @@ -522,7 +522,7 @@ func Test_Client_Agent_Body(t *testing.T) {
func Test_Client_Agent_BodyStream(t *testing.T) {
t.Parallel()
handler := func(c Ctx) error {
return c.Send(c.Request().Body())
return c.Send(c.Req().Body())
}

wrapAgent := func(a *Agent) {
Expand Down Expand Up @@ -702,7 +702,7 @@ func Test_Client_Agent_Json(t *testing.T) {
handler := func(c Ctx) error {
require.Equal(t, MIMEApplicationJSON, c.Get(HeaderContentType))

return c.Send(c.Request().Body())
return c.Send(c.Req().Body())
}

wrapAgent := func(a *Agent) {
Expand All @@ -715,7 +715,7 @@ func Test_Client_Agent_Json(t *testing.T) {
handler = func(c Ctx) error {
require.Equal(t, "application/problem+json", c.Get(HeaderContentType))

return c.Send(c.Request().Body())
return c.Send(c.Req().Body())
}

wrapAgent = func(a *Agent) {
Expand Down Expand Up @@ -744,7 +744,7 @@ func Test_Client_Agent_XML(t *testing.T) {
handler := func(c Ctx) error {
require.Equal(t, MIMEApplicationXML, c.Get(HeaderContentType))

return c.Send(c.Request().Body())
return c.Send(c.Req().Body())
}

wrapAgent := func(a *Agent) {
Expand All @@ -771,7 +771,7 @@ func Test_Client_Agent_Form(t *testing.T) {
handler := func(c Ctx) error {
require.Equal(t, MIMEApplicationForm, c.Get(HeaderContentType))

return c.Send(c.Request().Body())
return c.Send(c.Req().Body())
}

args := AcquireArgs()
Expand Down Expand Up @@ -801,7 +801,7 @@ func Test_Client_Agent_MultipartForm(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "bar", mf.Value["foo"][0])

return c.Send(c.Request().Body())
return c.Send(c.Req().Body())
})

go func() {
Expand Down
12 changes: 6 additions & 6 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ func (c *DefaultCtx) BaseURL() string {

// BodyRaw is an alias of [Request.BodyRaw].
func (c *DefaultCtx) BodyRaw() []byte {
return c.Request().BodyRaw()
return c.Req().BodyRaw()
}

// Body is an alias of [Request.Body].
func (c *DefaultCtx) Body() []byte {
return c.Request().Body()
return c.Req().Body()
}

// ClearCookie expires a specific cookie by key on the client side.
Expand Down Expand Up @@ -289,10 +289,10 @@ func (c *DefaultCtx) Download(file string, filename ...string) error {
return c.SendFile(file)
}

// Request return the *fasthttp.Request object
// Req return the *fasthttp.Req object
// This allows you to use all fasthttp request methods
// https://godoc.org/github.com/valyala/fasthttp#Request
func (c *DefaultCtx) Request() *Request {
// https://godoc.org/github.com/valyala/fasthttp#Req
func (c *DefaultCtx) Req() *Request {
return c.req
}

Expand Down Expand Up @@ -457,7 +457,7 @@ func (c *DefaultCtx) Fresh() bool {

// Get is an alias of [Request.Get].
func (c *DefaultCtx) Get(key string, defaultValue ...string) string {
return c.Request().Get(key, defaultValue...)
return c.Req().Get(key, defaultValue...)
}

// GetRespHeader returns the HTTP response header specified by field.
Expand Down
7 changes: 3 additions & 4 deletions ctx_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ type Ctx interface {
// Override this default with the filename parameter.
Download(file string, filename ...string) error

// Request return the *fasthttp.Request object
// This allows you to use all fasthttp request methods
// https://godoc.org/github.com/valyala/fasthttp#Request
Request() *Request
// Req returns the [Request] object for the current request context.
// To access the underlying fasthttp request object, use [Ctx.Context].
Req() *Request

// Response return the *fasthttp.Response object
// This allows you to use all fasthttp response methods
Expand Down
10 changes: 5 additions & 5 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func Test_Ctx_Body_With_Compression(t *testing.T) {

// Check if body raw is the same as previous before decompression
require.Equal(
t, tCase.body, c.Request().BodyRaw(),
t, tCase.body, c.Req().BodyRaw(),
"Body raw must be the same as set before",
)
})
Expand Down Expand Up @@ -658,7 +658,7 @@ func Test_Ctx_Body_With_Compression_Immutable(t *testing.T) {

// Check if body raw is the same as previous before decompression
require.Equal(
t, tCase.body, c.Request().BodyRaw(),
t, tCase.body, c.Req().BodyRaw(),
"Body raw must be the same as set before",
)
})
Expand Down Expand Up @@ -1879,7 +1879,7 @@ func Test_Ctx_IPs(t *testing.T) {
require.Empty(t, c.IPs())

// missing header
c.Request()
c.Req()
require.Empty(t, c.IPs())
}

Expand Down Expand Up @@ -1915,7 +1915,7 @@ func Test_Ctx_IPs_With_IP_Validation(t *testing.T) {
require.Empty(t, c.IPs())

// missing header
c.Request()
c.Req()
require.Empty(t, c.IPs())
}

Expand Down Expand Up @@ -2003,7 +2003,7 @@ func Benchmark_Ctx_IP_With_ProxyHeader_and_IP_Validation(b *testing.B) {
func Benchmark_Ctx_IP(b *testing.B) {
app := New()
c := app.AcquireCtx(&fasthttp.RequestCtx{})
c.Request()
c.Req()
var res string
b.ReportAllocs()
b.ResetTimer()
Expand Down
2 changes: 1 addition & 1 deletion middleware/logger/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func createTagMap(cfg *Config) map[string]LogFunc {
return output.Write(c.Body())
},
TagBytesReceived: func(output Buffer, c fiber.Ctx, _ *Data, _ string) (int, error) {
return appendInt(output, len(c.Request().Body()))
return appendInt(output, len(c.Req().Body()))
},
TagBytesSent: func(output Buffer, c fiber.Ctx, _ *Data, _ string) (int, error) {
if c.Response().Header.ContentLength() < 0 {
Expand Down
2 changes: 1 addition & 1 deletion middleware/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func Test_Proxy_Modify_Request(t *testing.T) {
t.Parallel()

_, addr := createProxyTestServer(t, func(c fiber.Ctx) error {
b := c.Request().Body()
b := c.Req().Body()
return c.SendString(string(b))
})

Expand Down

0 comments on commit 1b6eda4

Please sign in to comment.