Skip to content

Commit e0d4b3e

Browse files
authored
Merge pull request #469 from ipfs/release-v0.13.1
Release v0.13.1
2 parents 33ff595 + c891b6d commit e0d4b3e

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ The following emojis are used to highlight certain changes:
2424

2525
### Security
2626

27+
## [v0.13.1]
28+
29+
### Added
30+
31+
* An option `DisableHTMLErrors` has been added to `gateway.Config`. When this option
32+
is `true`, pretty HTML error pages for web browsers are disabled. Instead, a
33+
`text/plain` page with the raw error message as the body is returned.
34+
35+
### Changed
36+
37+
### Removed
38+
39+
### Fixed
40+
41+
### Security
42+
2743
## [v0.13.0]
2844

2945
### Added

gateway/assets/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="ipfs-logo">&nbsp;</div>
33
<nav>
44
<a href="https://ipfs.tech" target="_blank" rel="noopener noreferrer">About<span class="dn-mobile"> IPFS</span></a>
5-
<a href="https://ipfs.tech#install" target="_blank" rel="noopener noreferrer">Install<span class="dn-mobile"> IPFS</span></a>
5+
<a href="https://docs.ipfs.tech/install/" target="_blank" rel="noopener noreferrer">Install<span class="dn-mobile"> IPFS</span></a>
66
{{ range .Menu }}
77
<a href="{{ .URL }}" target="_blank" rel="noopener noreferrer">{{ .Title }}</a>
88
{{ end }}

gateway/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func webError(w http.ResponseWriter, r *http.Request, c *Config, err error, defa
159159
code = gwErr.StatusCode
160160
}
161161

162-
acceptsHTML := strings.Contains(r.Header.Get("Accept"), "text/html")
162+
acceptsHTML := !c.DisableHTMLErrors && strings.Contains(r.Header.Get("Accept"), "text/html")
163163
if acceptsHTML {
164164
w.Header().Set("Content-Type", "text/html")
165165
w.WriteHeader(code)

gateway/errors_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,38 @@ func TestWebError(t *testing.T) {
8787
webError(w, r, config, err, http.StatusInternalServerError)
8888
require.Equal(t, http.StatusTeapot, w.Result().StatusCode)
8989
})
90+
91+
t.Run("Error is sent as HTML when 'Accept' header contains 'text/html'", func(t *testing.T) {
92+
t.Parallel()
93+
94+
w := httptest.NewRecorder()
95+
r := httptest.NewRequest(http.MethodGet, "/blah", nil)
96+
r.Header.Set("Accept", "something/else, text/html")
97+
webError(w, r, config, NewErrorStatusCodeFromStatus(http.StatusTeapot), http.StatusInternalServerError)
98+
require.Equal(t, http.StatusTeapot, w.Result().StatusCode)
99+
require.Contains(t, w.Result().Header.Get("Content-Type"), "text/html")
100+
})
101+
102+
t.Run("Error is sent as plain text when 'Accept' header does not contain 'text/html'", func(t *testing.T) {
103+
t.Parallel()
104+
105+
w := httptest.NewRecorder()
106+
r := httptest.NewRequest(http.MethodGet, "/blah", nil)
107+
r.Header.Set("Accept", "application/json")
108+
webError(w, r, config, NewErrorStatusCodeFromStatus(http.StatusTeapot), http.StatusInternalServerError)
109+
require.Equal(t, http.StatusTeapot, w.Result().StatusCode)
110+
require.Contains(t, w.Result().Header.Get("Content-Type"), "text/plain")
111+
})
112+
113+
t.Run("Error is sent as plain text when 'Accept' header contains 'text/html' and config.DisableHTMLErrors is true", func(t *testing.T) {
114+
t.Parallel()
115+
116+
config := &Config{Headers: map[string][]string{}, DisableHTMLErrors: true}
117+
w := httptest.NewRecorder()
118+
r := httptest.NewRequest(http.MethodGet, "/blah", nil)
119+
r.Header.Set("Accept", "something/else, text/html")
120+
webError(w, r, config, NewErrorStatusCodeFromStatus(http.StatusTeapot), http.StatusInternalServerError)
121+
require.Equal(t, http.StatusTeapot, w.Result().StatusCode)
122+
require.Contains(t, w.Result().Header.Get("Content-Type"), "text/plain")
123+
})
90124
}

gateway/gateway.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ type Config struct {
4040
// overridden per FQDN in PublicGateways. To be used with WithHostname.
4141
NoDNSLink bool
4242

43+
// DisableHTMLErrors disables pretty HTML pages when an error occurs. Instead, a `text/plain`
44+
// page will be sent with the raw error message. This can be useful if this gateway
45+
// is being proxied by other service, which wants to use the error message.
46+
DisableHTMLErrors bool
47+
4348
// PublicGateways configures the behavior of known public gateways. Each key is
4449
// a fully qualified domain name (FQDN). To be used with WithHostname.
4550
PublicGateways map[string]*PublicGateway

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "v0.13.0"
2+
"version": "v0.13.1"
33
}

0 commit comments

Comments
 (0)