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

SetResult fails to parse JSON when the returned Content-Type is "application/x-amz-json-1.1" #594

Closed
zackwine opened this issue Oct 25, 2022 · 2 comments · Fixed by #702
Closed
Assignees
Labels
Milestone

Comments

@zackwine
Copy link

I found the SetResult API fails to parse the result JSON if the Content-Type is equal to "application/x-amz-json-1.1" (which Amazon uses for some endpoints). Would it be possible to add this as a supported Content-Type, or possibly support setting a custom JSON Content-Type for resty?

Looks like this is the regex that is failing to match: https://github.com/go-resty/resty/blob/master/client.go#L63

@segevda
Copy link
Contributor

segevda commented Oct 31, 2022

As a workaround, you can set application/json as the content-type using Request.ForceContentType method, which will force resty to unmarshall the resp body as a JSON.

tsbkw added a commit to tsbkw/resty that referenced this issue Oct 31, 2022
[Issue go-resty#594](go-resty#594) can be workaround by set `application/json` as ForceContentType,
but content-type may be different depends on response, and
ForceContentType assumes that server always return same content type.

AddForceUnmarshalRule enables unmarshal depends on content-type from
server.

Previously createGenServer return xml response without root element and
it cannot be unmarshalled because encoding/xml.Unmarshal is only
unmarshal chidlren of root element.
Now add root element in response and change assertion in test case
accordingly.
tsbkw added a commit to tsbkw/resty that referenced this issue Oct 31, 2022
[Issue go-resty#594](go-resty#594) can be worked around by set `application/json` as ForceContentType,
but content-type may be different depends on response, and
ForceContentType assumes that server always return same content type.

AddForceUnmarshalRule enables unmarshal depends on content-type from
server.

Previously createGenServer return xml response without root element and
it cannot be unmarshalled because encoding/xml.Unmarshal is only
unmarshal chidlren of root element.
Now add root element in response and change assertion in test case
accordingly.
@zackwine
Copy link
Author

@segevda Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants