mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2024-12-22 01:07:37 +00:00
Set Content-Type header to application/json for JSON endpoints (closes #6)
This commit is contained in:
parent
41a2475e3d
commit
5a0ae8746c
@ -9,6 +9,7 @@ import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.request.AbstractServlet;
|
||||
import dev.plex.request.GetMapping;
|
||||
import dev.plex.request.MappingHeaders;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@ -24,6 +25,7 @@ public class AdminsEndpoint extends AbstractServlet
|
||||
private static final String TITLE = "Admins - Plex HTTPD";
|
||||
|
||||
@GetMapping(endpoint = "/api/admins/")
|
||||
@MappingHeaders(headers = "content-type;application/json")
|
||||
public String getAdmins(HttpServletRequest request, HttpServletResponse response)
|
||||
{
|
||||
String ipAddress = request.getRemoteAddr();
|
||||
|
@ -48,6 +48,8 @@ public class IndefBansEndpoint extends AbstractServlet
|
||||
return indefbansHTML("Not enough permissions to view this page.");
|
||||
}
|
||||
}
|
||||
|
||||
response.setHeader("content-type", "application/json");
|
||||
return new GsonBuilder().setPrettyPrinting().create().toJson(Plex.get().getPunishmentManager().getIndefiniteBans().stream().toList());
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package dev.plex.request.impl;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import dev.plex.request.AbstractServlet;
|
||||
import dev.plex.request.GetMapping;
|
||||
import dev.plex.request.MappingHeaders;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -14,6 +15,7 @@ import org.bukkit.entity.Player;
|
||||
public class ListEndpoint extends AbstractServlet
|
||||
{
|
||||
@GetMapping(endpoint = "/api/list/")
|
||||
@MappingHeaders(headers = "content-type;application/json")
|
||||
public String getOnlinePlayers(HttpServletRequest request, HttpServletResponse response)
|
||||
{
|
||||
List<String> players = new ArrayList<>();
|
||||
|
@ -80,6 +80,8 @@ public class PunishmentsEndpoint extends AbstractServlet
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().peek(punishment -> punishment.setIp("")).toList());
|
||||
}
|
||||
}
|
||||
|
||||
response.setHeader("content-type", "application/json");
|
||||
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).setPrettyPrinting().create().toJson(punishedPlayer.getPunishments().stream().toList());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user