Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Kirill Smelkov
go
Commits
4bd0a544
Commit
4bd0a544
authored
Mar 17, 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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
src/cmd/gofix/httpserver.go
src/cmd/gofix/httpserver.go
+16
-1
src/cmd/gofix/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