@tilua-types/sunc 11.2.0 → 11.2.1

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.
package/README.md CHANGED
@@ -247,7 +247,7 @@ these runs only under an executor.
247
247
  <!-- compatibility:start -->
248
248
  ## Compatibility
249
249
 
250
- `@tilua-types/sunc@11.2.0` works with these tilua packages. *Released with* is the
250
+ `@tilua-types/sunc@11.2.1` works with these tilua packages. *Released with* is the
251
251
  version it was built and tested against.
252
252
 
253
253
  | Package | Range | Released with | |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tilua-types/sunc",
3
- "version": "11.2.0",
3
+ "version": "11.2.1",
4
4
  "description": "The script-executor environment as tilua types: sUNC and UNC names (getgenv, writefile, hookfunction, Drawing, ...)",
5
5
  "license": "ISC",
6
6
  "files": [
package/runtime/sunc.luau CHANGED
@@ -267,12 +267,27 @@ local function built(options)
267
267
  return copy
268
268
  end
269
269
 
270
+ -- Some executors (Solara) fail with "Can't parse JSON" when `Headers` is an
271
+ -- empty table, as they send it on as JSON `[]`: one with no headers is sent
272
+ -- without the field.
273
+ local function withoutEmptyHeaders(options)
274
+ if type(options) ~= "table" or type(options.Headers) ~= "table" or next(options.Headers) ~= nil then
275
+ return options
276
+ end
277
+ local copy = {}
278
+ for key, value in pairs(options) do
279
+ copy[key] = value
280
+ end
281
+ copy.Headers = nil
282
+ return copy
283
+ end
284
+
270
285
  __NAME__.http = {
271
286
  request = send and function(options)
272
287
  if type(options) == "function" then
273
- return send(built(options(types)))
288
+ return send(withoutEmptyHeaders(built(options(types))))
274
289
  end
275
- return send(options)
290
+ return send(withoutEmptyHeaders(options))
276
291
  end or nil,
277
292
  }
278
293
 
@@ -1077,7 +1092,8 @@ local function requestOf(state)
1077
1092
  return {
1078
1093
  Url = urlOf(state),
1079
1094
  Method = state.method,
1080
- Headers = headers,
1095
+ -- Left out when there are none: see withoutEmptyHeaders
1096
+ Headers = next(headers) ~= nil and headers or nil,
1081
1097
  Body = state.body,
1082
1098
  Cookies = next(state.cookies) ~= nil and copyOf(state.cookies) or nil,
1083
1099
  }
@@ -1125,6 +1141,7 @@ local function perform(state)
1125
1141
  if decision == "use" then
1126
1142
  return fromEntry(entry, true)
1127
1143
  elseif decision == "validate" then
1144
+ options.Headers = options.Headers or {}
1128
1145
  if entry.etag and requestHeaders["if-none-match"] == nil then
1129
1146
  options.Headers["If-None-Match"] = entry.etag
1130
1147
  end