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
6fe5c1a6
Commit
6fe5c1a6
authored
Jun 16, 2016
by
Pedro Nasser
Committed by
GitHub
Jun 16, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #885 from pedronasser/master
Fix rewrite bug with URL query + test case (#884)
parents
0f1e5bce
54355d8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
caddyhttp/rewrite/to.go
caddyhttp/rewrite/to.go
+10
-3
caddyhttp/rewrite/to_test.go
caddyhttp/rewrite/to_test.go
+1
-0
No files found.
caddyhttp/rewrite/to.go
View file @
6fe5c1a6
...
...
@@ -18,8 +18,15 @@ func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Repl
// try each rewrite paths
t
:=
""
query
:=
""
for
_
,
v
:=
range
tos
{
t
=
path
.
Clean
(
replacer
.
Replace
(
v
))
t
=
replacer
.
Replace
(
v
)
tparts
:=
strings
.
SplitN
(
t
,
"?"
,
2
)
t
=
path
.
Clean
(
tparts
[
0
])
if
len
(
tparts
)
>
1
{
query
=
tparts
[
1
]
}
// add trailing slash for directories, if present
if
strings
.
HasSuffix
(
v
,
"/"
)
&&
!
strings
.
HasSuffix
(
t
,
"/"
)
{
...
...
@@ -47,9 +54,9 @@ func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Repl
// perform rewrite
r
.
URL
.
Path
=
u
.
Path
if
u
.
RawQ
uery
!=
""
{
if
q
uery
!=
""
{
// overwrite query string if present
r
.
URL
.
RawQuery
=
u
.
RawQ
uery
r
.
URL
.
RawQuery
=
q
uery
}
if
u
.
Fragment
!=
""
{
// overwrite fragment if present
...
...
caddyhttp/rewrite/to_test.go
View file @
6fe5c1a6
...
...
@@ -22,6 +22,7 @@ func TestTo(t *testing.T) {
{
"/?a=b"
,
"/testfile /index.php?{query}"
,
"/testfile?a=b"
},
{
"/?a=b"
,
"/testdir /index.php?{query}"
,
"/index.php?a=b"
},
{
"/?a=b"
,
"/testdir/ /index.php?{query}"
,
"/testdir/?a=b"
},
{
"/test?url=http://caddyserver.com"
,
" /p/{path}?{query}"
,
"/p/test?url=http://caddyserver.com"
},
}
uri
:=
func
(
r
*
url
.
URL
)
string
{
...
...
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