-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.go
35 lines (28 loc) · 899 Bytes
/
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
package rest
import (
"fmt"
)
// AddHeader adds a header to the response, replacing any existing entry
func (r *Rest) AddHeader( name string, value string ) *Rest {
r.headers[ name ] = value
return r
}
// GetHeader returns a header from the request or "" if not present
func (r *Rest) GetHeader( name string ) string {
return r.request.Header.Get( name )
}
func (r *Rest) AccessControlAllowOrigin( value string ) *Rest {
if value == "" {
value = "*"
}
return r.AddHeader( "Access-Control-Allow-Origin", value )
}
func (r *Rest) Etag( tag string ) *Rest {
return r.AddHeader( "Etag", "\"" + tag + "\"" )
}
func (r *Rest) CacheMaxAge( age int ) *Rest {
return r.AddHeader( "Cache-Control", fmt.Sprintf( "public, max-age=%d, s-maxage=%d", age, age ) )
}
func (r *Rest) CacheNoCache() *Rest {
return r.AddHeader( "Cache-Control", "no-cache, no-store, must-revalidate" )
}