-
Notifications
You must be signed in to change notification settings - Fork 1
/
context_header.go
123 lines (98 loc) · 4.19 KB
/
context_header.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package zoox
import (
"fmt"
"time"
"github.com/go-zoox/headers"
)
// SetContentType sets the request content-type header.
func (ctx *Context) SetContentType(contentType string) {
ctx.SetHeader(headers.ContentType, contentType)
}
// SetCacheControl sets the request cache-control header.
func (ctx *Context) SetCacheControl(cacheControl string) {
ctx.SetHeader(headers.CacheControl, cacheControl)
}
// SetCacheControlWithMaxAge sets the request cache-control header with max-age.
func (ctx *Context) SetCacheControlWithMaxAge(maxAge time.Duration) {
ctx.SetCacheControl(fmt.Sprintf("max-age=%d", int(maxAge.Seconds())))
}
// SetCacheControlWithNoCache sets the request cache-control header with no-cache.
func (ctx *Context) SetCacheControlWithNoCache() {
ctx.SetCacheControl("no-cache")
}
// SetCacheControlWithNoStore sets the request cache-control header with no-store.
func (ctx *Context) SetCacheControlWithNoStore() {
ctx.SetCacheControl("no-store")
}
// SetHSTS sets the request strict-transport-security header.
func (ctx *Context) SetHSTS(maxAge time.Duration) {
ctx.SetHeader(headers.StrictTransportSecurity, fmt.Sprintf("max-age=%d", int(maxAge.Seconds())))
}
// SetXFramOptions sets the request x-frame-options header.
func (ctx *Context) SetXFramOptions(value string) {
ctx.SetHeader(headers.XFrameOptions, value)
}
// SetXFramOptionsDeny sets the request x-frame-options header with deny.
func (ctx *Context) SetXFramOptionsDeny() {
ctx.SetXFramOptions("deny")
}
// SetXFramOptionsSameOrigin sets the request x-frame-options header with sameorigin.
func (ctx *Context) SetXFramOptionsSameOrigin() {
ctx.SetXFramOptions("sameorigin")
}
// SetXFramOptionsAllowFrom sets the request x-frame-options header with allow-from.
func (ctx *Context) SetXFramOptionsAllowFrom(uri string) {
ctx.SetXFramOptions(fmt.Sprintf("allow-from %s", uri))
}
// SetXDownloadOptions sets the request x-download-options header.
func (ctx *Context) SetXDownloadOptions(value string) {
ctx.SetHeader(headers.XDownloadOptions, value)
}
// SetXDownloadOptionsNoOpen sets the request x-download-options header with noopen.
func (ctx *Context) SetXDownloadOptionsNoOpen() {
ctx.SetXDownloadOptions("noopen")
}
// SetXDownloadOptionsNoSniff sets the request x-download-options header with nosniff.
func (ctx *Context) SetXDownloadOptionsNoSniff() {
ctx.SetXDownloadOptions("nosniff")
}
// SetXXSSProtection sets the request x-xss-protection header.
func (ctx *Context) SetXXSSProtection(value string) {
ctx.SetHeader(headers.XXSSProtection, value)
}
// SetXXSSProtectionEnable sets the request x-xss-protection header with 1; mode=block.
func (ctx *Context) SetXXSSProtectionEnable() {
ctx.SetXXSSProtection("1; mode=block")
}
// SetXXSSProtectionDisable sets the request x-xss-protection header with 0.
func (ctx *Context) SetXXSSProtectionDisable() {
ctx.SetXXSSProtection("0")
}
// SetXXSSProtectionReport sets the request x-xss-protection header with 1; report=<reporting-uri>.
func (ctx *Context) SetXXSSProtectionReport(reportingURI string) {
ctx.SetXXSSProtection(fmt.Sprintf("1; report=%s", reportingURI))
}
// SetPoweredBy sets the request x-powered-by header.
func (ctx *Context) SetPoweredBy(value string) {
ctx.SetHeader(headers.XPoweredBy, value)
}
// SetContentDisposition sets the request content-disposition header with attachment.
func (ctx *Context) SetContentDisposition(filename string) {
ctx.SetHeader(headers.ContentDisposition, fmt.Sprintf("attachment; filename=\"%s\"", filename))
}
// SetContentDispositionInline sets the request content-disposition header with inline.
func (ctx *Context) SetContentDispositionInline(filename string) {
ctx.SetHeader(headers.ContentDisposition, fmt.Sprintf("inline; filename=\"%s\"", filename))
}
// SetDownloadFilename sets the request content-disposition header with attachment and filename.
func (ctx *Context) SetDownloadFilename(filename string) {
ctx.SetContentDisposition(filename)
}
// SetContentLocation sets the request content-location header.
func (ctx *Context) SetContentLocation(value string) {
ctx.SetHeader(headers.ContentLocation, value)
}
// SetLocation sets the request location header.
func (ctx *Context) SetLocation(value string) {
ctx.SetHeader(headers.Location, value)
}