Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: expose url in channel interface #214

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/interface/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Channel<T extends Record<string, any>> extends Phantom<T> {
request<I extends Tuple<ServiceInvocation<UCAN.Capability, T>>>(
request: HTTPRequest<I>
): Await<HTTPResponse<InferServiceInvocations<I, T>>>
url?: URL
}

export interface RequestEncoder {
Expand Down
16 changes: 16 additions & 0 deletions packages/transport/test/https.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,19 @@ if (typeof globalThis.fetch === 'undefined') {
}
})
}

test('should expose url', async () => {
const channel = HTTP.open({
url: new URL('https://ucan.xyz/'),
fetch: async (url, init) => {
return {
ok: true,
status: 200,
url,
arrayBuffer: () => UTF8.encode('pong').buffer,
headers: new Map([['content-type', 'text/plain']]),
}
},
})
assert.equal(channel.url?.toString(), 'https://ucan.xyz/')
})