Skip to content

Commit 6b6674f

Browse files
authored
Merge branch 'main' into feature/add-app-test-config
2 parents 0326c07 + a12ca10 commit 6b6674f

35 files changed

+1042
-699
lines changed

Diff for: .github/README.md

+210-119
Large diffs are not rendered by default.

Diff for: .github/workflows/markdown.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
uses: actions/checkout@v4
1616

1717
- name: Run markdownlint-cli2
18-
uses: DavidAnson/markdownlint-cli2-action@v17
18+
uses: DavidAnson/markdownlint-cli2-action@v18
1919
with:
2020
globs: |
2121
**/*.md

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- name: Upload coverage reports to Codecov
3434
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.go-version == '1.23.x' }}
35-
uses: codecov/codecov-action@v4.6.0
35+
uses: codecov/codecov-action@v5.0.0
3636
with:
3737
token: ${{ secrets.CODECOV_TOKEN }}
3838
file: ./coverage.txt

Diff for: bind.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (b *Bind) RespHeader(out any) error {
9595
// Cookie binds the requesr cookie strings into the struct, map[string]string and map[string][]string.
9696
// NOTE: If your cookie is like key=val1,val2; they'll be binded as an slice if your map is map[string][]string. Else, it'll use last element of cookie.
9797
func (b *Bind) Cookie(out any) error {
98-
if err := b.returnErr(binder.CookieBinder.Bind(b.ctx.Context(), out)); err != nil {
98+
if err := b.returnErr(binder.CookieBinder.Bind(b.ctx.RequestCtx(), out)); err != nil {
9999
return err
100100
}
101101

@@ -104,7 +104,7 @@ func (b *Bind) Cookie(out any) error {
104104

105105
// Query binds the query string into the struct, map[string]string and map[string][]string.
106106
func (b *Bind) Query(out any) error {
107-
if err := b.returnErr(binder.QueryBinder.Bind(b.ctx.Context(), out)); err != nil {
107+
if err := b.returnErr(binder.QueryBinder.Bind(b.ctx.RequestCtx(), out)); err != nil {
108108
return err
109109
}
110110

@@ -131,7 +131,7 @@ func (b *Bind) XML(out any) error {
131131

132132
// Form binds the form into the struct, map[string]string and map[string][]string.
133133
func (b *Bind) Form(out any) error {
134-
if err := b.returnErr(binder.FormBinder.Bind(b.ctx.Context(), out)); err != nil {
134+
if err := b.returnErr(binder.FormBinder.Bind(b.ctx.RequestCtx(), out)); err != nil {
135135
return err
136136
}
137137

@@ -149,7 +149,7 @@ func (b *Bind) URI(out any) error {
149149

150150
// MultipartForm binds the multipart form into the struct, map[string]string and map[string][]string.
151151
func (b *Bind) MultipartForm(out any) error {
152-
if err := b.returnErr(binder.FormBinder.BindMultipart(b.ctx.Context(), out)); err != nil {
152+
if err := b.returnErr(binder.FormBinder.BindMultipart(b.ctx.RequestCtx(), out)); err != nil {
153153
return err
154154
}
155155

@@ -163,7 +163,7 @@ func (b *Bind) MultipartForm(out any) error {
163163
// If there're no custom binder for mime type of body, it will return a ErrUnprocessableEntity error.
164164
func (b *Bind) Body(out any) error {
165165
// Get content-type
166-
ctype := utils.ToLower(utils.UnsafeString(b.ctx.Context().Request.Header.ContentType()))
166+
ctype := utils.ToLower(utils.UnsafeString(b.ctx.RequestCtx().Request.Header.ContentType()))
167167
ctype = binder.FilterFlags(utils.ParseVendorSpecificContentType(ctype))
168168

169169
// Check custom binders

Diff for: client/client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ func Test_Client_SetProxyURL(t *testing.T) {
15721572
}
15731573

15741574
c.Status(resp.StatusCode())
1575-
c.Context().SetBody(resp.Body())
1575+
c.RequestCtx().SetBody(resp.Body())
15761576

15771577
return nil
15781578
})

Diff for: ctx.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -382,26 +382,26 @@ func (c *DefaultCtx) ClearCookie(key ...string) {
382382
})
383383
}
384384

385-
// Context returns *fasthttp.RequestCtx that carries a deadline
385+
// RequestCtx returns *fasthttp.RequestCtx that carries a deadline
386386
// a cancellation signal, and other values across API boundaries.
387-
func (c *DefaultCtx) Context() *fasthttp.RequestCtx {
387+
func (c *DefaultCtx) RequestCtx() *fasthttp.RequestCtx {
388388
return c.fasthttp
389389
}
390390

391-
// UserContext returns a context implementation that was set by
391+
// Context returns a context implementation that was set by
392392
// user earlier or returns a non-nil, empty context,if it was not set earlier.
393-
func (c *DefaultCtx) UserContext() context.Context {
393+
func (c *DefaultCtx) Context() context.Context {
394394
ctx, ok := c.fasthttp.UserValue(userContextKey).(context.Context)
395395
if !ok {
396396
ctx = context.Background()
397-
c.SetUserContext(ctx)
397+
c.SetContext(ctx)
398398
}
399399

400400
return ctx
401401
}
402402

403-
// SetUserContext sets a context implementation by user.
404-
func (c *DefaultCtx) SetUserContext(ctx context.Context) {
403+
// SetContext sets a context implementation by user.
404+
func (c *DefaultCtx) SetContext(ctx context.Context) {
405405
c.fasthttp.SetUserValue(userContextKey, ctx)
406406
}
407407

@@ -1189,8 +1189,8 @@ func (c *DefaultCtx) Query(key string, defaultValue ...string) string {
11891189
// Queries()["filters[customer][name]"] == "Alice"
11901190
// Queries()["filters[status]"] == "pending"
11911191
func (c *DefaultCtx) Queries() map[string]string {
1192-
m := make(map[string]string, c.Context().QueryArgs().Len())
1193-
c.Context().QueryArgs().VisitAll(func(key, value []byte) {
1192+
m := make(map[string]string, c.RequestCtx().QueryArgs().Len())
1193+
c.RequestCtx().QueryArgs().VisitAll(func(key, value []byte) {
11941194
m[c.app.getString(key)] = c.app.getString(value)
11951195
})
11961196
return m
@@ -1219,7 +1219,7 @@ func (c *DefaultCtx) Queries() map[string]string {
12191219
// unknown := Query[string](c, "unknown", "default") // Returns "default" since the query parameter "unknown" is not found
12201220
func Query[V GenericType](c Ctx, key string, defaultValue ...V) V {
12211221
var v V
1222-
q := c.App().getString(c.Context().QueryArgs().Peek(key))
1222+
q := c.App().getString(c.RequestCtx().QueryArgs().Peek(key))
12231223

12241224
return genericParseType[V](q, v, defaultValue...)
12251225
}
@@ -1630,7 +1630,7 @@ func (c *DefaultCtx) SendFile(file string, config ...SendFile) error {
16301630
// Apply cache control header
16311631
if status != StatusNotFound && status != StatusForbidden {
16321632
if len(cacheControlValue) > 0 {
1633-
c.Context().Response.Header.Set(HeaderCacheControl, cacheControlValue)
1633+
c.RequestCtx().Response.Header.Set(HeaderCacheControl, cacheControlValue)
16341634
}
16351635

16361636
return nil

Diff for: ctx_interface_gen.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ctx_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -843,24 +843,24 @@ func Benchmark_Ctx_Body_With_Compression_Immutable(b *testing.B) {
843843
}
844844
}
845845

846-
// go test -run Test_Ctx_Context
847-
func Test_Ctx_Context(t *testing.T) {
846+
// go test -run Test_Ctx_RequestCtx
847+
func Test_Ctx_RequestCtx(t *testing.T) {
848848
t.Parallel()
849849
app := New()
850850
c := app.AcquireCtx(&fasthttp.RequestCtx{})
851851

852-
require.Equal(t, "*fasthttp.RequestCtx", fmt.Sprintf("%T", c.Context()))
852+
require.Equal(t, "*fasthttp.RequestCtx", fmt.Sprintf("%T", c.RequestCtx()))
853853
}
854854

855-
// go test -run Test_Ctx_UserContext
856-
func Test_Ctx_UserContext(t *testing.T) {
855+
// go test -run Test_Ctx_Context
856+
func Test_Ctx_Context(t *testing.T) {
857857
t.Parallel()
858858
app := New()
859859
c := app.AcquireCtx(&fasthttp.RequestCtx{})
860860

861861
t.Run("Nil_Context", func(t *testing.T) {
862862
t.Parallel()
863-
ctx := c.UserContext()
863+
ctx := c.Context()
864864
require.Equal(t, ctx, context.Background())
865865
})
866866
t.Run("ValueContext", func(t *testing.T) {
@@ -872,36 +872,36 @@ func Test_Ctx_UserContext(t *testing.T) {
872872
})
873873
}
874874

875-
// go test -run Test_Ctx_SetUserContext
876-
func Test_Ctx_SetUserContext(t *testing.T) {
875+
// go test -run Test_Ctx_SetContext
876+
func Test_Ctx_SetContext(t *testing.T) {
877877
t.Parallel()
878878
app := New()
879879
c := app.AcquireCtx(&fasthttp.RequestCtx{})
880880

881881
testKey := struct{}{}
882882
testValue := "Test Value"
883883
ctx := context.WithValue(context.Background(), testKey, testValue) //nolint: staticcheck // not needed for tests
884-
c.SetUserContext(ctx)
885-
require.Equal(t, testValue, c.UserContext().Value(testKey))
884+
c.SetContext(ctx)
885+
require.Equal(t, testValue, c.Context().Value(testKey))
886886
}
887887

888-
// go test -run Test_Ctx_UserContext_Multiple_Requests
889-
func Test_Ctx_UserContext_Multiple_Requests(t *testing.T) {
888+
// go test -run Test_Ctx_Context_Multiple_Requests
889+
func Test_Ctx_Context_Multiple_Requests(t *testing.T) {
890890
t.Parallel()
891891
testKey := struct{}{}
892892
testValue := "foobar-value"
893893

894894
app := New()
895895
app.Get("/", func(c Ctx) error {
896-
ctx := c.UserContext()
896+
ctx := c.Context()
897897

898898
if ctx.Value(testKey) != nil {
899899
return c.SendStatus(StatusInternalServerError)
900900
}
901901

902902
input := utils.CopyString(Query(c, "input", "NO_VALUE"))
903903
ctx = context.WithValue(ctx, testKey, fmt.Sprintf("%s_%s", testValue, input)) //nolint: staticcheck // not needed for tests
904-
c.SetUserContext(ctx)
904+
c.SetContext(ctx)
905905

906906
return c.Status(StatusOK).SendString(fmt.Sprintf("resp_%s_returned", input))
907907
})
@@ -913,7 +913,7 @@ func Test_Ctx_UserContext_Multiple_Requests(t *testing.T) {
913913
resp, err := app.Test(httptest.NewRequest(MethodGet, fmt.Sprintf("/?input=%d", i), nil))
914914

915915
require.NoError(t, err, "Unexpected error from response")
916-
require.Equal(t, StatusOK, resp.StatusCode, "context.Context returned from c.UserContext() is reused")
916+
require.Equal(t, StatusOK, resp.StatusCode, "context.Context returned from c.Context() is reused")
917917

918918
b, err := io.ReadAll(resp.Body)
919919
require.NoError(t, err, "Unexpected error from reading response body")
@@ -3220,7 +3220,7 @@ func Test_Ctx_SendFile_MaxAge(t *testing.T) {
32203220
// check expectation
32213221
require.NoError(t, err)
32223222
require.Equal(t, expectFileContent, c.Response().Body())
3223-
require.Equal(t, "public, max-age=100", string(c.Context().Response.Header.Peek(HeaderCacheControl)), "CacheControl Control")
3223+
require.Equal(t, "public, max-age=100", string(c.RequestCtx().Response.Header.Peek(HeaderCacheControl)), "CacheControl Control")
32243224
require.Equal(t, StatusOK, c.Response().StatusCode())
32253225
app.ReleaseCtx(c)
32263226
}

0 commit comments

Comments
 (0)