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

« back to all changes in this revision

Viewing changes to src/pkg/http/cgi/host.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import (
18
18
        "bufio"
19
 
        "bytes"
20
19
        "exec"
21
20
        "fmt"
22
21
        "http"
47
46
        Path string // path to the CGI executable
48
47
        Root string // root URI prefix of handler or empty for "/"
49
48
 
 
49
        // Dir specifies the CGI executable's working directory.
 
50
        // If Dir is empty, the base directory of Path is used.
 
51
        // If Path has no base directory, the current working
 
52
        // directory is used.
 
53
        Dir string
 
54
 
50
55
        Env        []string    // extra environment variables to set, if any, as "key=value"
51
56
        InheritEnv []string    // environment variables to inherit from host, as "key"
52
57
        Logger     *log.Logger // optional log for errors or nil to use log.Print
106
111
                env = append(env, "HTTPS=on")
107
112
        }
108
113
 
109
 
        if len(req.Cookie) > 0 {
110
 
                b := new(bytes.Buffer)
111
 
                for idx, c := range req.Cookie {
112
 
                        if idx > 0 {
113
 
                                b.Write([]byte("; "))
114
 
                        }
115
 
                        fmt.Fprintf(b, "%s=%s", c.Name, c.Value)
116
 
                }
117
 
                env = append(env, "HTTP_COOKIE="+b.String())
118
 
        }
119
 
 
120
114
        for k, v := range req.Header {
121
115
                k = strings.Map(upperCaseAndUnderscore, k)
122
 
                env = append(env, "HTTP_"+k+"="+strings.Join(v, ", "))
 
116
                joinStr := ", "
 
117
                if k == "COOKIE" {
 
118
                        joinStr = "; "
 
119
                }
 
120
                env = append(env, "HTTP_"+k+"="+strings.Join(v, joinStr))
123
121
        }
124
122
 
125
123
        if req.ContentLength > 0 {
133
131
                env = append(env, h.Env...)
134
132
        }
135
133
 
136
 
        path := os.Getenv("PATH")
137
 
        if path == "" {
138
 
                path = "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
 
134
        envPath := os.Getenv("PATH")
 
135
        if envPath == "" {
 
136
                envPath = "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
139
137
        }
140
 
        env = append(env, "PATH="+path)
 
138
        env = append(env, "PATH="+envPath)
141
139
 
142
140
        for _, e := range h.InheritEnv {
143
141
                if v := os.Getenv(e); v != "" {
151
149
                }
152
150
        }
153
151
 
154
 
        cwd, pathBase := filepath.Split(h.Path)
 
152
        var cwd, path string
 
153
        if h.Dir != "" {
 
154
                path = h.Path
 
155
                cwd = h.Dir
 
156
        } else {
 
157
                cwd, path = filepath.Split(h.Path)
 
158
        }
155
159
        if cwd == "" {
156
160
                cwd = "."
157
161
        }
162
166
        }
163
167
 
164
168
        cmd := &exec.Cmd{
165
 
                Path:   pathBase,
 
169
                Path:   path,
166
170
                Args:   append([]string{h.Path}, h.Args...),
167
171
                Dir:    cwd,
168
172
                Env:    env,
205
209
                if len(line) == 0 {
206
210
                        break
207
211
                }
208
 
                parts := strings.Split(string(line), ":", 2)
 
212
                parts := strings.SplitN(string(line), ":", 2)
209
213
                if len(parts) < 2 {
210
214
                        h.printf("cgi: bogus header line: %s", string(line))
211
215
                        continue