summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-09-27 00:19:44 +0700
committerShulhan <ms@kilabit.info>2024-09-30 23:04:56 +0700
commita0f3864d5dc77e8fb496fc88fd48a6a7869ef000 (patch)
tree9575aac69b05112f3abd660976b5dd31fd65f342
parent04ab5cfb262c8dbdadf2090bde99506ff2eac5a9 (diff)
downloadpakakeh.go-a0f3864d5dc77e8fb496fc88fd48a6a7869ef000.tar.xz
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].
-rw-r--r--lib/http/endpoint.go7
-rw-r--r--lib/http/response_type.go8
-rw-r--r--lib/http/server_test.go12
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 <ms@kilabit.info>. 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 <ms@kilabit.info>
+//
+// 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 <ms@kilabit.info>. 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 <ms@kilabit.info>
+//
+// 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 <ms@kilabit.info>. 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 <ms@kilabit.info>
+//
+// 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 {