From b5e5ff20e562e42888a9e96c1257c149afe88bee Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 16 Nov 2022 12:26:07 +0100 Subject: [PATCH] feat: update doc --- core/corehttp/gateway_handler_codec.go | 10 +++++----- test/sharness/t0123-gateway-json-cbor.sh | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/corehttp/gateway_handler_codec.go b/core/corehttp/gateway_handler_codec.go index 8f0a3c3fd95..355c8047239 100644 --- a/core/corehttp/gateway_handler_codec.go +++ b/core/corehttp/gateway_handler_codec.go @@ -127,15 +127,15 @@ func (i *gatewayHandler) serverCodecHTML(ctx context.Context, w http.ResponseWri
%s

Please follow the following links to download the document in other formats:

`, 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) { @@ -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 { diff --git a/test/sharness/t0123-gateway-json-cbor.sh b/test/sharness/t0123-gateway-json-cbor.sh index 20160ecbaeb..3a64af64356 100755 --- a/test/sharness/t0123-gateway-json-cbor.sh +++ b/test/sharness/t0123-gateway-json-cbor.sh @@ -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 @@ -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