Commit Graph

285 Commits

Author SHA1 Message Date
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
Steven Allen
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
Dimitris Apostolou
1e437c7e97
Fix typos and cleanup 2020-04-20 22:00:01 +03:00
Marcin Rataj
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
Hector Sanjuan
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
Marcin Rataj
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
Marcin Rataj
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
Steven Allen
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
Steven Allen
a53d48059b fix: migrate from deprecated warning function 2020-01-28 21:20:21 -08:00
Steven Allen
725e6844ee gateway: cleanup logic
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-01-10 10:19:13 +01:00
Steven Allen
5eea0a4ba0 http: use Method* constants
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2020-01-10 10:19:08 +01:00
Steven Allen
453b78962b chore(gateway): remove dead code 2020-01-05 16:43:45 -08:00
Steven Allen
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