-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix: support https?://<dnsLink>.ipns.<gateway> urls #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self review
/** | ||
* For dnslinks see https://specs.ipfs.tech/http-gateways/subdomain-gateway/#host-request-header | ||
* DNSLink names include . which means they must be inlined into a single DNS label to provide unique origin and work with wildcard TLS certificates. | ||
*/ | ||
|
||
// DNS label can have up to 63 characters, consisting of alphanumeric | ||
// characters or hyphens -, but it must not start or end with a hyphen. | ||
const dnsLabelRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/ | ||
|
||
/** | ||
* Checks if label looks like inlined DNSLink. | ||
* (https://specs.ipfs.tech/http-gateways/subdomain-gateway/#host-request-header) | ||
*/ | ||
function isInlinedDnsLink (label: string): boolean { | ||
return dnsLabelRegex.test(label) && label.includes('-') && !label.includes('.') | ||
} | ||
|
||
/** | ||
* DNSLink label decoding | ||
* * Every standalone - is replaced with . | ||
* * Every remaining -- is replaced with - | ||
* | ||
* @example en-wikipedia--on--ipfs-org.ipns.example.net -> example.net/ipns/en.wikipedia-on-ipfs.org | ||
*/ | ||
function dnsLinkLabelDecoder (linkLabel: string): string { | ||
return linkLabel.replace(/--/g, '%').replace(/-/g, '.').replace(/%/g, '-') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cid = resolveResult?.cid | ||
resolvedPath = resolveResult?.path | ||
log.trace('resolved %s to %c', cidOrPeerIdOrDnsLink, cid) | ||
log.trace('resolved %s to %c', decodedDnsLinkLabel, cid) | ||
ipnsCache.set(cidOrPeerIdOrDnsLink, resolveResult, 60 * 1000 * 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
caching the originally given dnsLink
## @helia/verified-fetch [1.1.2](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-1.1.1...@helia/verified-fetch-1.1.2) (2024-03-11) ### Bug Fixes * support https?://<dnsLink>.ipns.<gateway> urls ([#16](#16)) ([0ece19a](0ece19a))
🎉 This PR is included in version 1.1.2 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 1.5.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 1.0.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
Title
Feat: Support
https?://<dnsLink>.ipns.<domain>
URLsDescription
helia-http-gateway and helia-service-worker-gateway can now pass any urls they receive directly to @helia/verfied-fetch without having to do any URL parsing.
Notes & open questions
Change checklist