Skip to content

Commit 5b54138

Browse files
jansupolsenivam
authored andcommitted
Set Content-Type to application/octet-stream when not set when matching @consumes
Signed-off-by: jansupol <[email protected]>
1 parent 5b15428 commit 5b54138

File tree

51 files changed

+1144
-769
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1144
-769
lines changed

connectors/jdk-connector/src/main/java/org/glassfish/jersey/jdk/connector/internal/TransferEncodingParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -218,8 +218,8 @@ private boolean parseHttpChunkLength(final ByteBuffer input) throws ParseExcepti
218218

219219
while (offset < limit) {
220220
final byte b = input.get(offset);
221-
if (isSpaceOrTab(b) || /*trailing spaces are not allowed by the spec, but some server put it there*/
222-
b == HttpParserUtils.CR || b == HttpParserUtils.SEMI_COLON) {
221+
if (isSpaceOrTab(b) /*trailing spaces are not allowed by the spec, but some server put it there*/
222+
|| b == HttpParserUtils.CR || b == HttpParserUtils.SEMI_COLON) {
223223
headerParsingState.checkpoint = offset;
224224
} else if (b == HttpParserUtils.LF) {
225225
contentParsingState.chunkContentStart = offset + 1;

core-server/src/main/java/org/glassfish/jersey/server/ServerProperties.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,43 @@ public final class ServerProperties {
741741
public static final String UNWRAP_COMPLETION_STAGE_IN_WRITER_ENABLE =
742742
"jersey.config.server.unwrap.completion.stage.writer.enable";
743743

744+
/**
745+
* <p>
746+
* When an HTTP request does not contain a media type, the media type should default to {@code application/octet-stream}.
747+
* In the past, Jersey used to match any {@code @Consumes} when the HTTP {@code Content-Type} header was not set.
748+
* This property is to preserve the behaviour. Such behaviour is potentially dangerous, though.
749+
* The default behaviour is to set the request media type to {@code application/octet-stream} when none set.
750+
* This is a Jakarta REST requirement.
751+
* </p>
752+
* <p>
753+
* This change can be can be eminent especially for HTTP resource methods which do not expect an entity, such as HTTP GET:
754+
* <pre>
755+
* {@code
756+
* @Consumes(MediaType.TEXT_PLAIN)
757+
* @Produces(MediaType.TEXT_PLAIN)
758+
* @Path("/")
759+
* public class Resource {
760+
* @GET
761+
* public String get() {
762+
* return ...
763+
* }
764+
* }
765+
* }
766+
* </pre>
767+
* The client request needs to contain the {@code Content-Type} HTTP header, for instance:
768+
* {@code
769+
* webTarget.request().header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN).get()
770+
* }
771+
* </p>
772+
* <p>
773+
* Set this property to true, if the empty request media type is to match any {@code @Consumes}. The default is {@code false}.
774+
* The name of the configuration property is <tt>{@value}</tt>.
775+
* </p>
776+
* @since 3.1.0
777+
*/
778+
public static final String EMPTY_REQUEST_MEDIA_TYPE_MATCHES_ANY_CONSUMES =
779+
"jersey.config.server.empty.request.media.matches.any.consumes";
780+
744781
/**
745782
* JVM argument to define the value of
746783
* {@link org.glassfish.jersey.server.internal.monitoring.core.ReservoirConstants#COLLISION_BUFFER_POWER}.

0 commit comments

Comments
 (0)