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
Łukasz Nowak
caddy
Commits
f9b6ede9
Commit
f9b6ede9
authored
Feb 01, 2016
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #543 from DenBeke/master
fastcgi: IPv6 when parsing r.RemoteAddr
parents
184abe3b
c59fd1c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
1 deletion
+65
-1
middleware/fastcgi/fastcgi.go
middleware/fastcgi/fastcgi.go
+1
-1
middleware/fastcgi/fastcgi_test.go
middleware/fastcgi/fastcgi_test.go
+64
-0
No files found.
middleware/fastcgi/fastcgi.go
View file @
f9b6ede9
...
...
@@ -182,7 +182,7 @@ func (h Handler) buildEnv(r *http.Request, rule Rule, fpath string) (map[string]
// Separate remote IP and port; more lenient than net.SplitHostPort
var
ip
,
port
string
if
idx
:=
strings
.
Index
(
r
.
RemoteAddr
,
":"
);
idx
>
-
1
{
if
idx
:=
strings
.
Last
Index
(
r
.
RemoteAddr
,
":"
);
idx
>
-
1
{
ip
=
r
.
RemoteAddr
[
:
idx
]
port
=
r
.
RemoteAddr
[
idx
+
1
:
]
}
else
{
...
...
middleware/fastcgi/fastcgi_test.go
View file @
f9b6ede9
package
fastcgi
import
(
"net/http"
"net/url"
"testing"
)
...
...
@@ -29,3 +31,65 @@ func TestRuleParseAddress(t *testing.T) {
}
}
func
TestBuildEnv
(
t
*
testing
.
T
)
{
buildEnvSingle
:=
func
(
r
*
http
.
Request
,
rule
Rule
,
fpath
string
,
envExpected
map
[
string
]
string
,
t
*
testing
.
T
)
{
h
:=
Handler
{}
env
,
err
:=
h
.
buildEnv
(
r
,
rule
,
fpath
)
if
err
!=
nil
{
t
.
Error
(
"Unexpected error:"
,
err
.
Error
())
}
for
k
,
v
:=
range
envExpected
{
if
env
[
k
]
!=
v
{
t
.
Errorf
(
"Unexpected %v. Got %v, expected %v"
,
k
,
env
[
k
],
v
)
}
}
}
rule
:=
Rule
{}
url
,
err
:=
url
.
Parse
(
"http://localhost:2015/fgci_test.php?test=blabla"
)
if
err
!=
nil
{
t
.
Error
(
"Unexpected error:"
,
err
.
Error
())
}
r
:=
http
.
Request
{
Method
:
"GET"
,
URL
:
url
,
Proto
:
"HTTP/1.1"
,
ProtoMajor
:
1
,
ProtoMinor
:
1
,
Host
:
"localhost:2015"
,
RemoteAddr
:
"[2b02:1810:4f2d:9400:70ab:f822:be8a:9093]:51688"
,
RequestURI
:
"/fgci_test.php"
,
}
fpath
:=
"/fgci_test.php"
var
envExpected
=
map
[
string
]
string
{
"REMOTE_ADDR"
:
"[2b02:1810:4f2d:9400:70ab:f822:be8a:9093]"
,
"REMOTE_PORT"
:
"51688"
,
"SERVER_PROTOCOL"
:
"HTTP/1.1"
,
"QUERY_STRING"
:
"test=blabla"
,
"REQUEST_METHOD"
:
"GET"
,
"HTTP_HOST"
:
"localhost:2015"
,
}
// 1. Test for full canonical IPv6 address
buildEnvSingle
(
&
r
,
rule
,
fpath
,
envExpected
,
t
)
// 2. Test for shorthand notation of IPv6 address
r
.
RemoteAddr
=
"[::1]:51688"
envExpected
[
"REMOTE_ADDR"
]
=
"[::1]"
buildEnvSingle
(
&
r
,
rule
,
fpath
,
envExpected
,
t
)
// 3. Test for IPv4 address
r
.
RemoteAddr
=
"192.168.0.10:51688"
envExpected
[
"REMOTE_ADDR"
]
=
"192.168.0.10"
buildEnvSingle
(
&
r
,
rule
,
fpath
,
envExpected
,
t
)
}
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