better test endpoint ui

This commit is contained in:
Michael Quigley 2022-08-31 15:18:31 -04:00
parent 378d83715b
commit ac7ec589f6
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 39 additions and 15 deletions

View File

@ -377,10 +377,28 @@
</div>
<div id="container">
<div id="info">
<h2>The Current Now is {{ .Now }}</h2>
<p>The current 'HOST' header: {{ .Host }}</p>
<p>The remote host making the request: {{ .Remote }}</p>
<p>This host has these IP addresses: {{ .Ips }}</p>
<h2>{{ .Now }}</h2>
<h3>Local:</h3>
<table>
<tr><td>Host Header</td><td>{{ .Host }}</td></tr>
<tr><td>Remote Address</td><td>{{ .Remote }}</td></tr>
<tr><td>Local IP Addresses</td><td>{{ .Ips }}</td></tr>
</table>
<h3>Headers:</h3>
<table>
{{ range $header, $value := .Headers }}
<tr>
<td>{{ $header }}</td>
<td>
{{ range $v := $value }}
{{ $v }}
{{ end }}
</td>
</tr>
{{ end }}
</table>
</div>
</div>
</div>

View File

@ -56,22 +56,28 @@ func (cmd *testEndpointCommand) run(_ *cobra.Command, _ []string) {
func (cmd *testEndpointCommand) serveIndex(w http.ResponseWriter, r *http.Request) {
logrus.Infof("%v {%v} -> /index.html", r.RemoteAddr, r.Host)
ed := &endpointData{
Now: time.Now(),
Host: r.Host,
Remote: r.RemoteAddr,
}
ed.getIps()
if err := cmd.t.Execute(w, ed); err != nil {
if err := cmd.t.Execute(w, newEndpointData(r)); err != nil {
log.Error(err)
}
}
type endpointData struct {
Now time.Time
Host string
Remote string
Ips string
Now time.Time
Host string
Headers map[string][]string
Remote string
Ips string
}
func newEndpointData(r *http.Request) *endpointData {
ed := &endpointData{
Now: time.Now(),
Host: r.Host,
Headers: r.Header,
Remote: r.RemoteAddr,
}
ed.getIps()
return ed
}
func (ed *endpointData) getIps() {