@@ -14,6 +14,13 @@ import (
14
14
"github.com/elastic/beats/libbeat/outputs/transport"
15
15
)
16
16
17
+ const (
18
+ gzipEncoding = "gzip"
19
+ urlSchemaHTTP = "http"
20
+ urlSchemaHTTPS = "https"
21
+ )
22
+
23
+ // SimpleTransport contains the dialer and read/write callbacks
17
24
type SimpleTransport struct {
18
25
Dialer transport.Dialer
19
26
DisableCompression bool
@@ -32,7 +39,7 @@ func (t *SimpleTransport) checkRequest(req *http.Request) error {
32
39
}
33
40
34
41
scheme := req .URL .Scheme
35
- isHTTP := scheme == "http" || scheme == "https"
42
+ isHTTP := scheme == urlSchemaHTTP || scheme == urlSchemaHTTPS
36
43
if ! isHTTP {
37
44
return fmt .Errorf ("http: unsupported scheme %v" , scheme )
38
45
}
@@ -43,6 +50,7 @@ func (t *SimpleTransport) checkRequest(req *http.Request) error {
43
50
return nil
44
51
}
45
52
53
+ // RoundTrip sets up goroutines to write the request and read the responses
46
54
func (t * SimpleTransport ) RoundTrip (req * http.Request ) (* http.Response , error ) {
47
55
type readReturn struct {
48
56
resp * http.Response
@@ -68,7 +76,7 @@ func (t *SimpleTransport) RoundTrip(req *http.Request) (*http.Response, error) {
68
76
req .Method != "HEAD" {
69
77
70
78
requestedGzip = true
71
- req .Header .Add ("Accept-Encoding" , "gzip" )
79
+ req .Header .Add ("Accept-Encoding" , gzipEncoding )
72
80
defer req .Header .Del ("Accept-Encoding" )
73
81
}
74
82
@@ -132,7 +140,7 @@ func (t *SimpleTransport) readResponse(
132
140
}
133
141
t .sigStartRead ()
134
142
135
- if requestedGzip && resp .Header .Get ("Content-Encoding" ) == "gzip" {
143
+ if requestedGzip && resp .Header .Get ("Content-Encoding" ) == gzipEncoding {
136
144
resp .Header .Del ("Content-Encoding" )
137
145
resp .Header .Del ("Content-Length" )
138
146
resp .ContentLength = - 1
0 commit comments