Skip to content

Commit

Permalink
fix(okhttp): follow redirect for status codes 307 and 308 (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy authored Jun 1, 2024
1 parent 690d8e2 commit 2db0eda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- Bugfix: Fire death notifications for Doom modifier in Fortis Colosseum. (#474)
- Dev: Allow custom webhook handlers to use HTTP status code 307 and 308 to redirect requests. (#484)
- Dev: Add message source to chat notification metadata. (#476)

## 1.10.1
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/dinkplugin/message/DiscordMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ public DiscordMessageHandler(Gson gson, Client client, DrawManager drawManager,
}
return updatedChain.proceed(request);
})
.addInterceptor(chain -> {
Request request = chain.request();
Response response = chain.proceed(request);
String method = request.method();
// http status code 307 can be useful for custom webhook handlers to redirect requests as seen in https://github.com/pajlads/DinkPlugin/issues/482
// however, runelite uses okhttp 3.14.9, which does not follow RFC 7231 for code 307 (or RFC 7238 for code 308).
// while this was fixed in okhttp 4.6.0 (released on 2020-04-28), we need this interceptor to patch this issue for now
if (!method.equals("GET") && !method.equals("HEAD")) {
int code = response.code();
if (code == 307 || code == 308) {
String redirectUrl = response.header("Location");
if (redirectUrl != null) {
Request updatedRequest = request.newBuilder().url(redirectUrl).build();
return chain.proceed(updatedRequest);
}
}
}
return response;
})
.build();
}

Expand Down

0 comments on commit 2db0eda

Please sign in to comment.