File tree Expand file tree Collapse file tree 4 files changed +28
-6
lines changed
core-client/src/main/java/org/glassfish/jersey/client
core-server/src/main/java/org/glassfish/jersey/server Expand file tree Collapse file tree 4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -229,9 +229,19 @@ ClientConfig getClientConfig() {
229229 return clientConfig ;
230230 }
231231
232+ /**
233+ * Get the values of an HTTP request header if the header exists on the current request. The returned value will be
234+ * a read-only List if the specified header exists or {@code null} if it does not. This is a shortcut for
235+ * {@code getRequestHeaders().get(name)}.
236+ *
237+ * @param name the header name, case insensitive.
238+ * @return a read-only list of header values if the specified header exists, otherwise {@code null}.
239+ * @throws java.lang.IllegalStateException if called outside the scope of a request.
240+ */
232241 @ Override
233242 public List <String > getRequestHeader (String name ) {
234- return HeaderUtils .asStringList (getHeaders ().get (name ), clientConfig .getConfiguration ());
243+ final List <Object > values = getHeaders ().get (name );
244+ return values == null ? null : HeaderUtils .asStringList (values , clientConfig .getConfiguration ());
235245 }
236246
237247 @ Override
Original file line number Diff line number Diff line change @@ -821,13 +821,13 @@ private static long roundDown(final long time) {
821821 }
822822
823823 /**
824- * Get the values of a HTTP request header. The returned List is read-only.
825- * This is a shortcut for {@code getRequestHeaders().get(name)}.
824+ * Get the values of an HTTP request header if the header exists on the current request. The returned value will be
825+ * a read-only List if the specified header exists or {@code null} if it does not. This is a shortcut for
826+ * {@code getRequestHeaders().get(name)}.
826827 *
827828 * @param name the header name, case insensitive.
828- * @return a read-only list of header values.
829- *
830- * @throws IllegalStateException if called outside the scope of a request.
829+ * @return a read-only list of header values if the specified header exists, otherwise {@code null}.
830+ * @throws java.lang.IllegalStateException if called outside the scope of a request.
831831 */
832832 @ Override
833833 public List <String > getRequestHeader (final String name ) {
Original file line number Diff line number Diff line change @@ -480,6 +480,11 @@ public String get(@Context HttpHeaders hh) {
480480 </example >
481481 </para >
482482
483+ <para >
484+ For quicker getting of values for a known header name there is a shortcut for <literal >hh.getRequestHeaders().get(name)</literal >
485+ which is <literal >hh.getRequestHeader(name)</literal >.
486+ </para >
487+
483488 <para >In general &jaxrs.core.Context; can be used to obtain contextual Java types related to the request or response.
484489 </para >
485490
Original file line number Diff line number Diff line change 100100 <literal >true</literal >.
101101 </para >
102102 </listitem >
103+ <listitem >
104+ <para >
105+ Since Jersey 3.1.0+ the <literal >getRequestHeader(String name)</literal > method of the
106+ <literal >ClientRequest</literal > class returns NULL (instead of an empty List) in case if
107+ the specified header does not exist.
108+ </para >
109+ </listitem >
103110 </itemizedlist >
104111 </para >
105112 </section >
You can’t perform that action at this time.
0 commit comments