1. The problem I’m having:
I am trying to build a simple echo server with the template functionality
2. Error messages and/or full log output:
i’m trying to evaluate a template with a POST Method but get
HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD
3. Caddy version:
v2.6.4
caddyfile
:80 {
root * /srv
file_server
try_files {path}.html {path}
templates
encode zstd gzip
rewrite /* index.html
}
index.html
{{.RespHeader.Add "Set-Cookie" "myID=test"}}
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style>
table {
border-collapse: collapse;
}
table,
th,
td {
border-bottom: 1px solid #ddd;
padding: 15px;
font-family: monospace;
font-size: 18px;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
table,
th {
text-align: left;
}
th {
background-color: #04AA6D;
color: white;
}
tr:hover {
background-color: coral;
}
.c1 {
width: 100px;
}
.c2 {
width: 400px;
}
td {
border: 1px solid blue;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<main>
<div class="article-container">
Request:
<div style="overflow-x:auto;">
<table>
<tr>
<th class="c1">What</th>
<th class="c2">Value</th>
</tr>
<tr>
<td class="c1">time</td>
<td class="c2">{{placeholder "time.now"}}</td>
</tr>
<tr>
<td class="c1">Method</td>
<td class="c2">{{.Req.Method}}</td>
</tr>
<tr>
<td class="c1">URL</td>
<td class="c2">{{.Req.URL}}</td>
</tr>
<tr>
<td class="c1">YOUR IP</td>
<td class="c2">{{.RemoteIP}}</td>
</tr>
<tr>
<td class="c1">body</td>
<td class="c2">{{placeholder "http.request.body"}}</td>
</tr>
<!-- see https://caddyserver.com/docs/json/apps/http/#docs -->
<tr>
<td class="c1">query</td>
<td class="c2">{{placeholder "http.request.query"}}</td>
</tr>
<tr>
<td class="c1">vars</td>
<td class="c2">{{placeholder "http.vars.*"}}</td>
</tr>
</table>
</div>
HEADERS:
<div style="overflow-x:auto;">
<table>
<tr>
<th class="c1">Header</th>
<th class="c2">Value</th>
</tr>
{{range $key, $val := .Req.Header}}
<tr>
<td class="c1">{{$key}}</td>
<td class="c2">{{index $val 0}}</td>
</tr>
{{end}}
</table>
</div>
{{ $cookie := index .Req.Header "Cookie" }}
{{ $cs := index $cookie 0}}
{{ $ckv := splitList " " $cs}}
<div style="overflow-x:auto;">
<table>
<tr>
<th class="c1">Cookies</th>
</tr>
{{range $val := $ckv}}
<tr>
<td class="c1">{{$val}}</td>
</tr>
{{end}}
</table>
</div>
</div>
<div class="sidebar"></div>
</main>
</body>
</html>%
i understand POST requests are blocked in the file handler but is there another way?