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:
Telesphoreo 2022-05-30 02:44:29 -05:00 committed by GitHub
commit 8bef589b7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 0 deletions

View file

@ -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();

View file

@ -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());
}

View file

@ -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<>();

View file

@ -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());
}