Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(154)

Unified Diff: src/pkg/http/request.go

Issue 833044: code review 833044: simplify various code using new map index rule (Closed)
Patch Set: code review 833044: simplify various code using new map index rule Created 15 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/gob/type.go ('k') | src/pkg/http/response.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/http/request.go
===================================================================
--- a/src/pkg/http/request.go
+++ b/src/pkg/http/request.go
@@ -49,13 +49,13 @@
func (e *badStringError) String() string { return fmt.Sprintf("%s %q", e.what, e.str) }
-var reqExcludeHeader = map[string]int{
- "Host": 0,
- "User-Agent": 0,
- "Referer": 0,
- "Content-Length": 0,
- "Transfer-Encoding": 0,
- "Trailer": 0,
+var reqExcludeHeader = map[string]bool{
+ "Host": true,
+ "User-Agent": true,
+ "Referer": true,
+ "Content-Length": true,
+ "Transfer-Encoding": true,
+ "Trailer": true,
}
// A Request represents a parsed HTTP request header.
@@ -518,24 +518,19 @@
// Host: doesntmatter
// the same. In the second case, any Host line is ignored.
req.Host = req.URL.Host
- if v, present := req.Header["Host"]; present {
- if req.Host == "" {
- req.Host = v
- }
- req.Header["Host"] = "", false
+ if req.Host == "" {
+ req.Host = req.Header["Host"]
}
+ req.Header["Host"] = "", false
fixPragmaCacheControl(req.Header)
// Pull out useful fields as a convenience to clients.
- if v, present := req.Header["Referer"]; present {
- req.Referer = v
- req.Header["Referer"] = "", false
- }
- if v, present := req.Header["User-Agent"]; present {
- req.UserAgent = v
- req.Header["User-Agent"] = "", false
- }
+ req.Referer = req.Header["Referer"]
+ req.Header["Referer"] = "", false
+
+ req.UserAgent = req.Header["User-Agent"]
+ req.Header["User-Agent"] = "", false
// TODO: Parse specific header values:
// Accept
@@ -572,7 +567,7 @@
}
func ParseQuery(query string) (m map[string][]string, err os.Error) {
- data := make(map[string]*vector.StringVector)
+ m = make(map[string][]string)
for _, kv := range strings.Split(query, "&", 0) {
kvPair := strings.Split(kv, "=", 2)
@@ -586,17 +581,9 @@
err = e
}
- vec, ok := data[key]
- if !ok {
- vec = new(vector.StringVector)
- data[key] = vec
- }
+ vec := vector.StringVector(m[key])
vec.Push(value)
- }
-
- m = make(map[string][]string)
- for k, vec := range data {
- m[k] = vec.Data()
+ m[key] = vec
}
return
@@ -618,7 +605,7 @@
r.Form = make(map[string][]string)
return os.ErrorString("missing form body")
}
- ct, _ := r.Header["Content-Type"]
+ ct := r.Header["Content-Type"]
switch strings.Split(ct, ";", 2)[0] {
case "text/plain", "application/x-www-form-urlencoded", "":
var b []byte
@@ -643,7 +630,7 @@
if r.Form == nil {
r.ParseForm()
}
- if vs, ok := r.Form[key]; ok && len(vs) > 0 {
+ if vs := r.Form[key]; len(vs) > 0 {
return vs[0]
}
return ""
« no previous file with comments | « src/pkg/gob/type.go ('k') | src/pkg/http/response.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b