Commit Graph

231 Commits

Author SHA1 Message Date
Egor Seredin
5929d52171
ClientIP: check every proxy for trustiness (#2844) 2021-10-09 08:38:51 +08:00
Notealot
39181329de
Tidy: Complete TrustedProxies feature (#2887) 2021-10-06 09:37:25 +08:00
joeADSP
97b3c0d88a
Fix grammatical and spelling errors in context.go (#2883) 2021-09-29 07:35:06 +08:00
Matthieu MOREL
71f7087097
golangci(lint) : more linters (#2870) 2021-09-21 15:22:21 +08:00
filikos
deb83b6365
gin.Context.SetParam shortcut for e2e tests (#2848)
* Added SetParam shortcut for e2e tests, added SetParam test

* Adjusted naming and formatting

* fixed typo
2021-09-07 10:08:45 +08:00
Alexander Melentyev
dfc25f91e0
Add short func with named return (#2837) 2021-08-22 09:29:51 +08:00
wei
9a575a4c05
fallback Context.Deadline() Context.Done() Context.Err() to Context.Request.Context() (#2769)
* fallback Context.Deadline() Context.Done() Context.Err() to Context.Request.Context()

* update comments wording
2021-08-01 00:46:53 +08:00
ziheng
c7a28f8532
use bit shift operation instead of division (#2776) 2021-07-06 16:37:14 +08:00
Lanco
372cc4a010
Fix typo (#2772) 2021-07-02 09:58:43 +08:00
wei
7834a03e84
gin.Context with fallback value from gin.Context.Request.Context() (#2751)
* Update tree.go (#2659)

delete more "()"

* updated comments for Get function for params (#2756)

* ci: add github action workflows (#2596)

* ci: add github action workflows

* test: fixed the TestUnixSocket test on windows (#20)

* ci: add github action workflows (#18)

* Remove .travis.yml

* ci: replace GITTER_ROOM_ID and upload coverage every time you go test

* ci: update coverage using codecov/codecov-action@v1

* Merge branch 'master' into github-actions

* repo: replace travis ci to github actions

* ci: add go version 1.16

* fix: go install requires a specific version

* chore(ci): remove go 1.12 support

* chore(ci): remove os windows-latest

Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* Setting trusted platform using an enum-like (#2739)

* gin.Context with fallback value from c.Request.Context()

* add test case

Co-authored-by: youzeliang <youzel@126.com>
Co-authored-by: Ashwani <ashwanisharma686@gmail.com>
Co-authored-by: Jeff <laojianzi1994@gmail.com>
Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com>
2021-06-24 16:33:14 +08:00
Alessandro (Ale) Segala
dd8a27c0b6
Setting trusted platform using an enum-like (#2739) 2021-06-24 08:58:10 +08:00
Alessandro (Ale) Segala
6703dea51c
Get client IP when using Cloudflare (#2723)
Co-authored-by: thinkerou <thinkerou@gmail.com>
2021-05-28 10:03:59 +08:00
tyltr
afb38396b5
optimize code (#2722)
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2021-05-22 13:17:19 +08:00
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