Skip to content

Commit

Permalink
add Accept and decode response with +json suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Dec 12, 2024
1 parent 67ce0d2 commit 66499a3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions connector/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (client *HTTPClient) evalHTTPResponse(ctx context.Context, span trace.Span,
}

result = string(respBody)
case contentType == rest.ContentTypeXML:
case contentType == rest.ContentTypeXML || strings.HasSuffix(contentType, "+xml"):
field, extractErr := client.extractResultType(resultType)
if extractErr != nil {
return nil, nil, extractErr
Expand All @@ -384,7 +384,7 @@ func (client *HTTPClient) evalHTTPResponse(ctx context.Context, span trace.Span,
if err != nil {
return nil, nil, schema.NewConnectorError(http.StatusInternalServerError, err.Error(), nil)
}
case contentType == rest.ContentTypeJSON:
case contentType == rest.ContentTypeJSON || strings.HasSuffix(contentType, "+json"):
if len(resultType) > 0 {
namedType, err := resultType.AsNamed()
if err == nil && namedType.Name == string(rest.ScalarString) {
Expand Down
4 changes: 4 additions & 0 deletions connector/internal/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (c *RequestBuilder) Build() (*RetryableRequest, error) {
return nil, err
}

if rawRequest.Response.ContentType != "" && request.Headers.Get(acceptHeader) == "" {
request.Headers.Set(acceptHeader, rawRequest.Response.ContentType)
}

if rawRequest.RuntimeSettings != nil {
if rawRequest.RuntimeSettings.Timeout > 0 {
request.Runtime.Timeout = rawRequest.RuntimeSettings.Timeout
Expand Down
1 change: 1 addition & 0 deletions connector/internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

const (
acceptHeader = "Accept"
contentTypeHeader = "Content-Type"
defaultTimeoutSeconds uint = 30
defaultRetryDelays uint = 1000
Expand Down

0 comments on commit 66499a3

Please sign in to comment.