File tree Expand file tree Collapse file tree 1 file changed +19
-9
lines changed Expand file tree Collapse file tree 1 file changed +19
-9
lines changed Original file line number Diff line number Diff line change 1
1
package interceptors
2
2
3
- const (
4
- ContentTypeHeaderValue = "application/json; charset=utf-8 "
3
+ import (
4
+ "net/http "
5
5
)
6
6
7
- // const (
8
- // contentTypeHeaderName = "Content-Type"
9
- // )
7
+ const ContentTypeHeaderValue = "application/json; charset=utf-8"
10
8
11
- // TODO: add ReqContentType interceptor:
12
- // if req.Body != nil && req.Body != http.NoBody {
13
- // req.Header.Set(contentTypeHeaderName, i.ContentType)
14
- // }
9
+ const contentTypeHeaderName = "Content-Type"
10
+
11
+ // SetReqContentType sets Content-Type header to 'v' for requests with not empty body.
12
+ func SetReqContentType (client * http.Client , v string ) error {
13
+ return SetReq (client , setContentType (v ))
14
+ }
15
+
16
+ func setContentType (v string ) ReqUpdater {
17
+ return func (req * http.Request ) error {
18
+ if req .Body != nil && req .Body != http .NoBody {
19
+ req .Header .Set (contentTypeHeaderName , v )
20
+ }
21
+
22
+ return nil
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments