mirror of
https://github.com/gfleury/go-bitbucket-v1.git
synced 2025-04-05 01:10:12 -05:00
Merge pull request #69 from brainexe/real_all_body
read full request.Body to reuse http/1 connections
This commit is contained in:
commit
8e7ed04b84
@ -7,6 +7,7 @@ package bitbucketv1
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@ -668,7 +669,6 @@ func GetActivitiesResponse(r *APIResponse) (Activities, error) {
|
|||||||
|
|
||||||
// NewAPIResponse create new APIResponse from http.Response
|
// NewAPIResponse create new APIResponse from http.Response
|
||||||
func NewAPIResponse(r *http.Response) *APIResponse {
|
func NewAPIResponse(r *http.Response) *APIResponse {
|
||||||
|
|
||||||
response := &APIResponse{Response: r}
|
response := &APIResponse{Response: r}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
@ -688,10 +688,18 @@ func NewAPIResponseWithError(r *http.Response, bodyBytes []byte, err error) (*AP
|
|||||||
// NewBitbucketAPIResponse create new API response from http.response
|
// NewBitbucketAPIResponse create new API response from http.response
|
||||||
func NewBitbucketAPIResponse(r *http.Response) (*APIResponse, error) {
|
func NewBitbucketAPIResponse(r *http.Response) (*APIResponse, error) {
|
||||||
response := &APIResponse{Response: r}
|
response := &APIResponse{Response: r}
|
||||||
err := json.NewDecoder(r.Body).Decode(&response.Values)
|
|
||||||
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
err := decoder.Decode(&response.Values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if decoder.More() {
|
||||||
|
// there's more data in the stream, so discard whatever is left
|
||||||
|
_, _ = io.Copy(ioutil.Discard, r.Body)
|
||||||
|
}
|
||||||
|
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user