Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for compressed hydrator. Closes #988 #1018

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion pipeline/mutate/mutator_hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@

import (
"bytes"
"compress/gzip"
"compress/zlib"
"crypto/md5"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"time"
Expand All @@ -51,6 +54,8 @@
ErrNoCredentialsProvided = "No credentials were provided in mutator configuration"
contentTypeHeaderKey = "Content-Type"
contentTypeJSONHeaderValue = "application/json"
acceptEncodingHeaderKey = "Accept-Encoding"
acceptEncodingHeaderValue = "gzip, deflate"
)

type MutatorHydrator struct {
Expand Down Expand Up @@ -188,6 +193,7 @@
req.SetBasicAuth(credentials.Username, credentials.Password)
}
req.Header.Set(contentTypeHeaderKey, contentTypeJSONHeaderValue)
req.Header.Set(acceptEncodingHeaderKey, acceptEncodingHeaderValue)

var client *http.Client

Expand Down Expand Up @@ -235,8 +241,21 @@
return errors.New(ErrNon200ResponseFromAPI)
}

// Handle compressed data
var reader io.ReadCloser
switch res.Header.Get("Content-Encoding") {
case "gzip":
reader, err = gzip.NewReader(res.Body)
defer reader.Close()
case "deflate":
reader, err = zlib.NewReader(res.Body)
defer reader.Close()

Check warning on line 252 in pipeline/mutate/mutator_hydrator.go

View check run for this annotation

Codecov / codecov/patch

pipeline/mutate/mutator_hydrator.go#L247-L252

Added lines #L247 - L252 were not covered by tests
default:
reader = res.Body
}

sessionFromUpstream := authn.AuthenticationSession{}
err = json.NewDecoder(res.Body).Decode(&sessionFromUpstream)
err = json.NewDecoder(reader).Decode(&sessionFromUpstream)
if err != nil {
return errors.WithStack(err)
}
Expand Down