Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
c684de9a
Commit
c684de9a
authored
Apr 21, 2017
by
Tw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy: take original URL path into account when remove prefix
fix issue #1604 Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
27785f79
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletion
+11
-1
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+7
-0
caddyhttp/proxy/reverseproxy.go
caddyhttp/proxy/reverseproxy.go
+4
-1
No files found.
caddyhttp/proxy/proxy_test.go
View file @
c684de9a
...
...
@@ -977,6 +977,13 @@ func TestProxyDirectorURL(t *testing.T) {
targetURL
:
`https://localhost:2021/`
,
expectURL
:
`https://localhost:2021/%2F/test`
,
},
{
originalPath
:
`/test///mypath`
,
requestURL
:
`http://localhost:2020/test/%2F/mypath`
,
targetURL
:
`https://localhost:2021/t/`
,
expectURL
:
`https://localhost:2021/t/%2F/mypath`
,
without
:
"/test"
,
},
}
{
targetURL
,
err
:=
url
.
Parse
(
c
.
targetURL
)
if
err
!=
nil
{
...
...
caddyhttp/proxy/reverseproxy.go
View file @
c684de9a
...
...
@@ -121,6 +121,7 @@ func NewSingleHostReverseProxy(target *url.URL, without string, keepalive int) *
}
// We should remove the `without` prefix at first.
untouchedPath
,
_
:=
req
.
Context
()
.
Value
(
staticfiles
.
URLPathCtxKey
)
.
(
string
)
if
without
!=
""
{
req
.
URL
.
Path
=
strings
.
TrimPrefix
(
req
.
URL
.
Path
,
without
)
if
req
.
URL
.
Opaque
!=
""
{
...
...
@@ -129,6 +130,9 @@ func NewSingleHostReverseProxy(target *url.URL, without string, keepalive int) *
if
req
.
URL
.
RawPath
!=
""
{
req
.
URL
.
RawPath
=
strings
.
TrimPrefix
(
req
.
URL
.
RawPath
,
without
)
}
if
untouchedPath
!=
""
{
untouchedPath
=
strings
.
TrimPrefix
(
untouchedPath
,
without
)
}
}
// prefer returns val if it isn't empty, otherwise def
...
...
@@ -155,7 +159,6 @@ func NewSingleHostReverseProxy(target *url.URL, without string, keepalive int) *
prefer
(
target
.
RawPath
,
target
.
Path
),
prefer
(
req
.
URL
.
RawPath
,
req
.
URL
.
Path
))
}
untouchedPath
,
_
:=
req
.
Context
()
.
Value
(
staticfiles
.
URLPathCtxKey
)
.
(
string
)
req
.
URL
.
Path
=
singleJoiningSlash
(
target
.
Path
,
prefer
(
untouchedPath
,
req
.
URL
.
Path
))
// req.URL.Path must be consistent with decoded form of req.URL.RawPath if any
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment