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