Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
8b29f158
Commit
8b29f158
authored
Apr 21, 2013
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/http: fix a panic in Redirect
R=golang-dev, dsymonds, r CC=golang-dev
https://golang.org/cl/8721045
parent
782a5781
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
16 deletions
+25
-16
client_test.go
src/pkg/net/http/client_test.go
+1
-1
server.go
src/pkg/net/http/server.go
+2
-2
server_test.go
src/pkg/net/http/server_test.go
+22
-13
No files found.
src/pkg/net/http/client_test.go
View file @
8b29f158
...
...
@@ -180,7 +180,7 @@ func TestPostFormRequestFormat(t *testing.T) {
}
}
func
TestRedirects
(
t
*
testing
.
T
)
{
func
Test
Client
Redirects
(
t
*
testing
.
T
)
{
defer
afterTest
(
t
)
var
ts
*
httptest
.
Server
ts
=
httptest
.
NewServer
(
HandlerFunc
(
func
(
w
ResponseWriter
,
r
*
Request
)
{
...
...
src/pkg/net/http/server.go
View file @
8b29f158
...
...
@@ -1222,9 +1222,9 @@ func Redirect(w ResponseWriter, r *Request, urlStr string, code int) {
}
// clean up but preserve trailing slash
trailing
:=
urlStr
[
len
(
urlStr
)
-
1
]
==
'/'
trailing
:=
strings
.
HasSuffix
(
urlStr
,
"/"
)
urlStr
=
path
.
Clean
(
urlStr
)
if
trailing
&&
urlStr
[
len
(
urlStr
)
-
1
]
!=
'/'
{
if
trailing
&&
!
strings
.
HasSuffix
(
urlStr
,
"/"
)
{
urlStr
+=
"/"
}
urlStr
+=
query
...
...
src/pkg/net/http/server_test.go
View file @
8b29f158
...
...
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
http
package
http
_test
import
(
.
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
...
...
@@ -76,20 +78,27 @@ func TestServeMuxHandler(t *testing.T) {
},
}
h
,
pattern
:=
mux
.
Handler
(
r
)
cs
:=
&
codeSaver
{
h
:
Header
{}}
h
.
ServeHTTP
(
cs
,
r
)
if
pattern
!=
tt
.
pattern
||
cs
.
c
ode
!=
tt
.
code
{
t
.
Errorf
(
"%s %s %s = %d, %q, want %d, %q"
,
tt
.
method
,
tt
.
host
,
tt
.
path
,
cs
.
c
ode
,
pattern
,
tt
.
code
,
tt
.
pattern
)
rr
:=
httptest
.
NewRecorder
()
h
.
ServeHTTP
(
rr
,
r
)
if
pattern
!=
tt
.
pattern
||
rr
.
C
ode
!=
tt
.
code
{
t
.
Errorf
(
"%s %s %s = %d, %q, want %d, %q"
,
tt
.
method
,
tt
.
host
,
tt
.
path
,
rr
.
C
ode
,
pattern
,
tt
.
code
,
tt
.
pattern
)
}
}
}
// A codeSaver is a ResponseWriter that saves the code passed to WriteHeader.
type
codeSaver
struct
{
h
Header
code
int
func
TestServerRedirect
(
t
*
testing
.
T
)
{
// This used to crash. It's not valid input (bad path), but it
// shouldn't crash.
rr
:=
httptest
.
NewRecorder
()
req
:=
&
Request
{
Method
:
"GET"
,
URL
:
&
url
.
URL
{
Scheme
:
"http"
,
Path
:
"not-empty-but-no-leading-slash"
,
// bogus
},
}
Redirect
(
rr
,
req
,
""
,
304
)
if
rr
.
Code
!=
304
{
t
.
Errorf
(
"Code = %d; want 304"
,
rr
.
Code
)
}
}
func
(
cs
*
codeSaver
)
Header
()
Header
{
return
cs
.
h
}
func
(
cs
*
codeSaver
)
Write
(
p
[]
byte
)
(
int
,
error
)
{
return
len
(
p
),
nil
}
func
(
cs
*
codeSaver
)
WriteHeader
(
code
int
)
{
cs
.
code
=
code
}
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