@cantoo/capacitor-http-server
Advanced tools
@@ -114,4 +114,11 @@ package com.cantooscribe.httpserver | ||
| val requestedPort = call.getInt("port") ?: 0 | ||
| maxBodyBytes = call.getLong("maxBodyBytes") ?: DEFAULT_MAX_BODY | ||
| fileBodyThresholdBytes = call.getLong("fileBodyThresholdBytes") ?: DEFAULT_FILE_THRESHOLD | ||
| // PluginCall.getLong requires the underlying JSON value to be a | ||
| // java.lang.Long, but Android's JSONObject stores JS numbers that | ||
| // fit in int range as java.lang.Integer. Routing through getDouble | ||
| // handles Integer/Long/Double uniformly and avoids silently | ||
| // ignoring user-supplied values like `{ maxBodyBytes: 10_000_000 }`. | ||
| maxBodyBytes = call.getDouble("maxBodyBytes")?.toLong()?.takeIf { it > 0 } | ||
| ?: DEFAULT_MAX_BODY | ||
| fileBodyThresholdBytes = call.getDouble("fileBodyThresholdBytes")?.toLong()?.takeIf { it > 0 } | ||
| ?: DEFAULT_FILE_THRESHOLD | ||
@@ -118,0 +125,0 @@ val androidOpts = call.getObject("android") |
@@ -303,3 +303,13 @@ import Foundation | ||
| // guard mainly rejects oversized payloads early. | ||
| if Int(request.contentLength) > self.maxBodyBytes { | ||
| // | ||
| // GCDWebServerRequest.contentLength is NSUInteger and is imported in | ||
| // Swift as UInt. GCDWebServer sets it to NSUIntegerMax (= UInt.max) | ||
| // when the request has no Content-Length header (e.g. every GET), so | ||
| // we must NOT convert to Int here — Int(UInt.max) traps with | ||
| // "Not enough bits to represent the passed value". Compare in UInt | ||
| // and treat the sentinel as a zero-length body. | ||
| let rawContentLength = request.contentLength | ||
| let declaredBodyLength: UInt = rawContentLength == UInt.max ? 0 : rawContentLength | ||
| let limit = self.maxBodyBytes >= 0 ? UInt(self.maxBodyBytes) : 0 | ||
| if declaredBodyLength > limit { | ||
| if let r = GCDWebServerDataResponse(text: "Payload exceeds maxBodyBytes") { | ||
@@ -306,0 +316,0 @@ r.statusCode = 413 |
+1
-1
| { | ||
| "name": "@cantoo/capacitor-http-server", | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", | ||
| "description": "Capacitor plugin exposing a local HTTP server on iOS and Android with routing delegated to JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "dist/plugin.cjs.js", |
111230
1.03%