Skip to content

Commit

Permalink
feat: update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Nov 16, 2022
1 parent 8c6a8da commit b5e5ff2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/corehttp/gateway_handler_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ func (i *gatewayHandler) serverCodecHTML(ctx context.Context, w http.ResponseWri
<pre>%s</pre>
<p>Please follow the following links to download the document in other formats:</p>
<ul>
<li><a href="?format=dag-json">DAG-JSON</a></li>
<li><a href="?format=dag-cbor">DAG-CBOR</a></li>
<li><a href="?format=raw">Raw</a></li>
<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>
<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>
<li><a href="?format=raw">Download Raw Block</a></li>
</ul>
</body>
</html>
`, contentPath.String())

w.Write([]byte(body))
_, _ = w.Write([]byte(body))
}

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

w.Write(buf.Bytes())
_, _ = w.Write(buf.Bytes())
}

func setCodecContentDisposition(w http.ResponseWriter, r *http.Request, resolvedPath ipath.Resolved, contentType string) string {
Expand Down
10 changes: 10 additions & 0 deletions test/sharness/t0123-gateway-json-cbor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ test_expect_success "Add CARs for path traversal and DAG-PB representation tests
test_should_contain $DAG_PB_CID import_output
'

test_expect_success "GET DAG-JSON with Accept: text/html returns HTML" '
curl -sD - -H "Accept: text/html" "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID" > curl_output 2>&1 &&
test_should_contain "Content-Type: text/html" curl_output
'

test_expect_success "GET DAG-JSON traversal returns 400 if there is path remainder" '
curl --head "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_JSON_TRAVERSAL_CID/foo?format=dag-json" > curl_output 2>&1 &&
test_should_contain "400 Bad Request" curl_output
Expand All @@ -154,6 +159,11 @@ test_expect_success "GET DAG-JSON traverses multiple links" '
test_cmp expected actual
'

test_expect_success "GET DAG-CBOR with Accept: text/html returns HTML" '
curl -sD - -H "Accept: text/html" "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID" > curl_output 2>&1 &&
test_should_contain "Content-Type: text/html" curl_output
'

test_expect_success "GET DAG-CBOR traversal returns 400 if there is path remainder" '
curl --head "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo?format=dag-cbor" > curl_output 2>&1 &&
test_should_contain "400 Bad Request" curl_output
Expand Down

0 comments on commit b5e5ff2

Please sign in to comment.