mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
Adds "Host" and "X-Forwarded-For" header options (#61)
This commit is contained in:
parent
da2dc5c63a
commit
42523ae9d9
@ -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
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 = "", "", ""
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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 -}}
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user