-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
37 lines (31 loc) · 848 Bytes
/
http.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
package main
import (
"bytes"
"fmt"
"net/http"
"github.com/nsqio/nsq/internal/http_api"
"github.com/nsqio/nsq/internal/version"
)
var httpclient *http.Client
var userAgent string
func init() {
httpclient = &http.Client{Transport: http_api.NewDeadlineTransport(*httpTimeout)}
userAgent = fmt.Sprintf("nsq_to_http v%s", version.Binary)
}
func HTTPGet(endpoint string) (*http.Response, error) {
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
return httpclient.Do(req)
}
func HTTPPost(endpoint string, body *bytes.Buffer) (*http.Response, error) {
req, err := http.NewRequest("POST", endpoint, body)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", userAgent)
req.Header.Set("Content-Type", *contentType)
return httpclient.Do(req)
}