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
4bd0a544
Commit
4bd0a544
authored
Mar 16, 2011
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofix: httpserver - rewrite rw.SetHeader to rw.Header.Set
R=rsc CC=golang-dev
https://golang.org/cl/4271048
parent
5dd0869b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
httpserver.go
src/cmd/gofix/httpserver.go
+16
-1
httpserver_test.go
src/cmd/gofix/httpserver_test.go
+4
-0
No files found.
src/cmd/gofix/httpserver.go
View file @
4bd0a544
...
...
@@ -51,7 +51,7 @@ func httpserver(f *ast.File) bool {
// Look for w.UsingTLS() and w.Remoteaddr().
call
,
ok
:=
n
.
(
*
ast
.
CallExpr
)
if
!
ok
||
len
(
call
.
Args
)
!=
0
{
if
!
ok
||
(
len
(
call
.
Args
)
!=
0
&&
len
(
call
.
Args
)
!=
2
)
{
return
}
sel
,
ok
:=
call
.
Fun
.
(
*
ast
.
SelectorExpr
)
...
...
@@ -102,6 +102,21 @@ func httpserver(f *ast.File) bool {
Sel
:
ast
.
NewIdent
(
"RemoteAddr"
),
}
fixed
=
true
case
"SetHeader"
:
// replace w.SetHeader with w.Header().Set
// or w.Header().Del if second argument is ""
sel
.
X
=
&
ast
.
CallExpr
{
Fun
:
&
ast
.
SelectorExpr
{
X
:
ast
.
NewIdent
(
w
.
String
()),
Sel
:
ast
.
NewIdent
(
"Header"
),
},
}
sel
.
Sel
=
ast
.
NewIdent
(
"Set"
)
if
len
(
call
.
Args
)
==
2
&&
isEmptyString
(
call
.
Args
[
1
])
{
sel
.
Sel
=
ast
.
NewIdent
(
"Del"
)
call
.
Args
=
call
.
Args
[
:
1
]
}
fixed
=
true
}
})
}
...
...
src/cmd/gofix/httpserver_test.go
View file @
4bd0a544
...
...
@@ -16,6 +16,8 @@ var httpserverTests = []testCase{
import "http"
func f(xyz http.ResponseWriter, abc *http.Request, b string) {
xyz.SetHeader("foo", "bar")
xyz.SetHeader("baz", "")
xyz.Hijack()
xyz.Flush()
go xyz.Hijack()
...
...
@@ -33,6 +35,8 @@ func f(xyz http.ResponseWriter, abc *http.Request, b string) {
import "http"
func f(xyz http.ResponseWriter, abc *http.Request, b string) {
xyz.Header().Set("foo", "bar")
xyz.Header().Del("baz")
xyz.(http.Hijacker).Hijack()
xyz.(http.Flusher).Flush()
go xyz.(http.Hijacker).Hijack()
...
...
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