generated from ipfs/ipfs-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 100
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
feat: refactor gateway api to operate on higher level semantics #176
Merged
Merged
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
8ba923b
feat: refactor gateway api to operate on higher level semantics
aschmahmann 0ead6cd
fix: respond to comments
aschmahmann 8704fef
next iteration: moved _redirects and index.html back to being the gat…
aschmahmann 0b6c1c5
rename GatewayMetadata -> ContentPathMetadata
aschmahmann 32eeec6
Merge branch 'main' into feat/gateway-refactor
aschmahmann 9e32875
go mod tidy
aschmahmann 7d145b5
make tests mostly pass, includes change to go-unixfs
aschmahmann ebbe85d
Merge branch 'main' into feat/gateway-refactor
aschmahmann 8413c2b
use shared BlocksGatway
aschmahmann 2b172e7
fixup most errors, expand definition of NotFound
aschmahmann 461fca2
change error reporting to pass a test
aschmahmann 8fca1ae
tmp: point at go-unixfs commit hash
aschmahmann 2bba208
downgrade go-car+otel dependencies and tidy
aschmahmann 2631a5c
fix: bump go-unixfs dep that was missed previously
aschmahmann 6652355
bump go-unixfs to support cid metadata in symlinks
aschmahmann 3f135ce
fix it so we don't cache /ipns/somedir/index.html
aschmahmann bbdc88f
feat(gateway): allow content-type for UnixFS data to be determined by…
aschmahmann f8b96e5
refactor(gateway): move public sentinel errors to the same file as th…
aschmahmann 146bbff
docs(gateway): add clarification to ResolveMutable
aschmahmann 707bec5
feat: fix errors and expose ErrServiceUnavailable instead of go-ipfs-…
aschmahmann 382ceaa
fix more errors, assert index.html content type as text/html
aschmahmann 526e9e0
cleanup some todos
aschmahmann ba19090
refactor dirEntryMetadata name
aschmahmann 80bebc1
explicitly handle an impossible error
aschmahmann 09dc72d
fixup some text
aschmahmann f4b3232
more 500s and removing todos
aschmahmann 54b7644
docs: improve gateway API docs
aschmahmann 42dfc9d
blocks-gateway: remove extraneous methods
aschmahmann b4a6bb7
blocks-gateway: return non-UnixFS codecs from Get, except for non-Uni…
aschmahmann 61f233c
fix _redirects caching/mutability
aschmahmann 0caed11
fix gateway car requests
aschmahmann 8ff5626
switch multierr lib
aschmahmann 7275da3
reorder some imports
aschmahmann 7af0fc6
fix: set X-Ipfs-Roots for CARs
aschmahmann ac23a54
Merge branch 'main' into feat/gateway-refactor
aschmahmann 5efb46f
fix: restore error handling lost in merge commit
aschmahmann ea590f1
feat: switch Get to be multiple functions and implement range requests
aschmahmann 4a49a38
feat: add ResolvePath to gateway API
aschmahmann 36c78c0
fix error shadowing
aschmahmann 62c6100
chore: cleanup linter errors
aschmahmann 8c1c4d0
change GetCAR return signature to make the linter happy
aschmahmann 14e7ffb
fix: uint64 cannot be < 0
hacdias 17f8d70
chore: go mod tidy
hacdias e7366ca
apply some suggestions by @lidel
hacdias cde04e5
Merge branch 'main' into feat/gateway-refactor
hacdias db8b79e
feat: use rawRecord value for ipns record etag
hacdias 2411c38
refactor: call addUserHeaders and set X-Ipfs-Path earlier
hacdias e0a3b8b
docs: apply suggestions
hacdias 2615467
docs: clean explanation in isErrNotFound
hacdias 524f4fd
fix: panic on invalid ipns
hacdias c9bed98
improved errors, renamed variables, remove comments (lidel feedback)
hacdias 2eb8fb6
wrap directory entries for fast listing 🌮
hacdias ae65e02
feat: add default dns resolvers
hacdias 167a8a8
Merge branch 'main' into feat/gateway-refactor
hacdias cbf04b3
feat: switch Get to return a union of files.File and a directory list…
aschmahmann cd0193d
docs: change contract on GetRange to indicate the full file must stil…
aschmahmann 5f7a833
fix: switch _redirects to properly use root path instead of a partial…
aschmahmann e928893
refactor: remove unused types
hacdias c3d7b6f
refactor: make unixfs dir handling clearer
hacdias a05f54c
docs: handleWebRequestErrors
lidel 47d3e19
chore: rename to directoryMetadata
lidel 3de5712
change errors: graph size -> DAG size
aschmahmann 1c6d038
Merge branch 'main' into feat/gateway-refactor
hacdias 784eed6
fix merge
hacdias 1c4716f
fix: ensure basic ipld codecs are registered
hacdias 925f76d
Merge branch 'main' into feat/gateway-refactor
aschmahmann b5beaa2
more boxo related fixups
aschmahmann 2e4b7c3
more boxo related fixups
aschmahmann ffa3aad
cleanup variable name in example
aschmahmann 360b031
Merge branch 'main' into feat/gateway-refactor
hacdias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,12 @@ package gateway | |
|
||
import ( | ||
"context" | ||
"io" | ||
"net/http" | ||
"sort" | ||
|
||
cid "github.com/ipfs/go-cid" | ||
"github.com/ipfs/go-libipfs/blocks" | ||
"github.com/ipfs/go-libipfs/files" | ||
iface "github.com/ipfs/interface-go-ipfs-core" | ||
"github.com/ipfs/interface-go-ipfs-core/path" | ||
) | ||
|
||
|
@@ -17,34 +16,110 @@ type Config struct { | |
Headers map[string][]string | ||
} | ||
|
||
// API defines the minimal set of API services required for a gateway handler. | ||
// ImmutablePath TODO: This isn't great, as its just a signal and mutable paths fulfill the same interface | ||
type ImmutablePath interface { | ||
// String returns the path as a string. | ||
String() string | ||
|
||
// Namespace returns the first component of the path. | ||
// | ||
// For example path "/ipfs/QmHash", calling Namespace() will return "ipfs" | ||
// | ||
// Calling this method on invalid paths (IsValid() != nil) will result in | ||
// empty string | ||
Namespace() string | ||
|
||
// IsValid checks if this path is a valid ipfs Path, returning nil iff it is | ||
// valid | ||
IsValid() error | ||
} | ||
|
||
type GatewayMetadata struct { | ||
aschmahmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PathSegmentRoots []cid.Cid | ||
LastSegment path.Resolved | ||
RedirectInfo RedirectInfo | ||
} | ||
|
||
// RedirectInfo is used to help the gateway figure out what to happen if _redirects were leveraged | ||
type RedirectInfo struct { | ||
RedirectUsed bool | ||
StatusCode int | ||
Redirect4xxPage files.File | ||
Redirect4xxTo path.Path | ||
Redirect4xxPageCid cid.Cid | ||
Redirect3xxTo string | ||
} | ||
aschmahmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
type GetOpt func(*getOpts) error | ||
type getOpts struct { | ||
rangeFrom int | ||
rangeTo int | ||
|
||
fullDepth bool | ||
rawBlock bool | ||
} | ||
|
||
type dummyGetOpts struct{} | ||
|
||
var GetOptions dummyGetOpts | ||
|
||
// GetRange is a range request for some file data | ||
// Note: currently a full file object should be returned but reading from values outside the range can error | ||
func (o dummyGetOpts) GetRange(from, to int) GetOpt { | ||
return func(options *getOpts) error { | ||
options.rangeFrom = from | ||
options.rangeTo = to | ||
return nil | ||
} | ||
} | ||
|
||
// GetFullDepth fetches all data linked from the last logical node in the path. In particular, recursively fetch an | ||
// entire UnixFS directory. | ||
func (o dummyGetOpts) GetFullDepth() GetOpt { | ||
return func(options *getOpts) error { | ||
options.fullDepth = true | ||
return nil | ||
} | ||
} | ||
|
||
// GetRawBlock fetches the data at the last path element as if it were a raw block rather than something more complex | ||
// such as a UnixFS file or directory. | ||
func (o dummyGetOpts) GetRawBlock() GetOpt { | ||
return func(options *getOpts) error { | ||
options.rawBlock = true | ||
return nil | ||
} | ||
} | ||
|
||
type API interface { | ||
// GetUnixFsNode returns a read-only handle to a file tree referenced by a path. | ||
GetUnixFsNode(context.Context, path.Resolved) (files.Node, error) | ||
// Get returns a file or directory depending on what the path is that has been requested. | ||
// This Get follows the ipfs:// web semantics which means handling of index.html and _redirects files. | ||
// There are multiple options passable to this function, read them for more information. | ||
Get(context.Context, ImmutablePath, ...GetOpt) (GatewayMetadata, files.Node, error) | ||
|
||
// Head returns a file or directory depending on what the path is that has been requested. | ||
// This Head follows the ipfs:// web semantics which means handling of index.html and _redirects files. | ||
Head(context.Context, ImmutablePath) (GatewayMetadata, files.Node, error) | ||
|
||
// LsUnixFsDir returns the list of links in a directory. | ||
LsUnixFsDir(context.Context, path.Resolved) (<-chan iface.DirEntry, error) | ||
// GetCAR returns a CAR file for the given immutable path | ||
GetCAR(context.Context, ImmutablePath) (GatewayMetadata, io.ReadSeekCloser, error) | ||
aschmahmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// GetBlock return a block from a certain CID. | ||
GetBlock(context.Context, cid.Cid) (blocks.Block, error) | ||
// IsCached returns whether or not the path exists locally. | ||
IsCached(context.Context, path.Path) bool | ||
|
||
// GetIPNSRecord retrieves the best IPNS record for a given CID (libp2p-key) | ||
// from the routing system. | ||
GetIPNSRecord(context.Context, cid.Cid) ([]byte, error) | ||
|
||
// ResolveMutable takes a mutable path and resolves it into an immutable one. This means recursively resolving any | ||
// DNSLink or IPNS records. | ||
aschmahmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ResolveMutable(context.Context, path.Path) (ImmutablePath, error) | ||
|
||
// GetDNSLinkRecord returns the DNSLink TXT record for the provided FQDN. | ||
// Unlike ResolvePath, it does not perform recursive resolution. It only | ||
// checks for the existence of a DNSLink TXT record with path starting with | ||
// /ipfs/ or /ipns/ and returns the path as-is. | ||
GetDNSLinkRecord(context.Context, string) (path.Path, error) | ||
|
||
// IsCached returns whether or not the path exists locally. | ||
IsCached(context.Context, path.Path) bool | ||
|
||
// ResolvePath resolves the path using UnixFS resolver. If the path does not | ||
// exist due to a missing link, it should return an error of type: | ||
// https://pkg.go.dev/github.com/ipfs/[email protected]/resolver#ErrNoLink | ||
ResolvePath(context.Context, path.Path) (path.Resolved, error) | ||
} | ||
|
||
// A helper function to clean up a set of headers: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why
interface
?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.
Was matching the other path types, doesn't have to be though. This was mostly a placeholder