Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 0c3fa8a

Browse files
committed
Add accept and content-type headers silently
1 parent c3e572c commit 0c3fa8a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

graphiql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/graphiql/boot/GraphiQLController.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.nio.charset.Charset;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
import java.util.Properties;
511
import lombok.extern.slf4j.Slf4j;
612
import org.apache.commons.lang3.StringUtils;
7-
import org.apache.commons.lang3.text.StrSubstitutor;
13+
import org.apache.commons.text.StringSubstitutor;
814
import org.springframework.beans.factory.annotation.Autowired;
915
import org.springframework.core.env.Environment;
1016
import org.springframework.core.io.ClassPathResource;
11-
import org.springframework.http.MediaType;
1217
import org.springframework.security.web.csrf.CsrfToken;
1318
import org.springframework.util.StreamUtils;
1419
import org.springframework.web.bind.annotation.PathVariable;
1520
import org.springframework.web.bind.annotation.RequestParam;
1621

17-
import java.io.IOException;
18-
import java.io.InputStream;
19-
import java.nio.charset.Charset;
20-
import java.util.HashMap;
21-
import java.util.Map;
22-
import java.util.Properties;
23-
2422
/**
2523
* @author Andrew Potter
2624
*/
@@ -63,7 +61,8 @@ private void loadHeaders() {
6361
headerProperties = propertyReader.load();
6462
}
6563

66-
public byte[] graphiql(String contextPath, @PathVariable Map<String, String> params, Object csrf) {
64+
public byte[] graphiql(String contextPath, @PathVariable Map<String, String> params,
65+
Object csrf) {
6766
if (csrf != null) {
6867
CsrfToken csrfToken = (CsrfToken) csrf;
6968
headerProperties.setProperty(csrfToken.getHeaderName(), csrfToken.getToken());
@@ -75,7 +74,7 @@ public byte[] graphiql(String contextPath, @PathVariable Map<String, String> par
7574
contextPath + graphiQLProperties.getSTATIC().getBasePath()
7675
);
7776

78-
String populatedTemplate = StrSubstitutor.replace(template, replacements);
77+
String populatedTemplate = StringSubstitutor.replace(template, replacements);
7978
return populatedTemplate.getBytes(Charset.defaultCharset());
8079
}
8180

@@ -89,7 +88,8 @@ private Map<String, String> getReplacements(
8988
replacements.put("subscriptionsEndpoint", subscriptionsEndpoint);
9089
replacements.put("staticBasePath", staticBasePath);
9190
replacements.put("pageTitle", graphiQLProperties.getPageTitle());
92-
replacements.put("pageFavicon", getResourceUrl(staticBasePath, "favicon.ico", FAVICON_GRAPHQL_ORG));
91+
replacements
92+
.put("pageFavicon", getResourceUrl(staticBasePath, "favicon.ico", FAVICON_GRAPHQL_ORG));
9393
replacements.put("es6PromiseJsUrl", getResourceUrl(staticBasePath, "es6-promise.auto.min.js",
9494
joinCdnjsPath("es6-promise", "4.1.1", "es6-promise.auto.min.js")));
9595
replacements.put("fetchJsUrl", getResourceUrl(staticBasePath, "fetch.min.js",
@@ -115,9 +115,11 @@ private Map<String, String> getReplacements(
115115
log.error("Cannot serialize headers", e);
116116
}
117117
replacements
118-
.put("subscriptionClientTimeout", String.valueOf(graphiQLProperties.getSubscriptions().getTimeout() * 1000));
118+
.put("subscriptionClientTimeout",
119+
String.valueOf(graphiQLProperties.getSubscriptions().getTimeout() * 1000));
119120
replacements
120-
.put("subscriptionClientReconnect", String.valueOf(graphiQLProperties.getSubscriptions().isReconnect()));
121+
.put("subscriptionClientReconnect",
122+
String.valueOf(graphiQLProperties.getSubscriptions().isReconnect()));
121123
replacements.put("editorThemeCss", getEditorThemeCssURL());
122124
return replacements;
123125
}
@@ -153,7 +155,8 @@ private String joinJsDelivrPath(String library, String cdnVersion, String cdnFil
153155
return CDN_JSDELIVR_NET_NPM + library + "@" + cdnVersion + "/" + cdnFileName;
154156
}
155157

156-
private String constructGraphQlEndpoint(String contextPath, @RequestParam Map<String, String> params) {
158+
private String constructGraphQlEndpoint(String contextPath,
159+
@RequestParam Map<String, String> params) {
157160
String endpoint = graphiQLProperties.getEndpoint().getGraphql();
158161
for (Map.Entry<String, String> param : params.entrySet()) {
159162
endpoint = endpoint.replaceAll("\\{" + param.getKey() + "}", param.getValue());

0 commit comments

Comments
 (0)