spring-cloud / spring-cloud/spring-cloud-gateway
add standard request Content-Type Header Route Predicator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Is your feature request related to a problem? Please describe.
Add support for request content-type Header Route Predicate Factory based on RFC requirements.
That will simplify filtering requests when clients use different software/environments especially for embedded systems.
Content-type is a standart header of HTTP request. Thus it has followign differences:
- it's value is partly case-insensitive, partly could be sensitive.
The type, subtype, and parameter name tokens are case-insensitive.
Parameter values might or might not be case-sensitive, depending on
the semantics of the parameter name. ....A parameter value that matches the token production can be
transmitted either as a token or within a quoted-string. The quoted
and unquoted values are equivalent. For example, the following
examples are all equivalent, but the first is preferred for
consistency:
text/html;charset=utf-8
text/html;charset=UTF-8
Text/HTML;Charset="utf-8"
text/html; charset="utf-8"
- Unlike some similar constructs in other header fields, media type parameters do not allow whitespace (even "bad" whitespace) around the "=" character.
- Internet media types ought to be registered by IANA.
Describe the solution you'd like
something like:
spring:
cloud:
gateway:
routes:
- id: content_type_header_route
uri: https://example.org
predicates:
content-type:
media-type:
type: text
subtype: html
parameter:
value: utf-8
name: charset
is-value-case-insensitive: yes #(default value)
That will require changes in org.springframework.cloud.gateway.handler.predicate package.
Describe alternatives you've considered
It's possible to use Header Route Predicate Factory with custom regexes, thus one needs to take care of case sensitivity, "=" sign spaces which make it less readable
Additional context
https://tools.ietf.org/html/rfc7231#section-3.1.1.1
https://www.iana.org/assignments/media-types/media-types.xhtml
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
(*) when applicable
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing Header Route Predicate Factory and the org.springframework.cloud.gateway.handler.predicate package named in the issue. Read RFC 7231 section 3.1.1.1 and compare the requested media-type and parameter matching rules with the proposed route configuration. Done means a standard Content-Type route predicate supports the stated case, quoting, whitespace, and parameter behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100