braid-text 0.2.91 → 0.2.93
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/index.js +24 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -52,6 +52,26 @@ function create_braid_text() {
|
|
|
52
52
|
// make a=local and b=remote (swap if not)
|
|
53
53
|
if (a instanceof URL) { let swap = a; a = b; b = swap }
|
|
54
54
|
|
|
55
|
+
// Extract content type for proper Accept (GET) vs Content-Type (PUT) usage
|
|
56
|
+
var content_type
|
|
57
|
+
var get_headers = {}
|
|
58
|
+
var put_headers = {}
|
|
59
|
+
if (options.headers) {
|
|
60
|
+
for (var [k, v] of Object.entries(options.headers)) {
|
|
61
|
+
var lk = k.toLowerCase()
|
|
62
|
+
if (lk === 'accept' || lk === 'content-type') {
|
|
63
|
+
content_type = v
|
|
64
|
+
} else {
|
|
65
|
+
get_headers[k] = v
|
|
66
|
+
put_headers[k] = v
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (content_type) {
|
|
71
|
+
get_headers['Accept'] = content_type
|
|
72
|
+
put_headers['Content-Type'] = content_type
|
|
73
|
+
}
|
|
74
|
+
|
|
55
75
|
var resource = (typeof a == 'string') ? await get_resource(a) : a
|
|
56
76
|
|
|
57
77
|
function extend_frontier(frontier, version, parents) {
|
|
@@ -125,7 +145,7 @@ function create_braid_text() {
|
|
|
125
145
|
signal: ac.signal,
|
|
126
146
|
method: "HEAD",
|
|
127
147
|
version,
|
|
128
|
-
headers:
|
|
148
|
+
headers: get_headers
|
|
129
149
|
})
|
|
130
150
|
if (!r.ok && r.status !== 309 && r.status !== 500)
|
|
131
151
|
throw new Error(`unexpected HEAD status: ${r.status}`)
|
|
@@ -178,13 +198,13 @@ function create_braid_text() {
|
|
|
178
198
|
update.signal = ac.signal
|
|
179
199
|
update.dont_retry = true
|
|
180
200
|
if (options.peer) update.peer = options.peer
|
|
181
|
-
|
|
201
|
+
update.headers = put_headers
|
|
182
202
|
var x = await braid_text.put(b, update)
|
|
183
203
|
if (x.ok) {
|
|
184
204
|
local_first_put()
|
|
185
205
|
extend_fork_point(update)
|
|
186
206
|
} else if (x.status === 401 || x.status === 403) {
|
|
187
|
-
options.on_unauthorized?.()
|
|
207
|
+
await options.on_unauthorized?.()
|
|
188
208
|
} else throw new Error('failed to PUT: ' + x.status)
|
|
189
209
|
}
|
|
190
210
|
|
|
@@ -262,7 +282,7 @@ function create_braid_text() {
|
|
|
262
282
|
var b_ops = {
|
|
263
283
|
signal: ac.signal,
|
|
264
284
|
dont_retry: true,
|
|
265
|
-
headers: { ...
|
|
285
|
+
headers: { ...get_headers, 'Merge-Type': 'dt', 'accept-encoding': 'updates(dt)' },
|
|
266
286
|
parents: resource.meta.fork_point,
|
|
267
287
|
peer: options.peer,
|
|
268
288
|
heartbeats: 120,
|