Skip to content
Closed

Polish #1120

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public abstract class AbstractGraphQlHttpHandler {

protected final Log logger = LogFactory.getLog(getClass());

private final static MediaType APPLICATION_GRAPHQL = MediaType.parseMediaType("application/graphql");

private final WebGraphQlHandler graphQlHandler;

Expand Down Expand Up @@ -118,10 +119,9 @@ private static Mono<SerializableGraphQlRequest> applyApplicationGraphQlFallback(
String contentTypeHeader = request.headers().firstHeader(HttpHeaders.CONTENT_TYPE);
if (StringUtils.hasText(contentTypeHeader)) {
MediaType contentType = MediaType.parseMediaType(contentTypeHeader);
MediaType applicationGraphQl = MediaType.parseMediaType("application/graphql");

// Spec requires application/json but some clients still use application/graphql
return applicationGraphQl.includes(contentType) ? ServerRequest.from(request)
return APPLICATION_GRAPHQL.includes(contentType) ? ServerRequest.from(request)
.headers((headers) -> headers.setContentType(MediaType.APPLICATION_JSON))
.body(request.bodyToFlux(DataBuffer.class))
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public static RequestPredicate graphQlSse(String path) {

private static class GraphQlHttpRequestPredicate implements RequestPredicate {

private final static MediaType APPLICATION_GRAPHQL = MediaType.parseMediaType("application/graphql");

private final PathPattern pattern;

private final List<MediaType> contentTypes;
Expand All @@ -86,7 +88,7 @@ private static class GraphQlHttpRequestPredicate implements RequestPredicate {
PathPatternParser parser = PathPatternParser.defaultInstance;
path = parser.initFullPathPattern(path);
this.pattern = parser.parse(path);
this.contentTypes = List.of(MediaType.APPLICATION_JSON, MediaType.parseMediaType("application/graphql"));
this.contentTypes = List.of(MediaType.APPLICATION_JSON, APPLICATION_GRAPHQL);
this.acceptedMediaTypes = accepted;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public abstract class AbstractGraphQlHttpHandler {

protected final Log logger = LogFactory.getLog(getClass());

private final static MediaType APPLICATION_GRAPHQL = MediaType.parseMediaType("application/graphql");

private final IdGenerator idGenerator = new AlternativeJdkIdGenerator();

private final WebGraphQlHandler graphQlHandler;
Expand Down Expand Up @@ -174,9 +176,8 @@ private static SerializableGraphQlRequest applyApplicationGraphQlFallback(
String contentTypeHeader = request.headers().firstHeader(HttpHeaders.CONTENT_TYPE);
if (StringUtils.hasText(contentTypeHeader)) {
MediaType contentType = MediaType.parseMediaType(contentTypeHeader);
MediaType applicationGraphQl = MediaType.parseMediaType("application/graphql");
// Spec requires application/json but some clients still use application/graphql
if (applicationGraphQl.includes(contentType)) {
if (APPLICATION_GRAPHQL.includes(contentType)) {
try {
request = ServerRequest.from(request)
.headers((headers) -> headers.setContentType(MediaType.APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public static RequestPredicate graphQlSse(String path) {

private static class GraphQlHttpRequestPredicate implements RequestPredicate {

private final static MediaType APPLICATION_GRAPHQL = MediaType.parseMediaType("application/graphql");

private final PathPattern pattern;

private final List<MediaType> contentTypes;
Expand All @@ -86,7 +88,7 @@ private static class GraphQlHttpRequestPredicate implements RequestPredicate {
PathPatternParser parser = PathPatternParser.defaultInstance;
path = parser.initFullPathPattern(path);
this.pattern = parser.parse(path);
this.contentTypes = List.of(MediaType.APPLICATION_JSON, MediaType.parseMediaType("application/graphql"));
this.contentTypes = List.of(MediaType.APPLICATION_JSON, APPLICATION_GRAPHQL);
this.acceptedMediaTypes = accepted;
}

Expand Down