Adds "Host" and "X-Forwarded-For" header options (#61)

This commit is contained in:
Florian Michel 2022-01-31 06:40:58 +01:00 committed by GitHub
parent da2dc5c63a
commit 42523ae9d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 67 additions and 0 deletions

View File

@ -7,6 +7,7 @@ The format is based on [Keep a Changelog][keepachangelog] and this project adher
### UNRELEASED
- Go updated from `1.17.5` up to `1.17.6`
- Add "Host" and "X-Forwarded-For" Header to error pages
## v2.4.0

View File

@ -21,7 +21,9 @@ formats:
"message": {{ message | json }},
"description": {{ description | json }}{{ if show_details }},
"details": {
"host": {{ host | json }},
"original_uri": {{ original_uri | json }},
"forwarded_for": {{ forwarded_for | json }},
"namespace": {{ namespace | json }},
"ingress_name": {{ ingress_name | json }},
"service_name": {{ service_name | json }},
@ -39,7 +41,9 @@ formats:
<message>{{ message }}</message>
<description>{{ description }}</description>{{ if show_details }}
<details>
<host>{{ host }}</host>
<originalURI>{{ original_uri }}</originalURI>
<forwardedFor>{{ forwarded_for }}</forwardedFor>
<namespace>{{ namespace }}</namespace>
<ingressName>{{ ingress_name }}</ingressName>
<serviceName>{{ service_name }}</serviceName>

View File

@ -37,6 +37,8 @@ func RespondWithErrorPage( //nolint:funlen
props.ServiceName = string(ctx.Request.Header.Peek(ServiceName))
props.ServicePort = string(ctx.Request.Header.Peek(ServicePort))
props.RequestID = string(ctx.Request.Header.Peek(RequestID))
props.ForwardedFor = string(ctx.Request.Header.Peek(ForwardedFor))
props.Host = string(ctx.Request.Header.Peek(Host))
}
if page, exists := cfg.Pages[pageCode]; exists {

View File

@ -24,4 +24,10 @@ const (
// RequestID is a unique ID that identifies the request - same as for backend service
RequestID = "X-Request-ID"
// Forward-For identifies the user of this session
ForwardedFor = "X-Forwarded-For"
// Host identifies the hosts origin
Host = "Host"
)

View File

@ -12,6 +12,8 @@ type Properties struct { // only string properties with a "token" tag, please
ServiceName string `token:"service_name"`
ServicePort string `token:"service_port"`
RequestID string `token:"request_id"`
ForwardedFor string `token:"forwarded_for"`
Host string `token:"host"`
ShowRequestDetails bool
}

View File

@ -18,6 +18,8 @@ func TestProperties_Replaces(t *testing.T) {
ServiceName: "ddd",
ServicePort: "eee",
RequestID: "fff",
ForwardedFor:"ggg",
Host: "hhh",
}
r := props.Replaces()
@ -31,6 +33,8 @@ func TestProperties_Replaces(t *testing.T) {
assert.Equal(t, "ddd", r["service_name"])
assert.Equal(t, "eee", r["service_port"])
assert.Equal(t, "fff", r["request_id"])
assert.Equal(t, "ggg", r["forwarded_for"])
assert.Equal(t, "hhh", r["host"])
props.Code, props.Message, props.Description = "", "", ""

View File

@ -62,10 +62,18 @@
{{ if show_details }}
<div class="details">
<table>
{{- if host }}<tr>
<td class="name">Host</td>
<td class="value">{{ host }}</td>
</tr>{{ end -}}
{{- if original_uri }}<tr>
<td class="name">Original URI</td>
<td class="value">{{ original_uri }}</td>
</tr>{{ end -}}
{{- if forwarded_for }}<tr>
<td class="name">Forwarded for</td>
<td class="value">{{ forwarded_for }}</td>
</tr>{{ end -}}
{{- if namespace }}<tr>
<td class="name">Namespace</td>
<td class="value">{{ namespace }}</td>

View File

@ -55,10 +55,18 @@
{{ if show_details }}
<div class="details">
<table>
{{- if host }}<tr>
<td class="name">Host</td>
<td class="value">{{ host }}</td>
</tr>{{ end -}}
{{- if original_uri }}<tr>
<td class="name">Original URI</td>
<td class="value">{{ original_uri }}</td>
</tr>{{ end -}}
{{- if forwarded_for }}<tr>
<td class="name">Forwarded for</td>
<td class="value">{{ forwarded_for }}</td>
</tr>{{ end -}}
{{- if namespace }}<tr>
<td class="name">Namespace</td>
<td class="value">{{ namespace }}</td>

View File

@ -150,7 +150,9 @@
<p class="output">Good luck.</p>
{{ if show_details }}
<div class="details">
{{- if host }}<p class="output small">Host: <code>{{ host }}</code></p>{{ end -}}
{{- if original_uri }}<p class="output small">Original URI: <code>{{ original_uri }}</code></p>{{ end -}}
{{- if forwarded_for }}<p class="output small">Forwarded for: <code>{{ forwarded_for }}</code></p>{{ end -}}
{{- if namespace }}<p class="output small">Namespace: <code>{{ namespace }}</code></p>{{ end -}}
{{- if ingress_name }}<p class="output small">Ingress name: <code>{{ ingress_name }}</code></p>{{ end -}}
{{- if service_name }}<p class="output small">Service name: <code>{{ service_name }}</code></p>{{ end -}}

View File

@ -40,10 +40,18 @@
{{ if show_details }}
<div class="details">
<table>
{{- if host }}<tr>
<td class="name">Host</td>
<td class="value">{{ host }}</td>
</tr>{{ end -}}
{{- if original_uri }}<tr>
<td class="name">Original URI</td>
<td class="value">{{ original_uri }}</td>
</tr>{{ end -}}
{{- if forwarded_for }}<tr>
<td class="name">Forwarded for</td>
<td class="value">{{ forwarded_for }}</td>
</tr>{{ end -}}
{{- if namespace }}<tr>
<td class="name">Namespace</td>
<td class="value">{{ namespace }}</td>

View File

@ -40,10 +40,18 @@
{{ if show_details }}
<div class="details">
<table>
{{- if host }}<tr>
<td class="name">Host</td>
<td class="value">{{ host }}</td>
</tr>{{ end -}}
{{- if original_uri }}<tr>
<td class="name">Original URI</td>
<td class="value">{{ original_uri }}</td>
</tr>{{ end -}}
{{- if forwarded_for }}<tr>
<td class="name">Forwarded for</td>
<td class="value">{{ forwarded_for }}</td>
</tr>{{ end -}}
{{- if namespace }}<tr>
<td class="name">Namespace</td>
<td class="value">{{ namespace }}</td>

View File

@ -76,12 +76,24 @@
{{ if show_details }}
<div class="hidden" id="details">
<table>
{{- if host }}
<tr>
<td class="name">Host:</td>
<td class="value">{{ host }}</td>
</tr>
{{ end -}}
{{- if original_uri }}
<tr>
<td class="name">Original URI:</td>
<td class="value">{{ original_uri }}</td>
</tr>
{{ end -}}
{{- if forwarded_for }}
<tr>
<td class="name">Forwarded for:</td>
<td class="value">{{ forwarded_for }}</td>
</tr>
{{ end -}}
{{- if namespace }}
<tr>
<td class="name">Namespace:</td>

View File

@ -22,6 +22,8 @@ xpath "string(//error/details/ingressName)" == "baz"
xpath "string(//error/details/serviceName)" == "aaa"
xpath "string(//error/details/servicePort)" == "bbb"
xpath "string(//error/details/requestID)" == "ccc"
xpath "string(//error/details/forwardedFor)" == "ddd"
xpath "string(//error/details/host)" == "fff"
xpath "string(//error/details/timestamp)" exists
# X-Format in the action