284 Commits

Author SHA1 Message Date
9708475b3b docs(context): fix AbortWithStatusPureJSON comment typo (#4310)
Co-authored-by: 1911860538 <alxps1911@gmail.com>
2025-07-22 21:36:47 +08:00
e4c2a27624 refactor(context): remove unused Context dependency in get method (#4304)
Co-authored-by: 1911860538 <alxps1911@gmail.com>
2025-07-22 11:19:08 +08:00
dbd8a25150 feat: added AbortWithStatusPureJSON() in Context (#4290)
* feat: added `AbortWithStatusPureJSON()` in context

* Update context_test.go
2025-07-13 09:40:35 +08:00
41d8591eb1 refactor(context): refactor Keys type to map[any]any (#3963)
* refactor(context): refactor keys to `map[any]any`

Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>

* refactor(context): refactor keys to `map[any]any`

Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>

* style(context): remove empty lines before GetInt16, GetIntSlice, and GetStringMapString methods

- Remove unnecessary empty lines in the context.go file
- Improve code readability and consistency

Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>

* refactor(context): simplify GetStringSlice function

- Replace manual type assertion with generic getTyped function
- Reduce code duplication and improve type safety

Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>

* test(context): improve context.Set and context.Get tests

- Split existing test into separate functions for different scenarios
- Add test for setting and getting values with any key type
- Add test for handling non-comparable keys
- Improve assertions to check for key existence and value correctness

Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>

* refactor(context): replace fmt.Errorf with fmt.Sprintf in panic message

* test(context): remove trailing hyphen from context_test.go

* refactor(context): improve error message for missing key in context

- Remove unnecessary quotes around the key in the error message
- Simplify the error message format for better readability

* test(context): improve panic test message for non-existent key

---------

Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
2025-05-26 23:15:14 +08:00
40725d85ba chore(bind): return 413 status code when error is http.MaxBytesError (#4227)
* Bind: return 413 status code when error is `http.MaxBytesError`

The Go standard library includes a method `http.MaxBytesReader` that allows limiting the request body. For example, users can create a middleware like:

```go
func MiddlewareMaxBodySize(c *gin.Context) {
	// Limit request body to 100 bytes
	c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 100)
	c.Next()
}
```

When the body exceeds the limit, reading from the request body returns an error of type `http.MaxBytesError`.

This PR makes sure that when the error is of kind `http.MaxBytesError`, Gin returns the correct status code 413 (Request Entity Too Large) instead of a generic 400 (Bad Request).

* Disable test when using sonic

* Fix

* Disable for go-json too

* Add references to GitHub issues

* Test that the response is 400 for sonic and go-json
2025-05-25 20:36:33 +08:00
fb09c825e8 feat(context): add SetCookieData (#4240)
* feat(context): add SetCookieStruct (#4215)# This is a combination of 2 commits.

feat(context): add SetCookieStruct (#4215)

feat(context): add SetCookieStruct (#4215)

* feat(context): add SetCookieStruct (#4215)

* feat(context): fix SetCookieStruct→SetCookieData (gin-gonic#4215)

* fix(context): respect caller-specified SameSite value in SetCookieData
2025-05-21 08:20:44 +08:00
a4baac6e5e refactor(context):Avoid using filepath.Dir twice in SaveUploadedFile (#4181)
Co-authored-by: voyager1 <voyager1@voyager1deMacBook-Pro.local>
2025-03-18 22:14:38 +08:00
1eb827240e docs: fix case error of X-Real-IP (#4185)
Co-authored-by: voyager1 <voyager1@voyager1deMacBook-Pro.local>
2025-03-18 22:12:36 +08:00
e46bd52185 refactor(context): add an optional permission parameter to the SaveUploadedFile method (#4068) (#4088)
Co-authored-by: hso <hso@trinitysoft.co.kr>
2024-11-15 23:54:06 +08:00
f875d87283 chore(context): test context initialization and handler logic (#4087)
* enhance code imported by #3413

if it needs to check if the handler is nil, tie c.index shall
always ++

* test: refactor test context initialization and handler logic

- Remove an empty line in `TestContextInitQueryCache`
- Add `TestContextNext` function with tests for `Next` method behavior with no handlers, one handler, and multiple handlers

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: zjj <zhong2plus@gmail.com>
2024-11-15 23:49:08 +08:00
c8a3adc657 refactor(context): simplify "GetType()" functions (#4080)
This PR introduces a generic function, getTyped[T any], to simplify value retrieval in the Context struct. It replaces repetitive type assertions in the GetString  GetBool etc. methods.

Co-authored-by: Maksim Konovalov <maksim.konovalov@vk.team>
2024-10-29 23:24:53 +08:00
647311aba2 refactor(context): refactor context handling and improve test robustness (#4066)
Use assert.InDelta for float comparison with tolerance in TestContextGetFloat32
Remove unnecessary blank line in TestContextInitQueryCache
Replace anonymous struct with named contextKey type in TestContextWithFallbackValueFromRequestContext
Update context key handling in TestContextWithFallbackValueFromRequestContext to use contextKey type
2024-10-25 09:33:31 +08:00
9d7c0e9e1a feat(context): GetXxx added support for more go native types (#3633) 2024-09-15 08:58:59 +08:00
e0d46ded6c fix(context): verify URL is Non-nil in initQueryCache() (#3969) 2024-05-19 10:48:07 +08:00
4f339e6a35 fix(context): YAML judgment logic in Negotiate (#3966) 2024-05-14 10:25:54 +08:00
36b0dede4b fix(context): check handler is nil (#3413)
* fixed #3404 2022-11-23

* up 2022-11-23

* refactor: refactor context handling and nil checks

- Refactor nil checks to improve readability in `context.go`
- Modify the control flow in `HandlerNames` and `Next` methods to continue on nil values before appending or invoking handlers in `context.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* test: refactor context_test.go for clarity and efficiency

- Insert a `nil` value into the `HandlersChain` array in `context_test.go`
- Remove empty test functions in `context_test.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-05-13 14:55:41 +08:00
6ca8ddb1ae feat(binding): add BindPlain (#3904)
* add BindPlain

* fix ci/cd error
2024-05-13 11:11:56 +08:00
c964ad370b chore(optimize): the ShouldBindUri method of the Context struct (#3911)
Co-authored-by: huangzw <huangzw@hsmap.com>
2024-04-01 12:58:01 +08:00
7a865dcf1d feat(bind): ShouldBindBodyWith shortcut and change doc (#3871)
* feat: ShouldBindBodyWith shortcut and change doc

* fix: yaml can parse json test case

* style: fix new test case in context_test.go

* chore: modify the code style to specify binding type

* chroe: gofmt modifies the code format
2024-03-23 22:09:02 +08:00
2b1da2b0b3 fix(context): make context Value method adhere to Go standards (#3897) 2024-03-21 21:08:41 +08:00
ab8042e9e5 chore(request): check reader if it's nil before reading (#3419) 2024-03-11 22:44:28 +08:00
83fc7673f9 docs: fix typo in function documentation (#3872) 2024-03-11 22:25:28 +08:00
646312aef6 fix: protect Context.Keys map when call Copy method (#3873) 2024-03-11 22:24:36 +08:00
09f8224593 fix(route): Add fullPath in context copy (#3784)
* fix: Add fullPath in context copy

* Update context.go

---------

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-03-06 16:46:53 +08:00
739d2d9c80 chore(perf): Optimize the Copy method of the Context struct (#3859)
* Optimize the Copy method of the Context struct: using 'make' to initialize the map('cp.Keys') with a length of 'c.Keys'; avoiding repeatedly assiging the 'params' to 'context'.

* Using temporary variables to save c.Keys and c.Params to prevent them from changing during the copying process.

---------

Co-authored-by: huangzw <huangzw@hsmap.com>
2024-03-05 14:07:11 +08:00
bb1fc2e0fe fix Request.Context() checks (#3512)
Co-authored-by: Bence Vidosits <bence.vidosits1@ibm.com>
2023-05-29 09:59:35 +08:00
2d4bbec941 fix lack of escaping of filename in Content-Disposition (#3556)
* fix lack of escaping of filename in Content-Disposition

* add test for Content-Disposition filename escaping process

* fix filename escape bypass problem
fix backslashes before backquotes were not properly escaped problem.
2023-05-29 09:57:53 +08:00
1e1f0b1e76 chore: support min go version 1.18 (#3511)
* chore: min go version 1.18

* fix build tag error

* remove build tag

* fix word

* remove any.go

* replace interface{} instead of any
2023-03-01 10:03:48 +08:00
0c96a20209 Stop useless panicking in context and render (#2150)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2023-02-12 10:01:33 +08:00
7cb151bb4c fix(context): panic on NegotiateFormat - index out of range (#3397) 2023-01-16 22:50:07 +08:00
7d8fc1563b update context.go Get/Set method use defer (#3429)
Using defer to unlock  is more in line with go standards
2023-01-02 11:39:26 +08:00
cc367f9125 docs(context): #3369 modify the annotation about Context.Param() (#3414) 2022-12-01 13:15:31 +08:00
Qt
6150c488e7 remove deprecated of package io/ioutil (#3395) 2022-11-17 22:35:55 +08:00
212267d671 fix: fix typo in comment (#3371) 2022-11-08 19:54:48 +08:00
45c758e2f9 chore(file): Creates a directory named path (#3316)
Co-authored-by: mohanak <mohanak@mkcl.org>
2022-10-16 09:45:08 +08:00
b04917c53e chore: upgrade golangci-lint and fix golangci-lint error (#3278) 2022-08-15 21:38:20 +08:00
6c3a1d7063 Small doc fix on Context's ClientIP() method. (#3180) 2022-06-09 10:08:49 +08:00
wei
f197a8bae0 feat(context): add ContextWithFallback feature flag (#3166) (#3172)
Enable fallback Context.Deadline(), Context.Done(), Context.Err() and Context.Value()
2022-06-06 18:43:53 +08:00
4b68a5f12a chore: update go.mod and remove space from copyright (#3158)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-05-28 10:42:28 +08:00
ed03102ef0 [GIN-001] - Add TOML bining for gin (#3081)
Co-authored-by: GitstartHQ <gitstart@users.noreply.github.com>
2022-05-28 08:34:43 +08:00
e61cc06955 feat(context): return GIN Context from Value method (#2825) 2022-04-23 18:02:54 +08:00
6854212698 Fix: missing sameSite when do context.reset() (#3123) 2022-04-17 12:41:59 +08:00
2bde107686 test support go1.18 (#2990) 2022-03-21 09:43:17 +08:00
8860527de6 feat attachment filename support utf8 (#3071) 2022-03-17 11:56:16 +08:00
580e7da6ee Remove incorrect comments about context.Bind() and improve docs (#3028) 2022-01-20 22:33:35 +08:00
01363191be fix: typo (#3006) 2022-01-02 14:04:07 +08:00
92a988d761 fix: description error (#2988)
* fix:typo

* fix: typo

* fix: wrong when wildcard follows named param

* fix: description error

* update author list

* fix:typo

* fix: description error
2021-12-18 19:40:47 +08:00
0be805a675 TrustedProxies: Add default IPv6 support and refactor (#2967) 2021-12-03 14:49:16 +08:00
bc2417fc40 fix: description error (#2968) 2021-11-30 08:36:36 +08:00
ffb3b73430 fix: description error (#2961) 2021-11-26 16:38:10 +08:00