MM-13606 Remove consumeAndClose and clean up integration response handling (#10066)

* MM-13606 Remove consumeAndClose

* Allow overriding HTTPService's request timeout

* MM-13606 Clean up integration response handling

* Properly close httptest servers

* Address feedback

* Only call buf.Bytes when necessary

* Properly check for errors in doOutgoingWebhookRequest

* Add comment explaining ignored ioutil.ReadAll errors
This commit is contained in:
Harrison Healey
2019-01-09 17:07:08 -05:00
committed by GitHub
parent e67fe4c89d
commit 1a3ccaf305
18 changed files with 458 additions and 195 deletions

View File

@@ -7,6 +7,7 @@ import (
"net"
"net/http"
"strings"
"time"
"github.com/mattermost/mattermost-server/services/configservice"
)
@@ -20,7 +21,7 @@ type HTTPService interface {
// MakeTransport returns a RoundTripper that is suitable for making requests to external resources. The default
// implementation provides:
// - A shorter timeout for dial and TLS handshake (defined as constant "ConnectTimeout")
// - A timeout for end-to-end requests (defined as constant "RequestTimeout")
// - A timeout for end-to-end requests
// - A Mattermost-specific user agent header
// - Additional security for untrusted and insecure connections
MakeTransport(trustURLs bool) http.RoundTripper
@@ -28,14 +29,22 @@ type HTTPService interface {
type HTTPServiceImpl struct {
configService configservice.ConfigService
RequestTimeout time.Duration
}
func MakeHTTPService(configService configservice.ConfigService) HTTPService {
return &HTTPServiceImpl{configService}
return &HTTPServiceImpl{
configService,
RequestTimeout,
}
}
func (h *HTTPServiceImpl) MakeClient(trustURLs bool) *http.Client {
return NewHTTPClient(h.MakeTransport(trustURLs))
return &http.Client{
Transport: h.MakeTransport(trustURLs),
Timeout: h.RequestTimeout,
}
}
func (h *HTTPServiceImpl) MakeTransport(trustURLs bool) http.RoundTripper {