Skip to content

Commit 93528b6

Browse files
committed
Polishing
Closes gh-31491
1 parent 03d286c commit 93528b6

File tree

3 files changed

+37
-50
lines changed

3 files changed

+37
-50
lines changed

framework-docs/modules/ROOT/pages/web/webflux/reactive-spring.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ include::partial$web/forwarded-headers.adoc[]
372372

373373

374374

375-
[[webflux-forwarded-headers-forwardedheadertransformer]]
375+
[[webflux-forwarded-headers-transformer]]
376376
=== ForwardedHeaderTransformer
377377

378378
`ForwardedHeaderTransformer` is a component that modifies the host, port, and scheme of
@@ -390,7 +390,7 @@ filters, and `ForwardedHeaderTransformer` is used instead.
390390
[[webflux-forwarded-headers-security]]
391391
=== Security Considerations
392392

393-
There are security considerations for forwarded headers, since an application cannot know
393+
There are security considerations for forwarded headers since an application cannot know
394394
if the headers were added by a proxy, as intended, or by a malicious client. This is why
395395
a proxy at the boundary of trust should be configured to remove untrusted forwarded traffic coming
396396
from the outside. You can also configure the `ForwardedHeaderTransformer` with

framework-docs/modules/ROOT/pages/web/webmvc/filters.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ with `removeOnly=true`, in which case it removes but does not use the headers.
5757

5858

5959
[[filters-forwarded-headers-dispatcher]]
60-
=== About Dispatcher Types
60+
=== Dispatcher Types
6161

6262
In order to support xref:web/webmvc/mvc-ann-async.adoc[asynchronous requests] and error dispatches this
6363
filter should be mapped with `DispatcherType.ASYNC` and also `DispatcherType.ERROR`.
Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
As a request goes through proxies (such as load balancers) the host, port, and
1+
As a request goes through proxies such as load balancers the host, port, and
22
scheme may change, and that makes it a challenge to create links that point to the correct
33
host, port, and scheme from a client perspective.
44

@@ -14,7 +14,6 @@ There are other non-standard headers, too, including `X-Forwarded-Host`, `X-Forw
1414
`X-Forwarded-Proto`, `X-Forwarded-Ssl`, and `X-Forwarded-Prefix`.
1515

1616

17-
1817
[[x-forwarded-host]]
1918
==== X-Forwarded-Host
2019

@@ -25,7 +24,6 @@ a proxy which forwards the request to `http://localhost:8080/resource`, then a h
2524
`X-Forwarded-Host: example.com` can be sent to inform the server that the original host was `example.com`.
2625

2726

28-
2927
[[x-forwarded-port]]
3028
==== X-Forwarded-Port
3129

@@ -36,7 +34,6 @@ communicate the original port to a downstream server. For example, if a request
3634
to inform the server that the original port was `443`.
3735

3836

39-
4037
[[x-forwarded-proto]]
4138
==== X-Forwarded-Proto
4239

@@ -47,7 +44,6 @@ a proxy which forwards the request to `http://localhost:8080/resource`, then a h
4744
`X-Forwarded-Proto: https` can be sent to inform the server that the original protocol was `https`.
4845

4946

50-
5147
[[x-forwarded-ssl]]
5248
==== X-Forwarded-Ssl
5349

@@ -58,78 +54,69 @@ original protocol (e.g. https / https) to a downstream server. For example, if a
5854
original protocol was `https`.
5955

6056

61-
6257
[[x-forwarded-prefix]]
6358
==== X-Forwarded-Prefix
6459

6560
While not standard, https://microsoft.github.io/reverse-proxy/articles/transforms.html#defaults[`X-Forwarded-Prefix: <prefix>`]
6661
is a de-facto standard header that is used to communicate the original URL path prefix to a
6762
downstream server.
6863

69-
The definition of the path prefix is most easily defined by an example. For example, consider
70-
the following proxy to server mapping of:
64+
Use of `X-Forwarded-Prefix` can vary by deployment scenario, and needs to be flexible to
65+
allow replacing, removing, or prepending the path prefix of the target server.
66+
67+
_Scenario 1: Override path prefix_
7168

7269
[subs="-attributes"]
7370
----
7471
https://example.com/api/{path} -> http://localhost:8080/app1/{path}
7572
----
7673

