Skip to content

Commit

Permalink
feat(gateway): add RawError option
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Sep 19, 2023
1 parent 68914ea commit 9acc0ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ The following emojis are used to highlight certain changes:
### Added

* ✨ The `routing/http` implements Delegated Peer Routing introduced in [IPIP-417](https://github.com/ipfs/specs/pull/417).
* An option `RawError` has been added to `gateway.Config`. When this option is `true`,
pretty HTML error pages are disabled. Instead, a `text/plain` page with the raw error
message as the body is returned.

### Changed

Expand Down
2 changes: 1 addition & 1 deletion gateway/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func webError(w http.ResponseWriter, r *http.Request, c *Config, err error, defa
code = gwErr.StatusCode
}

acceptsHTML := strings.Contains(r.Header.Get("Accept"), "text/html")
acceptsHTML := !c.RawError && strings.Contains(r.Header.Get("Accept"), "text/html")
if acceptsHTML {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(code)
Expand Down
5 changes: 5 additions & 0 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ type Config struct {
// overridden per FQDN in PublicGateways. To be used with WithHostname.
NoDNSLink bool

// RawError disables pretty HTML pages when an error occurs. Instead, a `text/plain`
// page will be sent with the raw error message. This can be useful if this gateway
// is being proxied by other service, which wants to use the error message.
RawError bool

// PublicGateways configures the behavior of known public gateways. Each key is
// a fully qualified domain name (FQDN). To be used with WithHostname.
PublicGateways map[string]*PublicGateway
Expand Down

0 comments on commit 9acc0ac

Please sign in to comment.