Skip to content

Commit

Permalink
Merge pull request #14 from webconnex/reset-io-buffer
Browse files Browse the repository at this point in the history
Reset the RawHttpResponse.Body buffer so that it can be re-read by the caller
  • Loading branch information
Ken Michie authored Feb 9, 2024
2 parents 5c18fdf + e25ba3b commit c5780be
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions fc/fullcontact.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ func (fcClient *fullContactClient) validateAndSendMultiFieldRequestAsync(url str
func setPersonResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -524,6 +528,10 @@ func setPersonResponse(apiResponse *APIResponse) {
func setCompanyResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -545,6 +553,10 @@ func setCompanyResponse(apiResponse *APIResponse) {
func setResolveResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -566,6 +578,10 @@ func setResolveResponse(apiResponse *APIResponse) {
func setResolveResponseWithTags(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -587,6 +603,10 @@ func setResolveResponseWithTags(apiResponse *APIResponse) {
func setTagsResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -609,6 +629,10 @@ func setAudienceResponse(apiResponse *APIResponse) {
contentType := apiResponse.RawHttpResponse.Header.Get("Content-Type")
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -634,6 +658,10 @@ func setAudienceResponse(apiResponse *APIResponse) {
func setPermissionCreateResponse(apiResponse *APIResponse) {
_, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -646,6 +674,10 @@ func setPermissionCreateResponse(apiResponse *APIResponse) {
func setPermissionDeleteResponse(apiResponse *APIResponse) {
_, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -658,6 +690,10 @@ func setPermissionDeleteResponse(apiResponse *APIResponse) {
func setPermissionFindResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -679,6 +715,10 @@ func setPermissionFindResponse(apiResponse *APIResponse) {
func setPermissionVerifyResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -700,6 +740,10 @@ func setPermissionVerifyResponse(apiResponse *APIResponse) {
func setPermissionCurrentResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -721,6 +765,10 @@ func setPermissionCurrentResponse(apiResponse *APIResponse) {
func setVerfiySignalsResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -742,6 +790,10 @@ func setVerfiySignalsResponse(apiResponse *APIResponse) {
func setVerfiyMatchResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand All @@ -763,6 +815,10 @@ func setVerfiyMatchResponse(apiResponse *APIResponse) {
func setVerfiyActivityResponse(apiResponse *APIResponse) {
bodyBytes, err := ioutil.ReadAll(apiResponse.RawHttpResponse.Body)
defer apiResponse.RawHttpResponse.Body.Close()

// Reset the buffer so that it can be re-read by the caller.
apiResponse.RawHttpResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

if err != nil {
apiResponse.Err = err
return
Expand Down

0 comments on commit c5780be

Please sign in to comment.