Xudong Cai
03e5e05ae0
fix: data race with trustedCIDRs ( #2674 ) ( #2675 )
...
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-04-09 00:27:34 +08:00
Manu MA
bfc8ca285e
feat(engine): add trustedproxies and remoteIP ( #2632 )
...
Co-authored-by: Søren L. Hansen <soren@linux2go.dk>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Javier Provecho Fernandez <javiertitan@gmail.com>
2021-04-06 11:37:25 +08:00
An Xiao (Luffy)
7742ff50e0
Fix typos in context.go ( #2551 )
2020-11-11 09:41:35 +08:00
eudore
540b1eff70
update content-disposition header to MIME-style ( #2512 )
2020-09-25 09:45:17 +08:00
John Bampton
3100b7cb05
Fix spelling ( #2498 )
2020-09-14 10:40:20 +08:00
kaiiak
0304ee96ed
Add GetUint and GetUint64 method on gin.context ( #2487 )
2020-09-01 09:33:54 +08:00
Florian Polster
815e1ce281
Prevent panic in Context.GetQuery() when there is no Request ( #2412 )
...
Co-authored-by: thinkerou <thinkerou@gmail.com>
2020-08-08 20:32:19 +08:00
thinkerou
1d5b9badd9
chore: rename getQueryCache/getFormCache to initQueryCache/initFormCache ( #2375 )
2020-05-14 11:35:14 +08:00
Bo-Yi Wu
d17270dd90
Sync route tree to httprouter latest code ( #2368 )
...
* update tree
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* update countParams
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* fix testing
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* udpate
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* fix testing
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* refactor gin context
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* add fullPath
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* chore: refactor
* remove unused code
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* remove varsCount
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* refactor
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-05-10 13:22:25 +08:00
thinkerou
6ac7f194c4
chore: update some code style ( #2356 )
2020-05-05 13:55:57 +08:00
thinkerou
54175dbe72
chore: update the result of CR ( #2354 )
...
* chore: update the result of CR
* Update utils.go
* Update utils.go
* Update context.go
* Update context.go
2020-05-04 11:40:41 +08:00
Bo-Yi Wu
2c43278080
chore(performance): Change *sync.RWMutex to sync.RWMutex ( #2351 )
2020-05-03 20:39:34 +08:00
Bo-Yi Wu
298ebca691
fix missing initial sync.RWMutex ( #2305 )
...
* fix missing initial sync.RWMutex
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* Add unit testing.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-03-27 10:57:36 +08:00
Bo-Yi Wu
57f99ca50f
Add set samesite in cookie. ( #2306 )
...
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-03-27 10:47:22 +08:00
AcoNCodes
73ccfea3ba
Add mutex for protect Context.Keys map ( #1391 )
...
* Add mutex for protect Context.Keys map
* Fix tests
Co-authored-by: Nikolay Tolkachov <nik.tolkachov@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-03-17 00:52:02 +08:00
Nikifor Seryakov
1d055af1bc
FileFromFS ( #2112 )
...
* Context.FileFromFS added
* Context File and FileFromFS examples at README
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-03-07 10:23:33 +08:00
Erik Bender
731c827892
add yaml negotitation ( #2220 )
...
Co-authored-by: thinkerou <thinkerou@gmail.com>
2020-02-06 14:50:21 +08:00
ali
f94406a087
Added support for SameSite cookie flag ( #1615 )
...
* Added support for SameSite cookie flag
* fixed tests.
* Update context.go
* Update context_test.go
* Update context_test.go
Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-01-20 15:12:44 +08:00
Andrey Abramov
424e9685be
Update docs on Context.Done(), Context.Deadline() and Context.Err() ( #2196 )
...
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-01-08 01:48:28 +08:00
John Bampton
b8a7b6d194
Fix spelling ( #2202 )
2020-01-07 09:19:49 +08:00
linfangrong
0f951956d0
[FIX] c.Request.FormFile maybe file, need close ( #2114 )
2019-10-31 23:17:12 +08:00
willnewrelic
0ce4661029
Use Writer in Context.Status ( #1606 )
2019-10-17 10:14:44 +08:00
Santhosh Kumar
2e5a7196cc
use url.URL.Query instead of parsing query ( #2063 )
2019-09-24 10:01:57 +08:00
Panmax
b8b2fada5c
fix GetPostFormMap ( #2051 )
2019-09-10 14:32:30 +08:00
guonaihong
f98b339b77
support bind http header param #1956 ( #1957 )
...
* support bind http header param #1956
update #1956
```
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
type testHeader struct {
Rate int `header:"Rate"`
Domain string `header:"Domain"`
}
func main() {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
h := testHeader{}
if err := c.ShouldBindHeader(&h); err != nil {
c.JSON(200, err)
}
fmt.Printf("%#v\n", h)
c.JSON(200, gin.H{"Rate": h.Rate, "Domain": h.Domain})
})
r.Run()
// client
// curl -H "rate:300" -H "domain:music" 127.0.0.1:8080/
// output
// {"Domain":"music","Rate":300}
}
```
* add unit test
* Modify the code to get the http header
When the http header is obtained in the standard library,
the key value will be modified by the CanonicalMIMEHeaderKey function,
and finally the value of the http header will be obtained from the map.
As follows.
```go
func (h MIMEHeader) Get(key string) string {
// ...
v := h[CanonicalMIMEHeaderKey(key)]
// ...
}
```
This pr also follows this modification
* Thanks to vkd for suggestions, modifying code
* Increase test coverage
env GOPATH=`pwd` go test github.com/gin-gonic/gin/binding -coverprofile=cover.prof
ok github.com/gin-gonic/gin/binding 0.015s coverage: 100.0% of statements
* Rollback check code
* add use case to README.md
2019-06-27 12:47:45 +08:00
田欧
75b9d2bed7
Attempt to fix PostForm cache bug ( #1931 )
2019-06-12 21:07:15 +08:00
Bo-Yi Wu
08b52e5394
feat: improve get post data. ( #1920 )
...
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-06-02 17:24:41 +08:00
Bo-Yi Wu
4b6df417e4
chore: improve GetQueryMap performance. ( #1918 )
...
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-05-29 14:54:55 +08:00
ijaa
233a3e493d
add context param query cache ( #1450 )
2019-05-29 11:25:02 +08:00
Samuel Abreu
6e320c97e8
Fix context.Params race condition on Copy() ( #1841 )
...
* Fix context.Params race condition on Copy()
Using context.Param(key) on a context.Copy inside a goroutine
may lead to incorrect value on a high load, where another request
overwrite a Param
* Using waitgroup to wait asynchronous test case
2019-05-27 14:04:30 +08:00
Roman Zaynetdinov
35e33d3638
Hold matched route full path in the Context ( #1826 )
...
* Return nodeValue from getValue method
* Hold route full path in the Context
* Add small example
2019-05-26 08:20:21 +08:00
Kirill Motkov
b1d607a899
Some code improvements ( #1909 )
...
* strings.ToLower comparison changed to strings.EqualFold.
* Rewrite switch statement with only one case as if.
2019-05-21 23:08:52 +08:00
Dan Markham
094f9a9105
v1.4.0 + #1631 (remove go1.6/go1,7 support) ( #1851 )
...
* remove go1.6 support
* remove build tag
* remove todo
* remove go1.6 support: https://github.com/gin-gonic/gin/pull/1383/commits
* update readme
* remove go1.7 support
* fix embedmd error
* test
* revert it
* revert it
* remove context_17
* add pusher test
* v1.4.0 rc1
2019-05-07 18:32:32 +08:00
Daniel Krom
893c6cae07
Added stream flag indicates if client disconnected in middle of streaming ( #1252 )
2019-03-02 23:07:37 +08:00
Emmanuel Goh
ccb9e90295
Extend context.File to allow for the content-dispositon attachments via a new method context.Attachment ( #1260 )
...
* Add FileAttachment method to context to allow instant downloads with filenames
* Add relevant tests for FileAttachment method
2019-03-01 10:17:47 +08:00
Equim
2dd3193006
Support negotiation wildcards, fix #391 ( #1112 )
...
* support negotiation wildcards, fix #391
* fix typo
2019-03-01 10:03:14 +08:00
Raphael Gavache
e207a3ce65
Fix context.Copy() race condition ( #1020 )
...
* Fix context.Copy race condition
* Update githubapi_test.go
* fix code format
2019-02-26 15:10:16 +08:00
Luis GG
62749f0db4
Add context.HandlerNames() ( #1729 )
...
* Add context.HandlerNames()
This change adds a HandlerNames method that will return all registered handles in the context, in descending order
This is useful for debugging and troubleshooting purposes, especially in large apps
* Tests
Add tests for HandlerNames
* Fix HandlerNames test
* Simplify test
2019-02-26 12:15:40 +08:00
Dmitry Kutakov
4867ff9634
fix Context.Next() - recheck len of handlers every iteration ( #1745 )
...
* fix Context.Next() - recheck len of handlers every iteration
* add tests when Context.reset() can be called inside of handler
TestEngineHandleContext
TestContextResetInHandler
TestRouterStaticFSFileNotFound
* Context.Next() - format to while style
2019-01-18 09:57:06 +08:00
Dmitry Kutakov
b056a34bdc
fix errcheck warnings ( #1739 )
2019-01-18 09:32:53 +08:00
thinkerou
29a145c85d
Revert "context: inherits context cancelation and deadline from http.Request context for Go>=1.7 ( #1690 )" ( #1736 )
...
This reverts commit f67d7a90c4
.
2019-01-09 09:32:44 +08:00
Romain Beuque
f67d7a90c4
context: inherits context cancelation and deadline from http.Request context for Go>=1.7 ( #1690 )
...
*gin.Context implements standard context.Context methods, but always
returns data as context is still valid. Since Go 1.7, http.Request now
contains a context.Context object, which can be controlled by the
http.Server to indicates that the context is now closed, and persue of
request should be canceled.
This implements the propagation of http.Request context methods inside
gin.Context to have HTTP context cancelation information at gin.Context
level.
Signed-off-by: Romain Beuque <romain.beuque@corp.ovh.com>
2018-12-13 11:20:17 +08:00
thinkerou
59695e7ba8
Add BindUri ( #1694 )
...
* add BindUri
* fix bug
* fix code style
2018-12-12 23:40:29 +08:00
thinkerou
521d06c81d
support bind uri param ( #1612 )
...
* support bind uri (1)
* uri binding successful run
* fix vet warning: github.com/gin-gonic/gin/internal.Param composite literal uses unkeyed fields
* fix code style
* update function name
* fix test function signature
* add test for CanSet
* update readme and add test case
* remove internal.Params
* add coverage
* fix warning
2018-11-22 09:29:48 +08:00
Gordon Tyler
8cb390f8fe
Yaml binding ( #1618 )
...
* Add YAML binding for application/x-yaml.
* Add YAML binding methods to Context.
* Review fixes.
* Revert accidentally removed import.
2018-11-06 09:49:45 +08:00
Barnabus
7a374f9a47
Fix typos ( #1626 )
2018-11-05 14:17:04 +08:00
Ismail Gjevori
dbc330b804
Pass MaxMultipartMemory when FormFile is called ( #1600 )
...
When `gin.Context.FormFile("...")` is called the `engine.MaxMultipartMemory` is never used. This PR makes sure that the `MaxMultipartMemory` is passed and removes 2 calls to `http.Request.ParseForm` since they are called from `http.Request.ParseMultipartForm`
2018-10-22 23:01:14 +08:00
田欧
6db092f778
chore: add some annotations ( #1550 )
...
ref #1075 should all annotations and can close #1075 .
2018-09-15 15:21:54 +08:00
田欧
85f3e78abc
chore: remove else instead of return/continue ( #1502 )
...
As[ Effective Go](https://golang.org/doc/effective_go.html?#if ) about `if` said, remove else statement instead of return/continue statement.
2018-08-20 21:49:24 +08:00
田欧
6073a79ee0
not use protobuf on context but use it on render ( #1496 )
2018-08-19 17:39:58 +08:00
aljun
efdd3c8b81
Add support for Protobuf format response and unit test ( #1479 )
...
`Gin` now have the `protobufBinding` function to check the request format, but didn't have a protobuf response function like `c.YAML()`.
In our company [ByteDance](http://bytedance.com/ ), the largest internet company using golang in China, we use `gin` to transfer __Protobuf__ instead of __Json__, we have to write some internal library to make some wrappers to achieve that, and the code is not elegant. So we really want such a feature.
2018-08-19 10:45:56 +08:00
syssam
40ab9de4b5
Add BindXML AND ShouldBindXML #1484 ( #1485 )
...
Add BindXML AND ShouldBindXML #1484
2018-08-17 09:12:15 +08:00
田欧
647535cd9b
Support map as query string or post form parameters ( #1383 )
...
* support query map
* add GetQueryMap and unittest
* support post-form map
* add readme for query map
* attempt to fix bug for post-form map when go version is 1.6
* remove duplicate code
* remove comment
2018-08-06 12:07:11 +08:00
Dmitry Dorogin
631cfbd1ef
Simplify context error ( #1431 )
...
Hello!
Looking through context package and found a little bit complicated switch block. And tried to make it easier.
Thanks!
2018-08-05 13:29:26 +08:00
solos
220e8d3453
return json if jsonp has not callback ( #1438 )
...
return json if jsonp has not callback
2018-07-21 00:52:55 +08:00
Rex Lee(李俊)
85221af84c
add json ASCII string render ( #1358 )
...
add a json render that rendering json as ASCII string
2018-07-03 17:17:08 +08:00
田欧
eb9f313144
add comment for context ( #1413 )
...
ref #1075
annotation from go context source.
2018-06-28 17:08:09 +08:00
田欧
6c6d97ba2e
remove hardcode instead of http status value ( #1411 )
2018-06-26 17:21:32 +08:00
田欧
8035359102
use strings.Split instead of strings.IndexByte ( #1406 )
2018-06-23 00:08:58 +08:00
Jean-Christophe Lebreton
bf7803815b
Serve easily dynamic files with `DataFromReader` context method ( #1304 )
...
* Add DataFromReader context method
* Replace fmt by strconv.FormatInt
* Add pull request link to README
2018-05-12 11:00:42 +08:00
JINNOUCHI Yasushi
995fa8e9ce
Fix #216 : Enable to call binding multiple times in some formats ( #1341 )
...
* Add interface to read body bytes in binding
* Add BindingBody implementation for some binding
* Fix to use `BindBodyBytesKey` for key
* Revert "Fix to use `BindBodyBytesKey` for key"
This reverts commit 2c82901cea
.
* Use private-like key for body bytes
* Add tests for BindingBody & ShouldBindBodyWith
* Add note for README
* Remove redundant space between sentences
2018-05-11 10:33:33 +08:00
senhtry
8c24018290
Add Jsonp Support to Context ( #1333 )
2018-04-26 11:52:19 +08:00
Himanshu Mishra
46662e700b
Doc: Fix typo in documentation of Bind ( #1204 )
2017-12-20 09:32:39 +08:00
田欧
9a4ecc87d6
format some codes style ( #1165 )
2017-11-11 23:24:51 -06:00
Suhas Karanth
dfb68ce085
feat(context): ShouldBind counterparts for Bind methods ( #1047 )
...
* feat(context): ShouldBind counterparts for Bind methods + tests
* docs(readme): Switch examples to use ShouldBind methods
Add section for bind methods types, explain difference in behavior.
Switch all `c.Bind` examples to use `c.ShouldBind`.
2017-10-23 11:14:09 +02:00
Daniel M. Lambea
c9b344118f
Moved const 'defaultMemory' to attrib. Engine.MaxMultipartMemory instead. ( #1100 )
2017-09-07 11:45:16 +08:00
Eason Lin
8902826696
doc(context): add cookie doc ( #1088 )
2017-08-28 21:38:53 +02:00
Bo-Yi Wu
211c48f040
refactor: using requestHeader internal func ( #1083 )
...
* refactor: using requestHeader internal func.
* update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-08-26 12:02:47 +02:00
Dan Markham
b9686e91fa
Use standard library for retrieving header ( #1081 )
2017-08-25 23:53:27 -05:00
田欧
a8fa424ae5
update comment ( #1057 )
2017-08-16 11:55:50 +08:00
Eason Lin
df37e74fa1
doc(context): more clearer bind doc when input is not valid ( #1049 )
2017-08-01 12:49:28 +08:00
Eason Lin
7fafb3f4a1
doc(context): add status func comment. ( #1042 )
2017-07-28 08:50:58 +08:00
Eason Lin
c19aa0598b
feat(context): add BindQuery func ( #1029 )
...
* feat(context): add BindQuery func, only parse/bind the query string params.
* docs(readme): add BindQuery section.
* docs(readme): fix import.
* docs(readme): separate import
2017-07-19 09:50:05 +02:00
田欧
7180f2ba62
not use tmp var ( #1032 )
2017-07-17 22:39:39 -05:00
Eason Lin
93b3a0d7ec
feat(context): add SaveUploadedFile func. ( #1022 )
...
* feat(context): add SaveUploadedFile func.
* feat(context): update multiple upload examples.
* style(example): fix gofmt
* fix(example): add missing return
2017-07-15 22:42:08 -05:00
田欧
aa6d2d29f8
refactor(doc): use space not tab ( #1006 )
2017-07-11 10:28:08 -05:00
Eason Lin
75ed286c60
feat: add SecureJSON func to prevent json hijacking
2017-07-08 01:21:30 +08:00
田欧
e0fd6238d3
use comma ok and use single line ( #984 )
2017-07-06 09:49:54 -05:00
田欧
b985857899
update func comment ( #981 )
2017-07-05 20:28:16 -05:00
Javier Provecho Fernandez
42a34cdc35
docs(context): document keys, errors, and accepted, close #488
2017-07-05 16:55:59 +02:00
Javier Provecho Fernandez
d875f07409
Merge branch 'master' into develop
2017-07-02 14:23:55 +02:00
Javier Provecho Fernandez
68aa2c38da
fix(context): switch deprecated bindwith for mustbindwith
2017-06-28 00:46:35 +02:00
Javier Provecho Fernandez
1a9cba2cc7
Merge pull request #855 from gin-gonic/feat/662
...
feat(context): add idiomatic binding functions for clear err managment
2017-06-28 00:16:34 +02:00
Javier Provecho Fernandez
9a79e3f144
fix(import): switch sse import from gopkg to github
2017-06-27 23:17:02 +02:00
Bo-Yi Wu
1e1e4fc867
Add Makefile to check the following thing ( #947 )
...
* Add Makefile to check the following thing.
* vet check
* fmt check
* embedmd check
* misspell check
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* remove unused variable.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-12 21:50:42 -05:00
collinmsn
3f95933c3d
Add method to return main handler ( #930 )
...
Fix #928 Method to get main handler is desired
2017-06-02 03:00:55 -05:00
Javier Provecho Fernandez
5eea51b6c9
feat(context): add cast helpers to c.Keys ( #856 )
...
* feat(context): add cast helpers to c.Keys
* Add tests for cast helpers to c.Keys
2017-06-01 20:00:04 -05:00
Ammar Bandukwala
781cbd19f0
panic if err is nil on c.Error
...
A panic here provides a more informative stack trace than the panic which would otherwise occur while errors are being collected.
2017-05-09 22:30:56 -05:00
Rahul Datta Roy
d4a53101c3
Fix minor type in context.go ( #900 )
...
* Fix minor type in context.go
* More spelling fixes in context.go
2017-05-04 09:22:48 +08:00
Bo-Yi Wu
41316b9ca9
feat: add GetRawData func. ( #857 )
...
* feat: add GetRawData func.
* update return style
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-03-31 08:45:56 +08:00
Javier Provecho
73e5fcd855
feat(context): add idiomatic binding functions for clear err managment
2017-03-29 14:32:12 +00:00
Bo-Yi Wu
ad2dacedd6
feat: Support get value from request header. ( #839 )
2017-03-24 20:43:23 +08:00
pjgg
6ce1e86a27
chore(errorHandler):new abortWithStatus method with Json body ( #800 )
2017-02-14 09:11:01 +08:00
mbesancon
2d8477fc42
Fixed typos in Context ( #797 )
...
Simple english typos in the Copy() method
2017-02-01 22:47:50 +08:00
Javier Provecho Fernandez
963acc4b0c
Fix #198 ( #781 )
...
* Add new function to Render interface for writing content type only
* Add support for the new function in Render interface for writing content-type only
* Fix unhandled merge conflict in context_test.go
* Update vendor.json
2017-01-09 16:24:48 +01:00
tsirolnik
c115074d77
Use X-Forwarded-For before X-Real-Ip
...
Nginx uses X-Real-Ip with its IP instead of the client's IP. Therefore, we should use X-Forwarded-For *before* X-Real-Ip
2017-01-03 23:43:05 +08:00
David Irvine
ebe3580daf
Add convenience method to check if websockets required ( #779 )
...
* Add convenience method to check if websockets required
* Add tests
* Fix up tests for develop branch
2017-01-02 16:05:30 +08:00
Bo-Yi Wu
5cc3d5955f
Support upload single or multiple files.
...
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2016-12-24 12:25:01 +08:00
Javier Provecho Fernandez
2cab17ba50
Merge pull request #701 from maxatome/patch-1
...
Context.Get() does not need to test whether Keys is nil or not
2016-12-06 20:39:01 +01:00
Bo-Yi Wu
764e138e32
Merge pull request #755 from gin-gonic/755-app-engine-client-ip
...
Fix #723
2016-12-06 08:14:11 -06:00