From a0f3864d5dc77e8fb496fc88fd48a6a7869ef000 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 27 Sep 2024 00:19:44 +0700 Subject: lib/http: remove writing StatusNoContent on ResponseTypeNode To make consistent with RequestTypeNone, the ResponseTypeNone should not write any response header or HTTP status code. It will be handled manually by [Endpoint.Call]. --- lib/http/endpoint.go | 7 +++---- lib/http/response_type.go | 8 +++++--- lib/http/server_test.go | 12 ++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/http/endpoint.go b/lib/http/endpoint.go index 58ac2712..e209f401 100644 --- a/lib/http/endpoint.go +++ b/lib/http/endpoint.go @@ -1,6 +1,6 @@ -// Copyright 2018, Shulhan . All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2018 M. Shulhan +// +// SPDX-License-Identifier: BSD-3-Clause package http @@ -117,7 +117,6 @@ func (ep *Endpoint) call( switch ep.ResponseType { case ResponseTypeNone: - res.WriteHeader(http.StatusNoContent) return case ResponseTypeBinary: res.Header().Set(HeaderContentType, ContentTypeBinary) diff --git a/lib/http/response_type.go b/lib/http/response_type.go index 4fee2e88..b9b6e7cf 100644 --- a/lib/http/response_type.go +++ b/lib/http/response_type.go @@ -1,6 +1,6 @@ -// Copyright 2018, Shulhan . All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2018 M. Shulhan +// +// SPDX-License-Identifier: BSD-3-Clause package http @@ -9,6 +9,8 @@ type ResponseType string // List of valid response type. const ( + // ResponseTypeNone skip writing header Content-Type and status + // code, it will handled manually by [Endpoint.Call]. ResponseTypeNone ResponseType = `` ResponseTypeBinary ResponseType = `binary` ResponseTypeHTML ResponseType = `html` diff --git a/lib/http/server_test.go b/lib/http/server_test.go index e69ff99c..0c2851a7 100644 --- a/lib/http/server_test.go +++ b/lib/http/server_test.go @@ -1,6 +1,6 @@ -// Copyright 2018, Shulhan . All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2018 M. Shulhan +// +// SPDX-License-Identifier: BSD-3-Clause package http @@ -71,7 +71,7 @@ func TestRegisterDelete(t *testing.T) { Call: cbNone, }, reqURL: testServerURL + `/delete/none?k=v`, - expStatusCode: http.StatusNoContent, + expStatusCode: http.StatusOK, }, { desc: "With response type binary", ep: &Endpoint{ @@ -586,11 +586,11 @@ func TestRegisterPut(t *testing.T) { }, { desc: "With registered PUT and subtree root", reqURL: testServerURL + `/put/`, - expStatusCode: http.StatusNoContent, + expStatusCode: http.StatusOK, }, { desc: "With registered PUT and query", reqURL: testServerURL + `/put?k=v`, - expStatusCode: http.StatusNoContent, + expStatusCode: http.StatusOK, }} for _, c := range cases { -- cgit v1.3