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(plugins/response-transformer): support mime type structured syntax suffix #10656

Merged
merged 4 commits into from
May 24, 2023

Conversation

vm-001
Copy link
Contributor

@vm-001 vm-001 commented Apr 12, 2023

Summary

Based on the RFC(https://www.rfc-editor.org/rfc/rfc6839#section-3.1), application/problem+json is a valid mime type, and is a subset of application/json, can be treated like json.

Checklist

Issue reference

FTI-4959

@vm-001 vm-001 force-pushed the FTI-4959 branch 2 times, most recently from 425ed72 to a77d0e7 Compare April 12, 2023 03:17
@vm-001 vm-001 marked this pull request as ready for review April 12, 2023 03:18
@vm-001 vm-001 force-pushed the FTI-4959 branch 2 times, most recently from 76cf4a9 to daf8caa Compare April 12, 2023 05:45
kong/tools/mime_type.lua Show resolved Hide resolved
kong/tools/mime_type.lua Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -175,7 +175,9 @@
- **Request Transformer**: honor value of untrusted_lua configuration parameter
[#10327](https://github.com/Kong/kong/pull/10327)
- **OAuth2**: fix an issue that OAuth2 token was being cached to nil while access to the wrong service first.
[#10522](https://github.com/Kong/kong/pull/10522)
[#10522](https://github.com/Kong/kong/pull/10522)
- **Response Transformer**: fix an issue that plugin does not transform the response body while upstream returns a Content-Type with +json suffix at subtype.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **Response Transformer**: fix an issue that plugin does not transform the response body while upstream returns a Content-Type with +json suffix at subtype.
- **Response Transformer**: Support the use of structured syntax suffixes when parsing and matching content types.

kong/tools/mime_type.lua Show resolved Hide resolved
local JSON_MEDIA_TYPES = {
{ type = "application", subtype = "json" },
{ type = "application", subtype = "*+json" },
}
Copy link
Contributor

@hanshuebner hanshuebner Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to specify that a subtype is allowed? When parsing a document of a certain media type, its structured subtypes will always be permitted. The subtype information is useful for processors that know how to deal specifically with documents of that subtype. All other processors can always treat all subtype documents as if they were of the main type. Effectively, when matching a media type without a subtype, the subtype information can always be ignored and the additional *+json media type is not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on how we design the includes util function. Here, the includes is not taking application/problem+json as included to application/json, since the last one does not contain the wildcard.

The utils function does not have the knowledge of which specific mime types belong to its “parent” type. It just does the wildcard match.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The utils function does not have the knowledge of which specific mime types belong to its “parent” type. It just does the wildcard match.

As the function is designed to work with mime types, it should know thatapplication/json includes application/problem+json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that logic is reused by many places, I think it makes sense to come up with another convenient function that can consider that application/json includes application/problem+json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a commit. Would you please continue to review it?

local JSON_MEDIA_TYPES = {
{ type = "application", subtype = "json" },
{ type = "application", subtype = "*+json" },
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The utils function does not have the knowledge of which specific mime types belong to its “parent” type. It just does the wildcard match.

As the function is designed to work with mime types, it should know thatapplication/json includes application/problem+json.

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

Successfully merging this pull request may close these issues.

2 participants