-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(rpc): Content-Type headers and IPNS record get/put #11067
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
Conversation
- set application/x-tar when outputting tar (default and --archive) - set application/gzip when compression is enabled (--compress) - update go-ipfs-cmds with Tar encoding type and RFC 6713 compliant MIME types (application/gzip instead of application/x-gzip)
set proper Content-Type headers for RPC endpoints that return binary data: - `dag export`: application/vnd.ipld.car - `block get`: application/vnd.ipld.raw - `diag profile`: application/zip - `get`: application/x-tar or application/gzip (already worked, migrated to new API) uses the new OctetStream encoding type and SetContentType() method from go-ipfs-cmds to specify custom MIME types for binary responses. refs: #2376
|
I feel we can fix multiple bugs here if we make it more generic. I'll prototype in this and cmds PR drafts. |
add dedicated command to retrieve raw signed IPNS records from the
routing system. returns protobuf-encoded IPNS record with Content-Type
`application/vnd.ipfs.ipns-record`.
this provides a more convenient alternative to `ipfs routing get /ipns/<name>`
which returns JSON with base64-encoded data. the raw output can be piped
directly to `ipfs name inspect`:
ipfs name get <name> | ipfs name inspect
spec: https://specs.ipfs.tech/ipns/ipns-record/
also renames test files to http_rpc_* for clarity.
document RPC Content-Type headers for binary responses and new ipfs name get command
replaces Extra-based Content-Type documentation with the new HelpText.HTTP.ResponseContentType field from go-ipfs-cmds. commands updated: - ipfs get: application/x-tar, or application/gzip when compress=true - ipfs dag export: application/vnd.ipld.car - ipfs block get: application/vnd.ipld.raw - ipfs name get: application/vnd.ipfs.ipns-record - ipfs diag profile: application/zip also removes SetResponseContentTypeDesc helper from extra.go as it is no longer needed.
adds `ipfs name put` to complement `ipfs name get`, allowing users to store IPNS records obtained from external sources without needing the private key. useful for backup, restore, and debugging workflows. the command validates records by default (signature, sequence number). use `--force` to bypass validation for testing how routing handles malformed or outdated records. also reorganizes test/cli files: - rename http_rpc_* -> rpc_* to match existing convention - merge name_get_put_test.go into name_test.go - add file header comments documenting test purposes
includes SetContentType() for dynamic Content-Type headers
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.
Went into small rabbit hole of leveraging this to fix multiple user-reported problems and I expanded the scope a bit to make this more useful:
- Content-Type headers for more RPC endpoints - added proper MIME types for
dag export,block get,name get, anddiag profilein addition toipfs get - New
ipfs name get|putcommands - low-level tools for backing up, restoring, and debugging IPNS records without needing the private key.name getalso ensures we have an RPC endpoint that returns the
IANA-registeredapplication/vnd.ipfs.ipns-recordmedia type (the existingrouting getreturns JSON with base64-encoded payload + cant be easily integrated with systems that expectapplication/vnd.ipfs.ipns-recordwithout exposing gateway port too, this solves that devops annoyance) - HTTP RPC API documentation - commands now can declare their Content-Type in
HelpText.HTTP.ResponseContentTypeso http-api-docs that generate https://docs.ipfs.tech/reference/kubo/rpc/ can pick it up (will merge ipfs/ipfs-docs#2248 once RC1 ships)
The underlying go-ipfs-cmds changes (ipfs/go-ipfs-cmds#311) add a generic OctetStream encoding type and SetContentType() function, so commands can set arbitrary Content-Type headers at runtime based on flags like --compress.
Merging as all changes are pretty shallow, low risk, backward-compatible and opt-in (+ we will switch to cmds release anyway once #11148 is merged).
Existing behavior is preserved for commands that don't explicitly set a Content-Type, and we have full test coverage for name get|put.
Adds correct
Content-Typeto some commands (e.g.ipfs get)ipfs get --compressgives incorrect Header #2376Also
name get|put