-
Notifications
You must be signed in to change notification settings - Fork 3
/
content_type.go
36 lines (28 loc) · 1.04 KB
/
content_type.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
package httputils
import (
"fmt"
"github.com/valyala/fasthttp"
)
type ContentType string
func (c ContentType) SetCharset(charset string) ContentType {
return NewContentType(fmt.Sprintf("%s; charset=%s", c, charset))
}
func (c ContentType) SetBoundary(boundary string) ContentType {
return NewContentType(fmt.Sprintf("%s; boundary=%s", c, boundary))
}
func NewContentType(contentType string) ContentType { return ContentType(contentType) }
const (
TextHTML ContentType = "text/html"
TextPlain ContentType = "text/plain"
AppOctetStream ContentType = "application/octet-stream"
AppJSON ContentType = "application/json"
AppFormUrlencoded ContentType = "application/x-www-form-urlencoded"
AppXML ContentType = "application/xml"
MultiFormData ContentType = "multipart/form-data"
)
func (h *HTTP) SetContentType(contentType ContentType) *HTTP {
return h.Add(func(client *fasthttp.Client, req *fasthttp.Request, resp *fasthttp.Response) error {
req.Header.SetContentType(string(contentType))
return nil
})
}