aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/http/request.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2011-09-19 10:22:53 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2011-09-19 10:22:53 -0700
commit6b6cb725e99da3bf74be53489521636ee8ee4798 (patch)
treee253b7ac4dcc5d626bc8106fe6b233b5f7f2c8cb /src/pkg/http/request.go
parent24257a1ea2bee3f16efd6a154e87f02fccaf0ef2 (diff)
downloadgo-6b6cb725e99da3bf74be53489521636ee8ee4798.tar.xz
http: prevent DumpRequest from adding implicit headers
Fixes #2272 R=rsc CC=golang-dev https://golang.org/cl/5043051
Diffstat (limited to 'src/pkg/http/request.go')
-rw-r--r--src/pkg/http/request.go56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go
index ed4114b549..dc344ca005 100644
--- a/src/pkg/http/request.go
+++ b/src/pkg/http/request.go
@@ -64,13 +64,20 @@ func (e *badStringError) String() string { return fmt.Sprintf("%s %q", e.what, e
// Headers that Request.Write handles itself and should be skipped.
var reqWriteExcludeHeader = map[string]bool{
- "Host": true,
+ "Host": true, // not in Header map anyway
"User-Agent": true,
"Content-Length": true,
"Transfer-Encoding": true,
"Trailer": true,
}
+var reqWriteExcludeHeaderDump = map[string]bool{
+ "Host": true, // not in Header map anyway
+ "Content-Length": true,
+ "Transfer-Encoding": true,
+ "Trailer": true,
+}
+
// A Request represents a parsed HTTP request header.
type Request struct {
Method string // GET, POST, PUT, etc.
@@ -283,6 +290,53 @@ func (req *Request) WriteProxy(w io.Writer) os.Error {
return req.write(w, true)
}
+func (req *Request) dumpWrite(w io.Writer) os.Error {
+ urlStr := req.RawURL
+ if urlStr == "" {
+ urlStr = valueOrDefault(req.URL.EncodedPath(), "/")
+ if req.URL.RawQuery != "" {
+ urlStr += "?" + req.URL.RawQuery
+ }
+ }
+
+ bw := bufio.NewWriter(w)
+ fmt.Fprintf(bw, "%s %s HTTP/%d.%d\r\n", valueOrDefault(req.Method, "GET"), urlStr,
+ req.ProtoMajor, req.ProtoMinor)
+
+ host := req.Host
+ if host == "" && req.URL != nil {
+ host = req.URL.Host
+ }
+ if host != "" {
+ fmt.Fprintf(bw, "Host: %s\r\n", host)
+ }
+
+ // Process Body,ContentLength,Close,Trailer
+ tw, err := newTransferWriter(req)
+ if err != nil {
+ return err
+ }
+ err = tw.WriteHeader(bw)
+ if err != nil {
+ return err
+ }
+
+ err = req.Header.WriteSubset(bw, reqWriteExcludeHeaderDump)
+ if err != nil {
+ return err
+ }
+
+ io.WriteString(bw, "\r\n")
+
+ // Write body and trailer
+ err = tw.WriteBody(bw)
+ if err != nil {
+ return err
+ }
+ bw.Flush()
+ return nil
+}
+
func (req *Request) write(w io.Writer, usingProxy bool) os.Error {
host := req.Host
if host == "" {