Skip to content

Commit b5e5ff2

Browse files
committed
feat: update doc
1 parent 8c6a8da commit b5e5ff2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

core/corehttp/gateway_handler_codec.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ func (i *gatewayHandler) serverCodecHTML(ctx context.Context, w http.ResponseWri
127127
<pre>%s</pre>
128128
<p>Please follow the following links to download the document in other formats:</p>
129129
<ul>
130-
<li><a href="?format=dag-json">DAG-JSON</a></li>
131-
<li><a href="?format=dag-cbor">DAG-CBOR</a></li>
132-
<li><a href="?format=raw">Raw</a></li>
130+
<li><a href="?format=dag-json">Download in DAG-JSON</a> (<a href="https://ipld.io/specs/codecs/dag-json/spec/">format specification</a>)</li>
131+
<li><a href="?format=dag-cbor">Download in DAG-CBOR</a> (<a href="https://ipld.io/specs/codecs/dag-cbor/spec/">format specification</a>)</li>
132+
<li><a href="?format=raw">Download Raw Block</a></li>
133133
</ul>
134134
</body>
135135
</html>
136136
`, contentPath.String())
137137

138-
w.Write([]byte(body))
138+
_, _ = w.Write([]byte(body))
139139
}
140140

141141
func (i *gatewayHandler) serveCodecRaw(ctx context.Context, w http.ResponseWriter, r *http.Request, resolvedPath ipath.Resolved, contentPath ipath.Path, contentType string) {
@@ -204,7 +204,7 @@ func (i *gatewayHandler) serveCodecConverted(ctx context.Context, w http.Respons
204204
w.Header().Set("Last-Modified", modtime.UTC().Format(http.TimeFormat))
205205
}
206206

207-
w.Write(buf.Bytes())
207+
_, _ = w.Write(buf.Bytes())
208208
}
209209

210210
func setCodecContentDisposition(w http.ResponseWriter, r *http.Request, resolvedPath ipath.Resolved, contentType string) string {

test/sharness/t0123-gateway-json-cbor.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ test_expect_success "Add CARs for path traversal and DAG-PB representation tests
142142
test_should_contain $DAG_PB_CID import_output
143143
'
144144

145+
test_expect_success "GET DAG-JSON with Accept: text/html returns HTML" '
146+
curl -sD - -H "Accept: text/html" "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID" > curl_output 2>&1 &&
147+
test_should_contain "Content-Type: text/html" curl_output
148+
'
149+
145150
test_expect_success "GET DAG-JSON traversal returns 400 if there is path remainder" '
146151
curl --head "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID/foo?format=dag-json" > curl_output 2>&1 &&
147152
test_should_contain "400 Bad Request" curl_output
@@ -154,6 +159,11 @@ test_expect_success "GET DAG-JSON traverses multiple links" '
154159
test_cmp expected actual
155160
'
156161

162+
test_expect_success "GET DAG-CBOR with Accept: text/html returns HTML" '
163+
curl -sD - -H "Accept: text/html" "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID" > curl_output 2>&1 &&
164+
test_should_contain "Content-Type: text/html" curl_output
165+
'
166+
157167
test_expect_success "GET DAG-CBOR traversal returns 400 if there is path remainder" '
158168
curl --head "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo?format=dag-cbor" > curl_output 2>&1 &&
159169
test_should_contain "400 Bad Request" curl_output

0 commit comments

Comments
 (0)