Skip to content

Commit

Permalink
Use BodyInputStream instead of maxRequestSize
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Mar 22, 2024
1 parent 94ffce9 commit e43510c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ public static void onOfflineUpdateRequest(Context ctx) {
public static void onGeneralSettingsRequest(Context ctx) {
NetworkConfig config;
try {
config = kObjectMapper.readValue(ctx.body(), NetworkConfig.class);
config = kObjectMapper.readValue(ctx.bodyInputStream(), NetworkConfig.class);

ctx.status(200);
ctx.result("Successfully saved general settings");
logger.info("Successfully saved general settings");
} catch (JsonProcessingException e) {
} catch (IOException e) {
// If the settings can't be parsed, use the default network settings
config = new NetworkConfig();

Expand All @@ -381,7 +381,7 @@ public static class UICameraSettingsRequest {

public static void onCameraSettingsRequest(Context ctx) {
try {
var data = kObjectMapper.readTree(ctx.body());
var data = kObjectMapper.readTree(ctx.bodyInputStream());

int index = data.get("index").asInt();
var settings =
Expand Down Expand Up @@ -451,7 +451,7 @@ public static void onCalibrationEndRequest(Context ctx) {
int index;

try {
index = kObjectMapper.readTree(ctx.body()).get("index").asInt();
index = kObjectMapper.readTree(ctx.bodyInputStream()).get("index").asInt();

var calData = VisionModuleManager.getInstance().getModule(index).endCalibration();
if (calData == null) {
Expand Down Expand Up @@ -482,7 +482,7 @@ public static void onCalibrationEndRequest(Context ctx) {
}

public static void onCalibDBCalibrationImportRequest(Context ctx) {
var data = ctx.body();
var data = ctx.bodyInputStream();

try {
var actualObj = kObjectMapper.readTree(data);
Expand All @@ -503,7 +503,7 @@ public static void onCalibDBCalibrationImportRequest(Context ctx) {
ctx.status(200);
ctx.result("Calibration imported successfully from CalibDB data!");
logger.info("Calibration imported successfully from CalibDB data!");
} catch (JsonProcessingException e) {
} catch (IOException e) {
ctx.status(400);
ctx.result(
"The Provided CalibDB data is malformed and cannot be parsed for the required fields.");
Expand All @@ -515,7 +515,7 @@ public static void onCalibDBCalibrationImportRequest(Context ctx) {

public static void onDataCalibrationImportRequest(Context ctx) {
try {
var data = kObjectMapper.readTree(ctx.body());
var data = kObjectMapper.readTree(ctx.bodyInputStream());

int cameraIndex = data.get("cameraIndex").asInt();
var coeffs =
Expand Down Expand Up @@ -557,7 +557,7 @@ public static void onDeviceRestartRequest(Context ctx) {

public static void onCameraNicknameChangeRequest(Context ctx) {
try {
var data = kObjectMapper.readTree(ctx.body());
var data = kObjectMapper.readTree(ctx.bodyInputStream());

String name = data.get("name").asText();
int idx = data.get("cameraIndex").asInt();
Expand Down
10 changes: 6 additions & 4 deletions photon-server/src/main/java/org/photonvision/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ private static void start(int port) {
corsContainer.add(CorsPluginConfig::anyHost);
});

// Increase the upload size limit (arbitrary, but need to be able to deal with large
// calibration JSONs)
javalinConfig.http.maxRequestSize = (long) (50 * 1e6);

javalinConfig.requestLogger.http(
(ctx, ms) -> {
StringJoiner joiner =
Expand All @@ -77,6 +73,12 @@ private static void start(int port) {
.add(ctx.req().getMethod())
.add("from endpoint")
.add(ctx.path())
.add("of req size")
.add(Integer.toString(ctx.contentLength()))
.add("bytes & type")
.add(ctx.contentType())
.add("with return code")
.add(Integer.toString(ctx.res().getStatus()))
.add("for host")
.add(ctx.req().getRemoteHost())
.add("in")
Expand Down

0 comments on commit e43510c

Please sign in to comment.