1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 19:44:01 +08:00

283 Commits

Author SHA1 Message Date
beaa8fc29b feat: add gateway histogram metrics (#8443)
* feat(gw): response type histogram metrics

- response-type agnostic firstContentBlockGetMetric which counts the
  latency til the first content block.

- car/block/file/gen-dir-index duration histogram metrics that show how
  long each response type takes

* docs: improve metrics descriptions
* feat: more gw histogram buckets

0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 30, 60 secs
as suggested in reviews at https://github.com/ipfs/go-ipfs/pull/8443

Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Gus Eggert <gus@gus.dev>
2022-03-21 15:57:08 +01:00
4cabdfefbf feat(gateway): Block and CAR response formats (#8758)
* feat: serveRawBlock implements ?format=block
* feat: serveCar implements ?format=car
* feat(gw): ?format= or Accept HTTP header

- extracted file-like content type responses to separate .go files
- Accept HTTP header with support for application/vnd.ipld.* types

* fix: use .bin for raw block content-disposition

.raw may be handled by something, depending on OS, and .bin
seems to be universally "binary file" across all systems:
https://en.wikipedia.org/wiki/List_of_filename_extensions_(A%E2%80%93E)

* refactor: gateway_handler_unixfs.go

- Moved UnixFS response handling to gateway_handler_unixfs*.go files.
- Removed support for X-Ipfs-Gateway-Prefix (Closes #7702)

* refactor: prefix cleanup and readable paths

- removed dead code after X-Ipfs-Gateway-Prefix is gone
  (https://github.com/ipfs/go-ipfs/issues/7702)
- escaped special characters in content paths returned with http.Error
  making them both safer and easier to reason about (e.g. when invisible
  whitespace Unicode is used)
2022-03-17 17:15:24 +01:00
caba3b2643 feat: X-Ipfs-Roots for smarter HTTP caches (#8720) 2022-03-01 09:04:31 -08:00
edb32ac3d7 chore(gateway): debug logging for the http requests (#8518)
* chore(gateway): better logging for the http requests

* chore(gateway): removed defer and add more data to the final log

* chore(gateway): debug logging refactor

* chore(gateway): use debug w/o context when only msg

* doc: add cmd for log level

* chore: add more logs and address fedback

* chore(gateway): log subdomains and from=requestURI, refactor

* chore(gateway): fix debug redirect
2022-02-15 17:13:09 -05:00
7c76118b0b Merge pull request #8318 from ipfs/fix/path-panic
fix: avoid out of bounds error when rendering short hashes
2021-08-13 14:54:25 -07:00
02823935aa feat: register first block metric by default 2021-08-07 15:48:22 -04:00
66a76d27f3 fix: abort when we fail to resolve CIDs
I believe we figured that these were for "informational purposes", but
really, we _should_ always be able to resolve names to CIDs. If we
can't, there's probably something wrong with the directory.
2021-07-30 11:36:23 -07:00
0a3f88823c Merge pull request #7994 from ipfs/chore/deprecate-pathprefixes
chore: deprecate Gateway.PathPrefixes
2021-03-30 15:52:02 -07:00
2f105f79b9 chore: deprecate Gateway.PathPrefixes
Context:
https://github.com/ipfs/go-ipfs/issues/7702#issuecomment-803136077
2021-03-30 21:17:41 +02:00
763a120ed2 fix: no fixup if X-Ipfs-Gateway-Prefix is present
https://github.com/ipfs/go-ipfs/pull/7930#discussion_r597976690
2021-03-20 00:00:58 +01:00
a35ffee136 refactor: safer query handling
https://github.com/ipfs/go-ipfs/pull/7930#discussion_r597246135
2021-03-18 23:48:53 +01:00
450baef0e9 refactor: explicit prefix check
https://github.com/ipfs/go-ipfs/pull/7930#discussion_r584001161
2021-03-18 21:48:04 +01:00
b81b7549d3 refactor: addressing review
- moved to separate utility function
- return Bad Request error
- improved escaping of values passed via URL path
2021-03-18 21:22:07 +01:00
dae7387584 refactor: show error, delay redirect
This implements error page that does not hide the problem,
but still redirects to a valid path after short delay:
https://github.com/ipfs/go-ipfs/pull/7930#issuecomment-786882748
2021-02-27 00:57:05 +01:00
15e3732afd feat(gw): /ipfs/ipfs/{cid} → /ipfs/{cid}
This will try to recover from invalid paths like  /ipfs/ipfs/{cid}
and redirect to proper one, when possible.
2021-02-20 00:09:17 +01:00
abb25a1cfc refactor: remove redundant urlescape
URL.Query() will already decode the query parameters
2021-01-14 20:52:04 +01:00
3de5b14e0c fix: ?uri= url-decode and preserve query
This makes ?uri= param able to process URIs passed by web browsers
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler
2021-01-14 20:52:04 +01:00
36368ee4dd feat: support requests from registerProtocolHandler
This commit adds support for requests produced by navigator.registerProtocolHandler on gateways. Now one can register `dweb.link` as an URI handler for `ipfs://`:

```
navigator.registerProtocolHandler('ipfs', 'https://dweb.link/ipfs/?uri=%s', 'ipfs resolver')
```

Then opening `ipfs://QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR` will produce an HTTP GET call to:

```
https://dweb.link/ipfs?uri=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
```

The query parameter `uri` will now be parsed and the given content identifier resolved via:

`https://dweb.link/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR`
2021-01-14 20:52:04 +01:00
499e011df9 Merge pull request #7699 from ipfs/fix/dnslink-dir-listing
fix(dnslink-gw): breadcrumbs and CID column when dir listing
2020-11-10 15:03:36 -05:00
6ffd0aa22e fix(gw): preserve query on website redirect 2020-10-14 00:46:57 +02:00
3ed46d995f test(gw): add t0115-gateway-dir-listing.sh to sharness
This adds proper end-to-end tests for directory listing on Gateway port
that protects us against regressions oni each gw type:
- path gateway
- subdomain gateway
- dnslink website gateway

Tests cover:
- etag/unicode support
- breadcrumbs
- file name column
- hash column
2020-09-29 02:27:28 +02:00
c94bd768d2 fix(gw): links in CID column on dir listing
This switches go-ipfs to dir-index-html after
https://github.com/ipfs/dir-index-html/pull/43
got merged to master
2020-09-28 23:12:47 +02:00
cd1feb3af4 fix(gateway): correct breadcrumbs on dnslink site 2020-09-25 23:11:53 +02:00
19ec5f4a51 feat(gateway): Content-Disposition for legacy clients
This adds ASCII-only filename for clients that do not implement RFC 5987

Closes #7648
2020-09-16 22:39:04 +02:00
fd01acdfc0 feat(gateway): ?filename with download=true
This implements 'attachment' mode triggered then
?filename parameter is accompanied with &download=true

When Content-Disposition: attachment is detected by a modern browser
it will skip rendering and immediately open the "save as" dialog,
making this useful feature for using IPFS gateway as target of
"Download" links on various websites.

Parameter name was suggested in:
https://github.com/ipfs/go-ipfs/pull/4177#issuecomment-414870327
2020-09-16 22:15:18 +02:00
044790a838 feat: Directory page UI improvements
These changes are needed to prepare for the Directory page UI improvements
implemented in https://github.com/ipfs/dir-index-html/issues/37.

- update dir-index-html type structs
- emit gateway URL for root links
- emit CID of each directoryItem
- emit size of directory
- emit breadcrumbs
2020-08-19 20:09:35 -04:00
2d5f8b4ebe Include the git blob id of the dir-index bundle in the ETag
While the content of raw files retrieved via the gateway should never
change, the look and feel of the directory index can and will change
between versions of go-ipfs.

Incorporate the hash of assets/bindata.go into the ETag when appropriate
2020-05-25 18:42:07 +00:00
6a2fe0a20d fix: support directory listings even if a 404 page is present
fixes https://github.com/ipfs/go-ipfs/pull/4233#issuecomment-631454543

Basically, there's a trade-off here:

1. We can support directory listings while supporting 404 pages (this PR).
2. If a 404 page is present, directory listings don't work.

Given that option 1 is more flexible and users shouldn't be _too_ confused if
they land on a directory with no index.html page, I've gone with that option.
2020-05-20 19:11:50 -07:00
d4952f2a73 fix(gateway): ensure directory listings have Content-Type text/html
Files already have an explicit Content-Type set. Be sure to do this for
directory listings as well to avoid a fallback to autodetection in
net/http. That fallback fails when a ResponseWriter is installed that
performs compression.
2020-05-20 15:20:33 +02:00
7c7888c4db fix(gateway): fix status code for HEAD on redirects
Report a consistent status code for HEAD requests that end up in a
redirect.
2020-05-20 14:03:58 +02:00
dfceafdbd3 Gateway renders pretty 404 pages if available
In the same way that an `index.html` file is rendered, if one is present, when the
requested path is a directory, now an `ipfs-404.html` file is rendered if
the requested file is not present within the specified IPFS object.

`ipfs-404.html` files are looked for in the directory of the requested path and each
parent until one is found, falling back on the well-known 404 error message.

License: MIT
Signed-off-by: JP Hastings-Spital <jphastings@gmail.com>
2020-05-19 14:41:21 -07:00
e93f2002f5 optimize import order 2020-05-02 14:19:01 +05:30
214d29ebf8 #7252 - print error message 2020-05-01 22:37:20 +05:30
9201b1dde6 #7252 - read content directly instead of sending 512bytes 2020-05-01 20:29:32 +05:30
2e87ac88a3 Fixes #7252 - Uses gabriel-vasile/mimetype to support additional content types 2020-05-01 12:19:36 +05:30
46ae021733 feat: show the absolute path every time
Even for dnslink websites.

fixes https://github.com/ipfs/go-ipfs/issues/7205
2020-04-26 17:19:17 -07:00
d8bc5c991e feat: always show the hash
Previously, we only showed this /ipns paths. However, knowing the hash of the
current directory is useful regardless.
2020-04-26 16:09:02 -07:00
1e437c7e97 Fix typos and cleanup 2020-04-20 22:00:01 +03:00
8290ec11c3 fix: subdomain redirect for dir CIDs
Closes #7164

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-04-15 23:50:53 +02:00
7340543615 corehttp: Gateway handler: add Allow headers when returning MethodNotAllowed
Spec says that response with 405 must set Allow headers.
2020-04-05 09:57:57 +02:00
f9567a0a0f fix(gateway): curl without redirect on localhost
When request is sent to http://localhost:8080/ipfs/$cid response has
HTTP 301 status code and "Location" header with redirect destination at
$cid.ipfs.localhost:8080

Redirect is followed by browsersi, but not by commandline tools.
Status 301 is ignored by curl in default mode: it will print response
and won't follow redirect, user needs to add -L for that.

To fix curl, we return correct payload in body of HTTP 301 response,
but set Clear-Site-Data header to ensure Origin sandbox can't be abused.

This requires a surgical workaround:
If Location header is present in ResponseWriter's Header map,
we ensure http.ServeContent() returns HTTP 301

Context: https://github.com/ipfs/go-ipfs/pull/6982

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-03-18 08:50:40 -07:00
3ecccd6e1d feat(gateway): subdomain and proxy gateway
License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
2020-03-18 08:50:38 -07:00
72490f7ed0 gateway: simplify/improve dnslink rewrite handling
Instead of adding a new fake header (that could be spoofed by the client...),
just read the original request URI from the request object.

This also removes support for suborigins. They have never been implemented in
browsers and it looks like efforts have stalled. We can add support back if we
need it but, well, maintaining support was going to be more trouble than it was
worth.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-03-17 19:34:44 -07:00
a53d48059b fix: migrate from deprecated warning function 2020-01-28 21:20:21 -08:00
725e6844ee gateway: cleanup logic
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-01-10 10:19:13 +01:00
5eea0a4ba0 http: use Method* constants
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-01-10 10:19:08 +01:00
453b78962b chore(gateway): remove dead code 2020-01-05 16:43:45 -08:00
1a06fb6e2f fix(gateway): correct symlink content type
We should be _resolving_ symlinks (sometimes, still need to figure out when to
do this WRT IPNS). However, that's a larger feature.
2020-01-05 16:43:44 -08:00
3859f08bf7 fix(gateway): better seeking/sized
1. Require files to have known sizes. We can add support for unknown sizes
_later_ but we can't use ServeContent for those files.
2. Replace the `sizeReadSeeker` with a `lazySeeker`. This one makes no
assumptions about how it's used so we're less likely to run into weird bugs.
2020-01-05 16:43:44 -08:00
e8a6c0c050 fix(gateway): gracefully handle files with unknown sizes in directory listings 2020-01-05 16:43:44 -08:00