Skip to content

Commit f76407c

Browse files
committed
refactor: rename option to DeserializedResponses
1 parent c50d89f commit f76407c

4 files changed

Lines changed: 26 additions & 27 deletions

File tree

‎examples/gateway/common/handler.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewHandler(gwAPI gateway.IPFSBackend) http.Handler {
2121
// For these examples we have the trusted mode enabled by default. That is,
2222
// all types of requests will be accepted. By default, only Trustless Gateway
2323
// requests work: https://specs.ipfs.tech/http-gateways/trustless-gateway/
24-
TrustedMode: true,
24+
DeserializedResponses: true,
2525

2626
// Initialize the public gateways that we will want to have available through
2727
// Host header rewriting. This step is optional and only required if you're
@@ -35,14 +35,14 @@ func NewHandler(gwAPI gateway.IPFSBackend) http.Handler {
3535
UseSubdomains: true,
3636
// This gateway is used for testing and therefore we make non-trustless
3737
// requests. Thus, we have to manually turn on the trusted mode.
38-
TrustedMode: true,
38+
DeserializedResponses: true,
3939
},
4040
// Support local requests
4141
"localhost": {
42-
Paths: []string{"/ipfs", "/ipns"},
43-
NoDNSLink: false,
44-
UseSubdomains: true,
45-
TrustedMode: true,
42+
Paths: []string{"/ipfs", "/ipns"},
43+
NoDNSLink: false,
44+
UseSubdomains: true,
45+
DeserializedResponses: true,
4646
},
4747
},
4848
}

‎gateway/gateway.go‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ type Config struct {
2020
// headers via AddAccessControlHeaders.
2121
Headers map[string][]string
2222

23-
// TrustedMode configures this gateway to allow trusted requests. By default,
24-
// the gateway will operate in trustless mode, as defined in the specification:
25-
// https://specs.ipfs.tech/http-gateways/trustless-gateway/.
26-
//
27-
// This only applies to hostnames not defined under PublicGateways. In addition,
28-
// the hostnames localhost, 127.0.0.1 and ::1 are considered trusted by default.
29-
TrustedMode bool
23+
// DeserializedResponses configures this gateway to support returning data
24+
// in deserialized format. By default, the gateway will only provide raw responses,
25+
// operating as a trustless gateway, as defined in the specification:
26+
// https://specs.ipfs.tech/http-gateways/trustless-gateway/. This flag can be
27+
// overridden per FQDN in PublicGateways.
28+
DeserializedResponses bool
3029

3130
// NoDNSLink configures the gateway to _not_ perform DNS TXT record lookups in
3231
// response to requests with values in `Host` HTTP header. This flag can be
@@ -68,9 +67,9 @@ type Specification struct {
6867
// This should be set to true if you use HTTPS.
6968
InlineDNSLink bool
7069

71-
// TrustedMode configures this gateway to allow trusted requests. This setting
72-
// overrides the global setting. Not setting TrustedMode enables Trustless Mode.
73-
TrustedMode bool
70+
// DeserializedResponses configures this gateway to support returning data
71+
// in deserialized format. This setting overrides the global setting.
72+
DeserializedResponses bool
7473
}
7574

7675
// TODO: Is this what we want for ImmutablePath?

‎gateway/gateway_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *mock
199199

200200
func newTestServer(t *testing.T, api IPFSBackend) *httptest.Server {
201201
return newTestServerWithConfig(t, api, Config{
202-
Headers: map[string][]string{},
203-
TrustedMode: true,
202+
Headers: map[string][]string{},
203+
DeserializedResponses: true,
204204
})
205205
}
206206

@@ -591,8 +591,8 @@ func TestIpfsTrustlessMode(t *testing.T) {
591591
Paths: []string{"/ipfs", "/ipns"},
592592
},
593593
"trusted.com": {
594-
Paths: []string{"/ipfs", "/ipns"},
595-
TrustedMode: true,
594+
Paths: []string{"/ipfs", "/ipns"},
595+
DeserializedResponses: true,
596596
},
597597
},
598598
})
@@ -673,8 +673,8 @@ func TestIpnsTrustlessMode(t *testing.T) {
673673
Paths: []string{"/ipfs", "/ipns"},
674674
},
675675
"trusted.com": {
676-
Paths: []string{"/ipfs", "/ipns"},
677-
TrustedMode: true,
676+
Paths: []string{"/ipfs", "/ipns"},
677+
DeserializedResponses: true,
678678
},
679679
},
680680
})

‎gateway/handler.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (i *handler) getOrHeadHandler(w http.ResponseWriter, r *http.Request) {
240240
w.Header().Set("X-Ipfs-Path", contentPath.String())
241241

242242
// Trustless gateway.
243-
if !i.isTrustedMode(r) && !i.isValidTrustlessRequest(contentPath, responseFormat) {
243+
if !i.onlyDeserializedResponses(r) && !i.isSerializedRequest(contentPath, responseFormat) {
244244
err := errors.New("only trustless requests are accepted: https://specs.ipfs.tech/http-gateways/trustless-gateway/")
245245
webError(w, err, http.StatusNotImplemented)
246246
return
@@ -329,7 +329,7 @@ func (i *handler) addUserHeaders(w http.ResponseWriter) {
329329
}
330330
}
331331

332-
func (i *handler) isTrustedMode(r *http.Request) bool {
332+
func (i *handler) onlyDeserializedResponses(r *http.Request) bool {
333333
// Get the host, by default the request's Host. If this request went through
334334
// WithHostname, also check for the key in the context. If that is not present,
335335
// also check X-Forwarded-Host to support reverse proxies.
@@ -342,14 +342,14 @@ func (i *handler) isTrustedMode(r *http.Request) bool {
342342

343343
// If the gateway is defined, return whatever is set.
344344
if gw, ok := i.config.PublicGateways[host]; ok {
345-
return gw.TrustedMode
345+
return gw.DeserializedResponses
346346
}
347347

348348
// Otherwise, the default.
349-
return i.config.TrustedMode
349+
return i.config.DeserializedResponses
350350
}
351351

352-
func (i *handler) isValidTrustlessRequest(contentPath ipath.Path, responseFormat string) bool {
352+
func (i *handler) isSerializedRequest(contentPath ipath.Path, responseFormat string) bool {
353353
// Only allow "/{#1}/{#2}"-like paths.
354354
trimmedPath := strings.Trim(contentPath.String(), "/")
355355
pathComponents := strings.Split(trimmedPath, "/")

0 commit comments

Comments
 (0)