aboutsummaryrefslogtreecommitdiffhomepage
path: root/caddytest
diff options
context:
space:
mode:
authorMohammed Al Sahaf <[email protected]>2024-04-18 23:31:00 +0300
committerGitHub <[email protected]>2024-04-18 20:31:00 +0000
commitc6673ad4d8c3253179d697f06aac458e48e56546 (patch)
tree45ee4638989a6e591c0d21d55d3d174f31013ea3 /caddytest
parent9ab09433deba62f9f2b37d824570926f7ee69312 (diff)
downloadcaddy-c6673ad4d8c3253179d697f06aac458e48e56546.tar.gz
caddy-c6673ad4d8c3253179d697f06aac458e48e56546.zip
staticresp: Use the evaluated response body for sniffing JSON content-type (#6249)
Diffstat (limited to 'caddytest')
-rw-r--r--caddytest/integration/handler_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/caddytest/integration/handler_test.go b/caddytest/integration/handler_test.go
index 6db119eae..afc700b02 100644
--- a/caddytest/integration/handler_test.go
+++ b/caddytest/integration/handler_test.go
@@ -1,6 +1,7 @@
package integration
import (
+ "bytes"
"net/http"
"testing"
@@ -29,3 +30,30 @@ func TestBrowse(t *testing.T) {
}
tester.AssertResponseCode(req, 200)
}
+
+func TestRespondWithJSON(t *testing.T) {
+ tester := caddytest.NewTester(t)
+ tester.InitServer(`
+ {
+ skip_install_trust
+ admin localhost:2999
+ http_port 9080
+ https_port 9443
+ grace_period 1ns
+ }
+ localhost {
+ respond {http.request.body}
+ }
+ `, "caddyfile")
+
+ res, _ := tester.AssertPostResponseBody("https://localhost:9443/",
+ nil,
+ bytes.NewBufferString(`{
+ "greeting": "Hello, world!"
+ }`), 200, `{
+ "greeting": "Hello, world!"
+ }`)
+ if res.Header.Get("Content-Type") != "application/json" {
+ t.Errorf("expected Content-Type to be application/json, but was %s", res.Header.Get("Content-Type"))
+ }
+}