Skip to content

Commit df598c6

Browse files
committed
Make Content-Type match spec requirements
I guess, technically, JSON can be thought of as a kind of Javascript (after all, it's JavaScript Object Notation), but the spec says that we should be using `application/json`, which feels more correct too. Fixes a problem where the ruby remote driver did not want to start a new session.
1 parent 683fb0d commit df598c6

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

java/server/src/org/openqa/selenium/remote/server/AllHandlers.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
package org.openqa.selenium.remote.server;
1919

20-
import static com.google.common.net.MediaType.JAVASCRIPT_UTF_8;
20+
//import static com.google.common.net.MediaType.JAVASCRIPT_UTF_8;
21+
import static com.google.common.net.MediaType.JSON_UTF_8;
2122
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
2223
import static java.net.HttpURLConnection.HTTP_OK;
2324
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -103,7 +104,7 @@ public void execute(HttpRequest req, HttpResponse resp) throws IOException {
103104
.getBytes(UTF_8);
104105

105106
resp.setStatus(HTTP_NOT_FOUND);
106-
resp.setHeader("Content-Type", JAVASCRIPT_UTF_8.toString());
107+
resp.setHeader("Content-Type", JSON_UTF_8.toString());
107108
resp.setHeader("Content-Length", String.valueOf(payload.length));
108109

109110
resp.setContent(payload);
@@ -121,7 +122,7 @@ public void execute(HttpRequest req, HttpResponse resp) throws IOException {
121122
)).getBytes(UTF_8);
122123

123124
resp.setStatus(HTTP_OK);
124-
resp.setHeader("Content-Type", JAVASCRIPT_UTF_8.toString());
125+
resp.setHeader("Content-Type", JSON_UTF_8.toString());
125126
resp.setHeader("Content-Length", String.valueOf(payload.length));
126127

127128
resp.setContent(payload);

java/server/src/org/openqa/selenium/remote/server/BeginSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.openqa.selenium.remote.server;
1919

2020
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
21-
import static com.google.common.net.MediaType.JAVASCRIPT_UTF_8;
21+
import static com.google.common.net.MediaType.JSON_UTF_8;
2222
import static java.net.HttpURLConnection.HTTP_OK;
2323
import static java.nio.charset.StandardCharsets.UTF_8;
2424
import static org.openqa.selenium.remote.BrowserType.CHROME;
@@ -150,7 +150,7 @@ public void execute(HttpRequest req, HttpResponse resp) throws IOException {
150150
resp.setStatus(HTTP_OK);
151151
resp.setHeader("Cache-Control", "no-cache");
152152

153-
resp.setHeader("Content-Type", JAVASCRIPT_UTF_8.toString());
153+
resp.setHeader("Content-Type", JSON_UTF_8.toString());
154154
resp.setHeader("Content-Length", String.valueOf(payload.length));
155155

156156
resp.setContent(payload);

java/server/src/org/openqa/selenium/remote/server/ExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.openqa.selenium.remote.server;
1919

20-
import static com.google.common.net.MediaType.JAVASCRIPT_UTF_8;
20+
import static com.google.common.net.MediaType.JSON_UTF_8;
2121
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
2222
import static java.nio.charset.StandardCharsets.UTF_8;
2323

@@ -56,7 +56,7 @@ public void execute(HttpRequest req, HttpResponse resp) {
5656
byte[] bytes = new Gson().toJson(value).getBytes(UTF_8);
5757
resp.setStatus(HTTP_INTERNAL_ERROR);
5858

59-
resp.setHeader("Content-Type", JAVASCRIPT_UTF_8.toString());
59+
resp.setHeader("Content-Type", JSON_UTF_8.toString());
6060
resp.setHeader("Content-Length", String.valueOf(bytes.length));
6161

6262
resp.setContent(bytes);

java/server/src/org/openqa/selenium/remote/server/Passthrough.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.openqa.selenium.remote.server;
1919

20+
import static com.google.common.net.MediaType.JSON_UTF_8;
2021
import static java.nio.charset.StandardCharsets.UTF_8;
2122
import static org.openqa.selenium.remote.http.HttpMethod.POST;
2223

@@ -91,7 +92,7 @@ public void handle(HttpRequest req, HttpResponse resp) throws IOException {
9192
if (POST == req.getMethod()) {
9293
// We always transform to UTF-8 on the way up.
9394
String contentType = req.getHeader("Content-Type");
94-
contentType = contentType == null ? MediaType.JAVASCRIPT_UTF_8.toString() : contentType;
95+
contentType = contentType == null ? JSON_UTF_8.toString() : contentType;
9596

9697
MediaType type = MediaType.parse(contentType);
9798
connection.setRequestProperty("Content-Type", type.withCharset(UTF_8).toString());

0 commit comments

Comments
 (0)