Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Trustless gateway broker should use subdomain gateway to prevent 301 roundtrips #347

Closed
2color opened this issue Dec 14, 2023 · 2 comments · Fixed by #374
Closed

Trustless gateway broker should use subdomain gateway to prevent 301 roundtrips #347

2color opened this issue Dec 14, 2023 · 2 comments · Fixed by #374

Comments

@2color
Copy link
Member

2color commented Dec 14, 2023

Background

The current Trustless gateway broker uses path resolution by default and has 4 subdomain gateways defined in the defaults. This leads to it getting 301s for most requests because subdomain gateways redirect from path requests to the subdomain. For example:

https://cf-ipfs.com/ipfs/QmTUAobz6YU1Ej5dTibodQPNtKk2TNnQek5TXHv13Dk2zq?format=raw -> 301 https://bafybeicmg6dvbhclp6sctn7nfhaex64x7fuw552cufodvjt56zispmvhoy.ipfs.cf-ipfs.com/

https://dweb.link/ipfs/QmRCKiUi5g4w4QBpyNkTiczrcTiwQtGK9DHLnncxXdfD7c?format=raw -> 301 https://bafybeibkodyc2gs43vfj4cond2tw2kb4qsuik72bmeij5dpvwiyvsfasl4.ipfs.dweb.link/?format=raw

Since 301s are permanent, the browser will cache these after the initial request, however, this results in an additional round trip per CID.

const gwUrl = this.url
gwUrl.pathname = `/ipfs/${cid.toString()}`
// necessary as not every gateway supports dag-cbor, but every should support
// sending raw block as-is
gwUrl.search = '?format=raw'

Suggested solutions

@SgtPooki
Copy link
Member

I think we should use attempt to use subdomain gateways, and convert any cidv0 to v1

@2color
Copy link
Member Author

2color commented Jan 12, 2024

One thing to consider is that not all gateways support subdomain resolution. If we only support subdomain gateways we're limiting users because they are less common. If we support both, it comes with the added complexity (which seems fine).

I realise that subdomain resolution is important for origin isolation, but only relevant for loading sites directly from the trustless gateway.

SgtPooki added a commit that referenced this issue Jan 30, 2024
* fix: use path gateway to avoid redirects

fixes #347

* Update packages/block-brokers/src/trustless-gateway/index.ts

Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>

---------

Co-authored-by: Daniel N <2color@users.noreply.github.com>
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants