Skip to content

Commit 04fea57

Browse files
authored
fix: add q factor to json in accept header (#186)
Express preference for ndjson via q weight
1 parent 5744fa2 commit 04fea57

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/client/src/client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class DelegatedRoutingV1HttpApiClient implements DelegatedRoutingV1HttpAp
108108
setMaxListeners(Infinity, timeoutSignal, signal)
109109
const onStart = defer()
110110
const onFinish = defer()
111+
let found = 0
111112

112113
void this.httpQueue.add(async () => {
113114
onStart.resolve()
@@ -123,7 +124,7 @@ export class DelegatedRoutingV1HttpApiClient implements DelegatedRoutingV1HttpAp
123124
this.#addFilterParams(url, options.filterAddrs, options.filterProtocols)
124125
const getOptions = {
125126
headers: {
126-
accept: 'application/x-ndjson, application/json'
127+
accept: 'application/x-ndjson, application/json;q=0.8'
127128
},
128129
signal
129130
}
@@ -171,13 +172,15 @@ export class DelegatedRoutingV1HttpApiClient implements DelegatedRoutingV1HttpAp
171172
for (const provider of providers) {
172173
const record = this.#conformToPeerSchema(provider)
173174
if (record != null) {
175+
found++
174176
yield record
175177
}
176178
}
177179
} else if (contentType.includes('application/x-ndjson')) {
178180
for await (const provider of ndjson(toIt(res.body))) {
179181
const record = this.#conformToPeerSchema(provider)
180182
if (record != null) {
183+
found++
181184
yield record
182185
}
183186
}
@@ -187,7 +190,7 @@ export class DelegatedRoutingV1HttpApiClient implements DelegatedRoutingV1HttpAp
187190
} finally {
188191
signal.clear()
189192
onFinish.resolve()
190-
this.log('getProviders finished: %c', cid)
193+
this.log('getProviders finished: %c, found %d providers', cid, found++)
191194
}
192195
}
193196

0 commit comments

Comments
 (0)