mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
Some checks failed
CodeQL / codeql (push) Has been cancelled
Docker Check / lint (push) Has been cancelled
Docker Check / build (push) Has been cancelled
Gateway Conformance / gateway-conformance (push) Has been cancelled
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Has been cancelled
Go Build / go-build (push) Has been cancelled
Go Check / go-check (push) Has been cancelled
Go Lint / go-lint (push) Has been cancelled
Go Test / unit-tests (push) Has been cancelled
Go Test / cli-tests (push) Has been cancelled
Go Test / example-tests (push) Has been cancelled
Interop / interop-prep (push) Has been cancelled
Sharness / sharness-test (push) Has been cancelled
Spell Check / spellcheck (push) Has been cancelled
Interop / helia-interop (push) Has been cancelled
Interop / ipfs-webui (push) Has been cancelled
* fix http header when compress enabled for get command Closes #2376 * fix(rpc): set Content-Type for ipfs get based on output format - 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) * test(rpc): add Content-Type header tests for ipfs get * feat(rpc): add Content-Type headers for binary responses 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: https://github.com/ipfs/kubo/issues/2376 * feat(rpc): add `ipfs name get` command for IPNS record retrieval 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/ * feat(rpc): add `ipfs name put` command for IPNS record storage 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 * chore(deps): update go-ipfs-cmds to latest master includes SetContentType() for dynamic Content-Type headers --------- Co-authored-by: Marcin Rataj <lidel@lidel.org>
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/ipfs/kubo/test/cli/harness"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestRPCGetContentType verifies that the RPC endpoint for `ipfs get` returns
|
|
// the correct Content-Type header based on output format options.
|
|
//
|
|
// Output formats and expected Content-Type:
|
|
// - default (no flags): tar (transport format) -> application/x-tar
|
|
// - --archive: tar archive -> application/x-tar
|
|
// - --compress: gzip -> application/gzip
|
|
// - --archive --compress: tar.gz -> application/gzip
|
|
//
|
|
// Fixes: https://github.com/ipfs/kubo/issues/2376
|
|
func TestRPCGetContentType(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
node := harness.NewT(t).NewNode().Init()
|
|
node.StartDaemon("--offline")
|
|
|
|
// add test content
|
|
cid := node.IPFSAddStr("test content for Content-Type header verification")
|
|
|
|
tests := []struct {
|
|
name string
|
|
query string
|
|
expectedContentType string
|
|
}{
|
|
{
|
|
name: "default returns application/x-tar",
|
|
query: "?arg=" + cid,
|
|
expectedContentType: "application/x-tar",
|
|
},
|
|
{
|
|
name: "archive=true returns application/x-tar",
|
|
query: "?arg=" + cid + "&archive=true",
|
|
expectedContentType: "application/x-tar",
|
|
},
|
|
{
|
|
name: "compress=true returns application/gzip",
|
|
query: "?arg=" + cid + "&compress=true",
|
|
expectedContentType: "application/gzip",
|
|
},
|
|
{
|
|
name: "archive=true&compress=true returns application/gzip",
|
|
query: "?arg=" + cid + "&archive=true&compress=true",
|
|
expectedContentType: "application/gzip",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
url := node.APIURL() + "/api/v0/get" + tt.query
|
|
|
|
req, err := http.NewRequest(http.MethodPost, url, nil)
|
|
require.NoError(t, err)
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
require.NoError(t, err)
|
|
defer resp.Body.Close()
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
assert.Equal(t, tt.expectedContentType, resp.Header.Get("Content-Type"),
|
|
"Content-Type header mismatch for %s", tt.name)
|
|
})
|
|
}
|
|
}
|