Commit Graph

297 Commits

Author SHA1 Message Date
Jorropo
196887cbe5 chore: bump go-libp2p v0.22.0 & go1.18&go1.19
Fixes: #9225
2022-09-09 17:09:38 +02:00
Marcin Rataj
924ab0616b
Merge pull request #9070 from iand/feat-modular-gateway
feat: make corehttp a reusable component
2022-08-17 03:25:29 +02:00
Marcin Rataj
7992025254 fix(gw): 404 when a valid DAG is missing link 2022-07-23 00:16:31 +02:00
Ian Davis
f8cdd96c2a
Clarify offlineApi argument 2022-07-21 15:14:52 +01:00
Ian Davis
f4d87419ce
feat: make corehttp a reusable component 2022-07-21 15:09:06 +01:00
Marcin Rataj
58aaee00f8 feat(gw): Cache-Control: only-if-cached
This implements the only-if-cached behavior documented in specs:
https://github.com/ipfs/specs/blob/main/http-gateways/PATH_GATEWAY.md#cache-control-request-header
https://github.com/ipfs/specs/blob/main/http-gateways/PATH_GATEWAY.md#only-if-cached-head-behavior
2022-07-07 08:49:26 +02:00
Marcin Rataj
82467bc936 refactor: rename to kubo 2022-07-06 18:40:37 +02:00
Marcin Rataj
67fdb6efcd
feat(gw): improved If-None-Match support (#8891)
Improves the way we handle If-None-Match header:
- Support for more than one Etag passed in If-None-Match
- Match both strong and weak Etags to maximize caching across
  various HTTP clients and libraries (some send weak Etags by default)
- Support for wildcard '*'
- Tests for If-None-Match behavior
2022-04-19 20:57:11 +02:00
Justin Johnson
e07baf5835
chore(gw): extract logical functions to improve readability (#8885)
* Extract functions from getOrHeadHandler to improve readability and prepare for later refactorings

* Address PR feedback on when to return errors or booleans

* Be explicit about use of *requestError vs error
2022-04-15 16:06:43 +02:00
Gus Eggert
9bd346e250
fix: fix context plumbing in gateway handlers (#8871)
This ensures that child contexts are passed around between
the handlers so that traces show the call hierarchy correctly.
2022-04-11 23:09:00 +02:00
makeworld
52bf133946
fix(gw): missing return if dir fails to finalize (#8806) 2022-04-08 23:09:23 +02:00
Ian Davis
fbf76663f4
fix(gw): update metrics only when payload data sent (#8827)
* fix: report gateway http metrics only when response is successful
* fix(gw): 304 Not Modified as no-op

This fix ensures we don't do any additional work when Etag match
what user already has in their own cache.

Co-authored-by: Marcin Rataj <lidel@lidel.org>
2022-04-08 22:07:44 +02:00
Gus Eggert
f855bfe6ef
feat: add basic gateway tracing (#8595)
* add deprecation warning when tracer plugins are loaded
* add response format attribute to span in gateway handler
* add note about tracing's experimental status in godoc
* add nil check for TTL when adding name span attrs
* add basic sharness test for integration with otel collector
* add nil check in UnixFSAPI.processLink
* test: sharness check all json objs for swarm span
* add env var docs to docs/environment-variables.md
* chore: pin the otel collector version
* add tracing spans per response type (#8841)
* docs: tracing with jaeger-ui

Co-authored-by: Marcin Rataj <lidel@lidel.org>
2022-04-04 19:24:05 +02:00
Marcin Rataj
5fa556945e
fix(gw): validate requested CAR version (#8835)
* fix(gw): validate requested CAR version

This adds validation of 'application/vnd.ipld.car;version=n' passed
in the Accept header by HTTP clients to align Gateway behavior with
the spec submitted to IANA.

* test: fix comment in test/sharness/t0118-gateway-car.sh

Co-authored-by: Gus Eggert <gus@gus.dev>

Co-authored-by: Gus Eggert <gus@gus.dev>
2022-04-01 09:12:46 -07:00
Adin Schmahmann
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
Marcin Rataj
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
Marcin Rataj
caba3b2643
feat: X-Ipfs-Roots for smarter HTTP caches (#8720) 2022-03-01 09:04:31 -08:00
Manuel Alonso
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
Steven Allen
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
Adrian Lanzafame
02823935aa feat: register first block metric by default 2021-08-07 15:48:22 -04:00
Steven Allen
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
Steven Allen
0a3f88823c
Merge pull request #7994 from ipfs/chore/deprecate-pathprefixes
chore: deprecate Gateway.PathPrefixes
2021-03-30 15:52:02 -07:00
Marcin Rataj
2f105f79b9
chore: deprecate Gateway.PathPrefixes
Context:
https://github.com/ipfs/go-ipfs/issues/7702#issuecomment-803136077
2021-03-30 21:17:41 +02:00
Marcin Rataj
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
Marcin Rataj
a35ffee136
refactor: safer query handling
https://github.com/ipfs/go-ipfs/pull/7930#discussion_r597246135
2021-03-18 23:48:53 +01:00
Marcin Rataj
450baef0e9
refactor: explicit prefix check
https://github.com/ipfs/go-ipfs/pull/7930#discussion_r584001161
2021-03-18 21:48:04 +01:00
Marcin Rataj
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
Marcin Rataj
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
Marcin Rataj
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
Marcin Rataj
abb25a1cfc refactor: remove redundant urlescape
URL.Query() will already decode the query parameters
2021-01-14 20:52:04 +01:00
Marcin Rataj
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
Dennis Trautwein
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
Adin Schmahmann
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
Marcin Rataj
6ffd0aa22e
fix(gw): preserve query on website redirect 2020-10-14 00:46:57 +02:00
Marcin Rataj
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
Marcin Rataj
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
Marcin Rataj
cd1feb3af4
fix(gateway): correct breadcrumbs on dnslink site 2020-09-25 23:11:53 +02:00
Marcin Rataj
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
Marcin Rataj
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
Kevin Neaton
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
Peter Rabbitson
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
Steven Allen
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
Peter Wu
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
Peter Wu
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
JP Hastings-Spital
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
Gowtham G
e93f2002f5 optimize import order 2020-05-02 14:19:01 +05:30
Gowtham G
214d29ebf8 #7252 - print error message 2020-05-01 22:37:20 +05:30
Gowtham G
9201b1dde6 #7252 - read content directly instead of sending 512bytes 2020-05-01 20:29:32 +05:30
Gowtham G
2e87ac88a3 Fixes #7252 - Uses gabriel-vasile/mimetype to support additional content types 2020-05-01 12:19:36 +05:30
Steven Allen
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