-
Notifications
You must be signed in to change notification settings - Fork 121
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
Convenience method for checking header value lists #1066
Conversation
Error: Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.3.0:jar (attach-javadocs) on project jakarta.ws.rs-api: MavenReportException: Error while generating Javadoc: |
6b098ee
to
a9b589e
Compare
Thanks. Fixed. |
If nobody objects to adopting this small feature to JAX-RS 4.0, then I would invest some more time and add a TCK test in this PR and remove the draft state flag. Any objects? Please veto NOW so I spare the time for writing the tests. Thanks. |
A few thoughts about this proposal. First of all: Personally, I never had a situation where this method would have been helpful. However, I see use cases for it, so I'm not against adding it to the API. One thing I'm wondering about is how to deal with case-insensitivity. For the header name, the situation is clear, as HTTP header names are case-insensitive, which should be handled correctly by the implementation. But what about the header value? My first feeling was that it should do a case-sensitive match. However, in case of |
Could Servlet not need the exact same utility? |
We could provide two methods, one case-sensitive and one case-insensitive, just like the JRE does it https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/String.html#equalsIgnoreCase(java.lang.String). |
OT: Frankly spoken, I personally do not see any use of Servlets anymore at all these days. JAX-RS is superior from the user's view in most cases other than performance wrt to HTTP use. I have not used neither Servlets, nor Servlet-based JAX-RS since years (this is why I lead the Java SE Bootstrap project). If you ask me, the core idea of Servlet API is deprecated, as it was invented as a pure Java replacement for NSAPI / ISAPI, hence to enable Java code run on popular web servers like IIS or Apache (which simply tried to prevent starting native processes using (Fast) CGI). Those times are over since decades. Since most people meanwhile migrated to "real" Java based application servers (hence: products able to natively run JAX-RS), and since mainstream users are migrating to cloud / servlerss architectures, there is not much use left over for Servlets. If you ask me, Servlet API should be dropped in favor of a "Streamlet API" which just provides the interface between a JAX-RS implementation and an NIO engine like Netty or Grizzly. The HTTP part should be completely hidden in the JAX-RS engine; if Grizzly / Netty want to process HTTP, they could natively support JAX-Rs instead of Servlet API instead. Having said that: If somebody likes, he could copy my work provided here for JAX-RS, but I personally will not spend a minute into Servlet API anymore. |
Thinking deeper about it, I do not see the need for different methods just to prevent a single "if". I modified the proposal accordingly. WDYT? |
Or should we go with a super-flexible solution instead, like providing a predicate? One could then pass even precompiled regex, a lambda expression, or method handles like boolean containsHeaderString(String name, Predicate<String> valuePredicate) |
Now, this can possibly have a |
Well, yes and no. Technically yes, it certainly could, and I would be happy to sponsor one once a majority agreed upon one of the proposal made so far (case-insensitive always? customizable? separate methods? boolean flag? predicate?). But the original idea was that perfect performance can only be provided with the knowledge of the underlying map implementation: Is it a map? Is it a list of entries? Is it a string array? etc. So all vendors should implment it. Given the fact that I would be happy to provide a PR for Jersey, and that only few competitors do exist, I do not see the benefit of a default implementation, frankly spoken. |
I would think the default should be case-insensitive since in HTTP/1 header names should be case-insensitive. AIUI in HTTP/2 they must be lowercase. |
jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientRequestContext.java
Outdated
Show resolved
Hide resolved
I am not convinced about this method. It could be good for some headers, such as
So there is plenty of HTTP headers that use commas for other purposes than separator. All dates containing headers is such an example (with syntax
For the generic usage, I'd suggest a separator argument (nullable for no split) to separate the header values. |
@jansupol Seems like a reasonable suggestion, and we can still use commas by default. |
Good idea, I will add this in the next iteration of this PR, stay tuned. :-) |
On the other hand, we are using a comma (and exactly a comma but nothing else) in |
Sounds good. |
Implemented by b5f0a9e. |
How do you envision such a default? By an additional variant of the same method having just two parameters? |
What would you like more, breaking backwards compatibility by adding a new argument to the existing method, or adding a second variant of the same method? |
Yes, if we think using commas is a sufficiently common case --as suggested by your original PR. |
4136135
to
d739f8b
Compare
Done. :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
For release 4.0 I'd like to propose a convencience method for response/request contexts which I missed a lot in the past years and which I implemented again and again in multiple ways -- most of them lacking either performance or perfection.
The problem it solves is that it is rather hard to get it perfectly correct checking for items in comma-separated headers - without losing valuable performance.
Example: How to check if there is a
Cache-Control: no-store
value set in case the actual sent headers containsCache-Control
multiple times and each of the findings is possibly a comma-separated list? RegEx over getHeaderString() comes into mind, but this is rather slow, as it first concatenates everything just to split it up afterwards. Iterating all findings comes into mind next, which is everything but convenient nor particularly readable.Solution: An implementation of this new method would be provided by the runtime vendor, hence could provide not only most convenient usage to the caller, but also perform best possible as it is optimized according to the actual implementation's internal map design
WDYT?