Skip to content

Commit

Permalink
HOTFIX for last commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
e3ndr committed Nov 15, 2021
1 parent 0eb8405 commit d3accd2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/co/casterlabs/katana/http/HttpRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

@Getter
public class HttpRouter implements HttpListener {
private static String ALLOWED_METHODS;

private MultiValuedMap<String, HttpServlet> hostnames = new ArrayListValuedHashMap<>();
private List<Reason> failReasons = new ArrayList<>();
private boolean keepErrorStatus = true;
Expand All @@ -55,6 +57,13 @@ public class HttpRouter implements HttpListener {
// Unless the response is chunked, this value will effectively be
// the maximum buffer size.
IOUtil.DEFAULT_BUFFER_SIZE = (int) DataSize.MEGABYTE.toBytes(10);

List<String> methods = new ArrayList<>();
for (HttpMethod method : HttpMethod.values()) {
methods.add(method.name());
}

ALLOWED_METHODS = String.join(", ", methods);
}

@SneakyThrows
Expand Down Expand Up @@ -179,6 +188,7 @@ public void stop() {
String referer = split[1].split("/")[0]; // Strip protocol and uri

response.putHeader("Access-Control-Allow-Origin", protocol + "://" + referer);
response.putHeader("Access-Control-Allow-Methods", ALLOWED_METHODS);
response.putHeader("Access-Control-Allow-Headers", "Authorization, *");
this.logger.debug("Set CORS headers for %s", referer);
}
Expand All @@ -201,7 +211,8 @@ public void stop() {
for (HttpServlet servlet : servlets) {
if (Util.regexContains(servlet.getAllowedHosts(), referer)) {
response.putHeader("Access-Control-Allow-Origin", protocol + "://" + referer);
response.putHeader("Access-Control-Allow-Method", session.getMethod().name());
response.putHeader("Access-Control-Allow-Methods", ALLOWED_METHODS);
response.putHeader("Access-Control-Allow-Headers", "Authorization, *");
this.logger.debug("Set CORS header for %s", referer);
break;
}
Expand Down

0 comments on commit d3accd2

Please sign in to comment.