77-
The prefix is defined as the porition of the URL path before the capture group of `+{path}+`.
78-
For the proxy, the prefix is `/api` and for the server the prefix is `/app1`. In this case,
79-
the header of `X-Forwarded-Prefix: /api` can be sent to indicate the original prefix of `/api`
80-
which overrides the server's prefix of `/app1`.
74+
The prefix is the start of the path before the capture group `+{path}+`. For the proxy,
75+
the prefix is `/api` while for the server the prefix is `/app1`. In this case, the proxy
76+
can send `X-Forwarded-Prefix: /api` to have the original prefix `/api` override the
77+
server prefix `/app1`.
8178

82-
The `X-Forwarded-Prefix` is flexible because it overrides the existing prefix. This means that
83-
the server prefix can be replaced (as demonstrated above), removed, or modified.
79+
_Scenario 2: Remove path prefix_
8480

85-
The previous example demonstrated how to replace the prefix, but at times users may want to
86-
instruct the server to remove the prefix. For example, consider the proxy to server
87-
mapping of:
81+
At times, an application may want to have the prefix removed. For example, consider the
82+
following proxy to server mapping:
8883

8984
[subs="-attributes"]
9085
----
9186
https://app1.example.com/{path} -> http://localhost:8080/app1/{path}
9287
https://app2.example.com/{path} -> http://localhost:8080/app2/{path}
9388
----
9489

95-
In the `app1` example above, the proxy has an empty prefix and the server has a prefix of
96-
`/app1`. The header of ``X-Forwarded-Prefix: `` can be sent to indicate the original empty
97-
prefix which overrides the server's prefix of `/app1`. In the `app2` example above, the proxy
98-
has an empty prefix and the server has a prefix of `/app2`. The header of ``X-Forwarded-Prefix: ``
99-
can be sent to indicate the original empty prefix which overrides the server's prefix of `/app2`.
90+
The proxy has no prefix, while applications `app1` and `app2` have path prefixes
91+
`/app1` and `/app2` respectively. The proxy can send ``X-Forwarded-Prefix: `` to
92+
have the empty prefix override server prefixes `/app1` and `/app2`.
10093

10194
[NOTE]
10295
====
103-
A common usecase is that an organization pays licenses per production application server.
104-
This means that they prefer to deploy multiple applications to each application server to
105-
avoid paying the licensing fees.
106-
107-
Another common usecase is that organizations may be using more resource intensive
108-
application servers. This means that they prefer to deploy multiple applications to each
109-
application server to avoid consuming additional resources.
110-
111-
In both of these usecases, applications must define a non-empty context root because there is
112-
more than one application associated to the same application server.
113-
114-
While their application is deployed with a non-empty context root, they do not want this
115-
expressed in the path of their URLs because they use a different subdomain for each application.
116-
Using different subdomains for each application provides benefits such as:
117-
118-
* Added security (e.g. same origin policy)
119-
* Allows for scaling the applications differently (a different domain can point to different
120-
IP addresses)
121-
122-
The example above illustrates how to implement such a scenario.
96+
A common case for this deployment scenario is where licenses are paid per
97+
production application server, and it is preferable to deploy multiple applications per
98+
server to reduce fees. Another case is I/O bound applications, and the need to deploy
99+
multiple applications to each application server to consume less resources.
100+
101+
In this scenario, applications need a non-empty context root because there are multiple
102+
applications on the same server. However, this should not be visible in URL paths of
103+
the public API where applications may use different subdomains that provides benefits
104+
such as:
105+
106+
* Added security, e.g. same origin policy
107+
* Independent scaling of applications (different domain points to different IP address)
123108
====
124109

125-
In some cases, a proxy may want to insert a prefix in front of the existing prefix. For
126-
example, consider the proxy to server mapping of:
110+
_Scenario 3: Insert path prefix_
111+
112+
In other cases, it may be necessary to prepend a prefix. For example, consider the
113+
following proxy to server mapping:
127114

128115
[subs="-attributes"]
129116
----
130117
https://example.com/api/app1/{path} -> http://localhost:8080/app1/{path}
131118
----
132119

133-
In the example above, the proxy has a prefix of `/api/app1` and the server has a prefix of
134-
`/app1`. The header of `X-Forwarded-Prefix: /api/app1` can be sent to indicate the original
135-
prefix of `/api/app1` which overrides the server's prefix of `/app1`.
120+
In this case, the proxy has a prefix of `/api/app1` and the server has a prefix of
121+
`/app1`. The proxy can send `X-Forwarded-Prefix: /api/app1` to have the original prefix
122+
`/api/app1` override the server prefix `/app1`.

0 commit comments

Comments
 (0)