1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-1070 Read response body data before closing (#1071)

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer 2021-03-27 19:30:18 -07:00 committed by GitHub
parent 2fd9d623a1
commit 8eb4a25891
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,10 @@
package jira package jira
import ( import (
"bytes"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -10,6 +12,8 @@ import (
"github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/utils"
) )
// IssuesFor returns a collection of issues for a given collection of projects.
// If username is provided, it scopes the issues to that person
func (widget *Widget) IssuesFor(username string, projects []string, jql string) (*SearchResult, error) { func (widget *Widget) IssuesFor(username string, projects []string, jql string) (*SearchResult, error) {
query := []string{} query := []string{}
@ -38,7 +42,7 @@ func (widget *Widget) IssuesFor(username string, projects []string, jql string)
} }
searchResult := &SearchResult{} searchResult := &SearchResult{}
err = utils.ParseJSON(searchResult, resp.Body) err = utils.ParseJSON(searchResult, bytes.NewReader(resp))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -52,7 +56,7 @@ func buildJql(key string, value string) string {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *Widget) jiraRequest(path string) (*http.Response, error) { func (widget *Widget) jiraRequest(path string) ([]byte, error) {
url := fmt.Sprintf("%s%s", widget.settings.domain, path) url := fmt.Sprintf("%s%s", widget.settings.domain, path)
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
@ -61,13 +65,15 @@ func (widget *Widget) jiraRequest(path string) (*http.Response, error) {
} }
req.SetBasicAuth(widget.settings.email, widget.settings.apiKey) req.SetBasicAuth(widget.settings.email, widget.settings.apiKey)
httpClient := &http.Client{Transport: &http.Transport{ httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
InsecureSkipVerify: !widget.settings.verifyServerCertificate, InsecureSkipVerify: !widget.settings.verifyServerCertificate,
}, },
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
}, },
} }
resp, err := httpClient.Do(req) resp, err := httpClient.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -78,7 +84,12 @@ func (widget *Widget) jiraRequest(path string) (*http.Response, error) {
return nil, fmt.Errorf(resp.Status) return nil, fmt.Errorf(resp.Status)
} }
return resp, nil body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
} }
func getProjectQuery(projects []string) string { func getProjectQuery(projects []string) string {