Skip to content

Commit 0c56dd3

Browse files
authored
Merge pull request #27 from Sukikui/fixture/get-endpoint
Impose `GET` as API endpoint
2 parents 2ad73d7 + 79bbbce commit 0c56dd3

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/client/java/fr/sukikui/playercoordsapi/PlayerCoordsAPIClient.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,19 @@ private void cleanupServerResources() {
164164
}
165165

166166
private void handleCoordsRequest(HttpExchange exchange) throws IOException {
167-
// Handle CORS preflight request
168-
if (exchange.getRequestMethod().equalsIgnoreCase("OPTIONS")) {
167+
String method = exchange.getRequestMethod();
168+
169+
if (method.equalsIgnoreCase("OPTIONS")) {
169170
sendResponse(exchange, 204, null);
170171
return;
171172
}
172173

174+
if (!method.equalsIgnoreCase("GET")) {
175+
exchange.getResponseHeaders().set("Allow", "GET, OPTIONS");
176+
sendResponse(exchange, 405, "{\"error\": \"Method not allowed\"}");
177+
return;
178+
}
179+
173180
// Check if the client is allowed to access (only localhost)
174181
InetAddress remoteAddress = exchange.getRemoteAddress().getAddress();
175182
if (remoteAddress == null || !remoteAddress.isLoopbackAddress()) {

0 commit comments

Comments
 (0)