@cappitolian/http-local-server-swifter 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,17 +13,15 @@ import com.getcapacitor.JSObject;
13
13
  import com.getcapacitor.Plugin;
14
14
  import com.getcapacitor.PluginCall;
15
15
 
16
- import org.json.JSONException;
17
16
  import org.json.JSONObject;
18
17
 
19
18
  import java.io.IOException;
20
- import java.util.HashMap;>
19
+ import java.util.HashMap;
21
20
  import java.util.Map;
22
21
  import java.util.UUID;
23
22
  import java.util.concurrent.CompletableFuture;
24
23
  import java.util.concurrent.ConcurrentHashMap;
25
24
  import java.util.concurrent.TimeUnit;
26
- import java.util.concurrent.TimeoutException;
27
25
 
28
26
  import fi.iki.elonen.NanoHTTPD;
29
27
 
@@ -40,7 +38,7 @@ public class HttpLocalServerSwifter {
40
38
  private static final int RATE_LIMIT = 30; // requests
41
39
  private static final long RATE_WINDOW_MS = 60_000; // per minute
42
40
 
43
- // Private final properties
41
+ // Private final properties
44
42
  private final Plugin plugin;
45
43
  private final int port;
46
44
  private final int timeoutSeconds;
@@ -48,7 +46,7 @@ public class HttpLocalServerSwifter {
48
46
  // Private properties
49
47
  private LocalNanoServer server;
50
48
 
51
- private boolean isRateLimited(String ip) {
49
+ private static boolean isRateLimited(String ip) {
52
50
  long now = System.currentTimeMillis();
53
51
 
54
52
  rateLimitMap.compute(ip, (key, timestamps) -> {
@@ -101,7 +99,7 @@ public class HttpLocalServerSwifter {
101
99
  Log.i(TAG, "Server started at " + localIp + ":" + port);
102
100
  } catch (IOException e) {
103
101
  Log.e(TAG, "Failed to start server", e);
104
-
102
+
105
103
  call.reject("Failed to start server: " + e.getMessage());
106
104
  }
107
105
  }
@@ -289,7 +287,7 @@ public class HttpLocalServerSwifter {
289
287
  Response response = newFixedLengthResponse(Response.Status.NO_CONTENT, "text/plain", "");
290
288
 
291
289
  addCorsHeaders(response);
292
-
290
+
293
291
  return response;
294
292
  }
295
293
 
@@ -297,7 +295,7 @@ public class HttpLocalServerSwifter {
297
295
  response.addHeader("Access-Control-Allow-Origin", "*");
298
296
  response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS");
299
297
  response.addHeader("Access-Control-Allow-Headers",
300
- "Origin, Content-Type, Accept, Authorization, X-Requested-With");
298
+ "Origin, Content-Type, Accept, Authorization, X-Requested-With, x-api-key");
301
299
  response.addHeader("Access-Control-Max-Age", "3600");
302
300
  // Prevents TCP connection reuse. NanoHTTPD does not handle keep-alive
303
301
  // correctly under rapid sequential requests, causing ERR_INVALID_HTTP_RESPONSE.
@@ -186,7 +186,7 @@ public protocol HttpLocalServerSwifterDelegate: AnyObject {
186
186
  "Content-Type": "application/json",
187
187
  "Access-Control-Allow-Origin": "*",
188
188
  "Access-Control-Allow-Methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS",
189
- "Access-Control-Allow-Headers": "Origin, Content-Type, Accept, Authorization, X-Requested-With"
189
+ "Access-Control-Allow-Headers": "Origin, Content-Type, Accept, Authorization, X-Requested-With, x-api-key"
190
190
  ]
191
191
 
192
192
  if
@@ -210,7 +210,7 @@ public protocol HttpLocalServerSwifterDelegate: AnyObject {
210
210
  return .raw(204, "No Content", [
211
211
  "Access-Control-Allow-Origin": "*",
212
212
  "Access-Control-Allow-Methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS",
213
- "Access-Control-Allow-Headers": "Origin, Content-Type, Accept, Authorization, X-Requested-With",
213
+ "Access-Control-Allow-Headers": "Origin, Content-Type, Accept, Authorization, X-Requested-With, x-api-key",
214
214
  "Access-Control-Max-Age": "86400"
215
215
  ], nil)
216
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappitolian/http-local-server-swifter",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "Runs a local HTTP server on your device, accessible over LAN. Supports connect, disconnect, GET, and POST methods with IP and port discovery.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",