mirror of https://github.com/gin-gonic/gin.git
Compare commits
2 Commits
4857f7c66e
...
cd86308ad1
Author | SHA1 | Date |
---|---|---|
Saksham Arya | cd86308ad1 | |
Saksham Arya | c2e744e158 |
12
context.go
12
context.go
|
@ -21,7 +21,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-contrib/sse"
|
"github.com/gin-contrib/sse"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/binding"
|
"github.com/gin-gonic/gin/binding"
|
||||||
"github.com/gin-gonic/gin/render"
|
"github.com/gin-gonic/gin/render"
|
||||||
)
|
)
|
||||||
|
@ -72,6 +71,9 @@ type Context struct {
|
||||||
// This mutex protects Keys map.
|
// This mutex protects Keys map.
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
|
|
||||||
|
// This mutex protects headers map
|
||||||
|
hmu sync.RWMutex
|
||||||
|
|
||||||
// Keys is a key/value pair exclusively for the context of each request.
|
// Keys is a key/value pair exclusively for the context of each request.
|
||||||
Keys map[string]any
|
Keys map[string]any
|
||||||
|
|
||||||
|
@ -984,8 +986,8 @@ func (c *Context) Status(code int) {
|
||||||
// It writes a header in the response.
|
// It writes a header in the response.
|
||||||
// If value == "", this method removes the header `c.Writer.Header().Del(key)`
|
// If value == "", this method removes the header `c.Writer.Header().Del(key)`
|
||||||
func (c *Context) Header(key, value string) {
|
func (c *Context) Header(key, value string) {
|
||||||
c.mu.Lock()
|
c.hmu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.hmu.Unlock()
|
||||||
if value == "" {
|
if value == "" {
|
||||||
c.Writer.Header().Del(key)
|
c.Writer.Header().Del(key)
|
||||||
return
|
return
|
||||||
|
@ -995,8 +997,8 @@ func (c *Context) Header(key, value string) {
|
||||||
|
|
||||||
// GetHeader returns value from request headers.
|
// GetHeader returns value from request headers.
|
||||||
func (c *Context) GetHeader(key string) string {
|
func (c *Context) GetHeader(key string) string {
|
||||||
c.mu.RLock()
|
c.hmu.RLock()
|
||||||
defer c.mu.RUnlock()
|
defer c.hmu.RUnlock()
|
||||||
return c.requestHeader(key)
|
return c.requestHeader(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-contrib/sse"
|
"github.com/gin-contrib/sse"
|
||||||
|
"github.com/gin-gonic/gin/binding"
|
||||||
|
testdata "github.com/gin-gonic/gin/testdata/protoexample"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin/binding"
|
|
||||||
testdata "github.com/gin-gonic/gin/testdata/protoexample"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ context.Context = (*Context)(nil)
|
var _ context.Context = (*Context)(nil)
|
||||||
|
|
Loading…
Reference in New Issue