This document defines conventions for how applications can identify an available IPFS Gateway, and how IPFS Gateway implementations can signal their own endpoint to client applications.
There are two ways of hinting the user-preferred gateway URL:
IPFS_GATEWAY environment variablegateway file at a well-known pathApplications SHOULD evaluate these hints in order and stop on the first match:
IPFS_GATEWAY environment variable is setgateway file is present at one of the well-known filesystem pathsIf a hint is present but its value is not a valid URL, applications SHOULD report an error instead of silently falling back to the next hint.
If no valid hint is found, gateway selection is unconfigured. Applications SHOULD NOT fall back to a hard-coded non-localhost gateway (see Security below).
IPFS_GATEWAY Environment VariableWhen the IPFS_GATEWAY environment variable is set, the value SHOULD be interpreted
as the URL of the IPFS Gateway to use. The value holds a single URL, following
the same rules as the first line of the gateway file.
Applications SHOULD give this variable precedence over gateway URLs from internal application configuration. Explicit per-invocation user input, such as a command-line argument, MAY take precedence over this variable.
gateway Configuration FileClient application SHOULD check if file is present at specific filesystem paths, in order:
IPFS_PATH is set, try $IPFS_PATH/gatewayHOME is set, try $HOME/.ipfs/gateway (the default IPFS_PATH location)$XDG_CONFIG_HOME/ipfs/gateway (only if XDG_CONFIG_HOME is set)$HOME/.config/ipfs/gateway (default XDG location)/etc/ipfs/gateway (system-wide)%LOCALAPPDATA%/ipfs/gateway (local user)%APPDATA%/ipfs/gateway (roaming user)%PROGRAMDATA%/ipfs/gateway (system-wide)$HOME/Library/Application Support/ipfs/gateway (user)/Library/Application Support/ipfs/gateway (system-wide)When gateway file is present, the file contents MUST be interpreted as an
ASCII text file with one URL per line (separated by \n or \r\n).
The first line MUST be a valid http:// or https:// URL consisting only of
a scheme, host, and optional port, with no path, query, or fragment
(e.g., http://127.0.0.1:8080). The gateway at this URL MUST support
[trustless-gateway], SHOULD support [path-gateway] when deserialized
responses are required, and SHOULD support [subdomain-gateway] when Origin
isolation is required.
Implementations MAY support additional lines for gateway pools or failover. Additional lines, when present, MUST follow the same URL rules, and empty lines MUST be ignored. Implementations that do not support multiple URLs SHOULD read only the first line and ignore the rest of the file.
Applications that integrate IPFS support via HTTP gateways:
https://, or localhost (e.g., http://127.0.0.1:8080), which
browsers treat as potentially trustworthy.http://{cid}.ipfs.localhost:8080), so each content root is loaded
from its own origin.Applications SHOULD NOT default to public gateways (see Security above). Instead, applications SHOULD suggest to the user how to run a local node.
Implementers SHOULD test against implementations mentioned in ipip-0280 as the baseline for making decisions around maximizing interoperability.
Copyright and related rights waived via CC0.
We gratefully acknowledge the following individuals for their valuable contributions, ranging from minor suggestions to major insights, which have shaped and improved this specification.