Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resource/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (u *HTTP) Validate(sys *system.System) []TestResult {
RequestHeader: u.RequestHeader, RequestBody: u.RequestBody, Method: u.Method})
sysHTTP.SetAllowInsecure(u.AllowInsecure)
sysHTTP.SetNoFollowRedirects(u.NoFollowRedirects)
defer sysHTTP.Close()

var results []TestResult
results = append(results, ValidateValue(u, "status", u.Status, sysHTTP.Status, skip))
Expand Down
10 changes: 10 additions & 0 deletions system/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type HTTP interface {
Exists() (bool, error)
SetAllowInsecure(bool)
SetNoFollowRedirects(bool)
Close() error
}

type DefHTTP struct {
Expand All @@ -46,6 +47,7 @@ type DefHTTP struct {
KeyFile string
Method string
Proxy string
bodyConsumed bool
}

func NewDefHTTP(_ context.Context, httpStr string, system *System, config util.Config) HTTP {
Expand Down Expand Up @@ -214,10 +216,18 @@ func (u *DefHTTP) Body() (io.Reader, error) {
if err := u.setup(); err != nil {
return nil, err
}
u.bodyConsumed = true

return u.resp.Body, nil
}

func (u *DefHTTP) Close() error {
if u.resp != nil && u.resp.Body != nil && !u.bodyConsumed {
return u.resp.Body.Close()
}
return nil
}

func hasUserAgentHeader(headers []string) bool {
for _, header := range headers {
if strings.HasPrefix(strings.ToLower(header), USER_AGENT_HEADER_PREFIX) {
Expand Down
Loading