Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce an RFC valid Accept value for remote dev requests #22621

Merged
merged 1 commit into from
Jan 5, 2022
Merged
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 @@ -32,6 +32,16 @@ public class HttpRemoteDevClient implements RemoteDevClient {

private final Logger log = Logger.getLogger(HttpRemoteDevClient.class);

/**
* The default Accept header defined in sun.net.www.protocol.http.HttpURLConnection is invalid and
* does not respect the RFC so we override it with a valid value.
* RESTEasy is quite strict regarding the RFC and throws an error.
* Note that this is just the default HttpURLConnection header value made valid.
* See https://bugs.openjdk.java.net/browse/JDK-8163921 and https://bugs.openjdk.java.net/browse/JDK-8177439
* and https://github.com/quarkusio/quarkus/issues/20904
*/
private static final String DEFAULT_ACCEPT = "text/html, image/gif, image/jpeg; q=0.2, */*; q=0.2";

private final String url;
private final String password;
private final long reconnectTimeoutMillis;
Expand Down Expand Up @@ -95,6 +105,7 @@ private void sendData(Map.Entry<String, byte[]> entry, String session) throws IO
connection = (HttpURLConnection) new URL(url + "/" + entry.getKey()).openConnection();
connection.setRequestMethod("PUT");
connection.setDoOutput(true);
connection.setRequestProperty(HttpHeaders.ACCEPT.toString(), DEFAULT_ACCEPT);
connection.addRequestProperty(HttpHeaders.CONTENT_TYPE.toString(), RemoteSyncHandler.APPLICATION_QUARKUS);
connection.addRequestProperty(RemoteSyncHandler.QUARKUS_SESSION_COUNT, Integer.toString(currentSessionCounter));

Expand All @@ -120,6 +131,7 @@ private String doConnect(RemoteDevState initialState, Function<Set<String>, Map<

HttpURLConnection connection = (HttpURLConnection) new URL(url + RemoteSyncHandler.CONNECT)
.openConnection();
connection.setRequestProperty(HttpHeaders.ACCEPT.toString(), DEFAULT_ACCEPT);
connection.addRequestProperty(HttpHeaders.CONTENT_TYPE.toString(), RemoteSyncHandler.APPLICATION_QUARKUS);
//for the connection we use the hash of the password and the contents
//this can be replayed, but only with the same contents, and this does not affect the server
Expand Down Expand Up @@ -195,6 +207,7 @@ public void run() {
//long polling request
//we always send the current problem state
connection = (HttpURLConnection) devUrl.openConnection();
connection.setRequestProperty(HttpHeaders.ACCEPT.toString(), DEFAULT_ACCEPT);
connection.setRequestMethod("POST");
connection.addRequestProperty(HttpHeaders.CONTENT_TYPE.toString(), RemoteSyncHandler.APPLICATION_QUARKUS);
connection.addRequestProperty(RemoteSyncHandler.QUARKUS_SESSION_COUNT,
Expand Down Expand Up @@ -223,6 +236,7 @@ public void run() {
}
log.info("deleting " + file);
connection = (HttpURLConnection) new URL(url + "/" + file).openConnection();
connection.setRequestProperty(HttpHeaders.ACCEPT.toString(), DEFAULT_ACCEPT);
connection.setRequestMethod("DELETE");
connection.addRequestProperty(HttpHeaders.CONTENT_TYPE.toString(),
RemoteSyncHandler.APPLICATION_QUARKUS);
Expand Down Expand Up @@ -270,6 +284,7 @@ private String waitForRestart(RemoteDevState initialState,
while (System.currentTimeMillis() < timeout) {
try {
HttpURLConnection connection = (HttpURLConnection) probeUrl.openConnection();
connection.setRequestProperty(HttpHeaders.ACCEPT.toString(), DEFAULT_ACCEPT);
connection.setRequestMethod("POST");
connection.addRequestProperty(HttpHeaders.CONTENT_TYPE.toString(), RemoteSyncHandler.APPLICATION_QUARKUS);
IoUtil.readBytes(connection.getInputStream());
Expand Down