Skip to content

Commit

Permalink
Use long type for handling request body size. (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekharkunov authored Jan 11, 2024
1 parent 9ea34dd commit 99e0825
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions server/src/main/java/com/defold/extender/ExtenderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public class ExtenderController {
private final RemoteEngineBuilder remoteEngineBuilder;
private final boolean remoteBuilderEnabled;
private final String[] remoteBuilderPlatforms;
private static int maxPackageSize = 1024* 1024*1024;
private static long maxPackageSize = 1024*1024*1024;
private File jobResultLocation;

private static final String DM_DEBUG_JOB_FOLDER = System.getenv("DM_DEBUG_JOB_FOLDER");
private static final String DM_DEBUG_KEEP_JOB_FOLDER = System.getenv("DM_DEBUG_KEEP_JOB_FOLDER");
private static final String DM_DEBUG_JOB_UPLOAD = System.getenv("DM_DEBUG_JOB_UPLOAD");

static private int parseSizeFromString(String size) {
static private long parseSizeFromString(String size) {
size = size.toLowerCase();
int multiplier = 1;
if (size.endsWith("mb")) {
Expand All @@ -82,7 +82,7 @@ else if (size.endsWith("gb")) {
multiplier = 1024*1024;
}

return Integer.parseInt(size) * multiplier;
return Long.parseLong(size) * multiplier;
}

@Autowired
Expand All @@ -108,7 +108,7 @@ public ExtenderController(DefoldSdkService defoldSdkService,
this.remoteEngineBuilder = remoteEngineBuilder;
this.remoteBuilderEnabled = remoteBuilderEnabled;
this.remoteBuilderPlatforms = remoteBuilderPlatforms;
this.maxPackageSize = parseSizeFromString(maxPackageSize);
ExtenderController.maxPackageSize = parseSizeFromString(maxPackageSize);
this.jobResultLocation = new File(jobResultLocation);
this.jobResultLocation.mkdirs();

Expand Down Expand Up @@ -454,8 +454,8 @@ static void validateFilename(String path) throws ExtenderException {
}

static void receiveUpload(MultipartHttpServletRequest request, File uploadDirectory) throws IOException, FileUploadException, ExtenderException {
if (request.getContentLength() > ExtenderController.maxPackageSize ) {
String msg = String.format("Build request is too large: %d bytes. Max allowed size is %d bytes.", request.getContentLength(), ExtenderController.maxPackageSize);
if (request.getContentLengthLong() > ExtenderController.maxPackageSize ) {
String msg = String.format("Build request is too large: %d bytes. Max allowed size is %d bytes.", request.getContentLengthLong(), ExtenderController.maxPackageSize);
LOGGER.error(msg);
throw new ExtenderException(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void addMetric(final String name, final long value, String... tags) {

public void measureReceivedRequest(final HttpServletRequest request) {
addMetric("job.receive", timer.start());
addMetric("job.requestSize", request.getContentLength());
addMetric("job.requestSize", request.getContentLengthLong());
}

public void measureSdkDownload(String sdk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void setUp() {
@Test
public void measureReceivedRequest() {
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getContentLength()).thenReturn(500);
when(request.getContentLengthLong()).thenReturn(500);
metricsWriter.measureReceivedRequest(request);
Expand Down

0 comments on commit 99e0825

Please sign in to comment.