From 7684240c147cd1b938164db4d15234eb92c611c1 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 29 Feb 2024 13:54:25 +0100 Subject: [PATCH 1/2] gw: explain why we normalize trailing slash in dirs --- src/http-gateways/path-gateway.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/http-gateways/path-gateway.md b/src/http-gateways/path-gateway.md index 5de0e604..42e7ef38 100644 --- a/src/http-gateways/path-gateway.md +++ b/src/http-gateways/path-gateway.md @@ -520,10 +520,16 @@ This header is more widely used in [SUBDOMAIN_GATEWAY.md](./SUBDOMAIN_GATEWAY.md Gateway MUST return a redirect when a valid UnixFS directory was requested without the trailing `/`, for example: -- response for `https://ipfs.io/ipns/en.wikipedia-on-ipfs.org/wiki` - (no trailing slash) will be HTTP 301 redirect with +- response for UnixFS directory at `https://example.com/ipns/en.wikipedia-on-ipfs.org/wiki` + (no trailing slash) MUST be HTTP 301 redirect with `Location: /ipns/en.wikipedia-on-ipfs.org/wiki/` +This normalization is required for directory-based relative links +and security scopes such as Service Worker registrations to work correctly. +It also ensures the same behavior on path gateways (`https://example.com/ipfs/cid/` with trailing `/`) +and origin-isolated HTTP contexts `https://cid.ipfs.dweb.link` +or non-HTTP URLs like `ipfs://cid`, where empty path component is implicit `/`. + ### `X-Ipfs-Path` (response header) Used for HTTP caching and indicating the IPFS address of the data. From 55737437c8434bbfe2f959539ed3b9167dc3d3fb Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 29 Feb 2024 14:00:42 +0100 Subject: [PATCH 2/2] chore: lint --- src/http-gateways/path-gateway.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http-gateways/path-gateway.md b/src/http-gateways/path-gateway.md index 42e7ef38..5088728c 100644 --- a/src/http-gateways/path-gateway.md +++ b/src/http-gateways/path-gateway.md @@ -524,10 +524,10 @@ without the trailing `/`, for example: (no trailing slash) MUST be HTTP 301 redirect with `Location: /ipns/en.wikipedia-on-ipfs.org/wiki/` -This normalization is required for directory-based relative links +This normalization is required for directory-based relative links and security scopes such as Service Worker registrations to work correctly. It also ensures the same behavior on path gateways (`https://example.com/ipfs/cid/` with trailing `/`) -and origin-isolated HTTP contexts `https://cid.ipfs.dweb.link` +and origin-isolated HTTP contexts `https://cid.ipfs.dweb.link` or non-HTTP URLs like `ipfs://cid`, where empty path component is implicit `/`. ### `X-Ipfs-Path` (response header)