~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/fix/httpheaders.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2011 The Go Authors.  All rights reserved.
2
 
// Use of this source code is governed by a BSD-style
3
 
// license that can be found in the LICENSE file.
4
 
 
5
 
package main
6
 
 
7
 
import (
8
 
        "go/ast"
9
 
)
10
 
 
11
 
func init() {
12
 
        register(httpHeadersFix)
13
 
}
14
 
 
15
 
var httpHeadersFix = fix{
16
 
        "httpheaders",
17
 
        "2011-06-16",
18
 
        httpheaders,
19
 
        `Rename http Referer, UserAgent, Cookie, SetCookie, which are now methods.
20
 
 
21
 
http://codereview.appspot.com/4620049/
22
 
`,
23
 
}
24
 
 
25
 
func httpheaders(f *ast.File) bool {
26
 
        if !imports(f, "http") {
27
 
                return false
28
 
        }
29
 
 
30
 
        called := make(map[ast.Node]bool)
31
 
        walk(f, func(ni interface{}) {
32
 
                switch n := ni.(type) {
33
 
                case *ast.CallExpr:
34
 
                        called[n.Fun] = true
35
 
                }
36
 
        })
37
 
 
38
 
        fixed := false
39
 
        typeof, _ := typecheck(headerTypeConfig, f)
40
 
        walk(f, func(ni interface{}) {
41
 
                switch n := ni.(type) {
42
 
                case *ast.SelectorExpr:
43
 
                        if called[n] {
44
 
                                break
45
 
                        }
46
 
                        if t := typeof[n.X]; t != "*http.Request" && t != "*http.Response" {
47
 
                                break
48
 
                        }
49
 
                        switch n.Sel.Name {
50
 
                        case "Referer", "UserAgent":
51
 
                                n.Sel.Name += "()"
52
 
                                fixed = true
53
 
                        case "Cookie":
54
 
                                n.Sel.Name = "Cookies()"
55
 
                                fixed = true
56
 
                        }
57
 
                }
58
 
        })
59
 
        return fixed
60
 
}
61
 
 
62
 
var headerTypeConfig = &TypeConfig{
63
 
        Type: map[string]*Type{
64
 
                "*http.Request":  {},
65
 
                "*http.Response": {},
66
 
        },
67
 
}