Skip to content

Commit 36c4ac8

Browse files
committed
Update for release 60
1 parent 111463f commit 36c4ac8

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

cookie.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sort"
1414
"strings"
1515
"time"
16+
"url"
1617
)
1718

1819
func sanitizeName(n string) string {
@@ -89,10 +90,10 @@ func writeSetCookies(w io.Writer, kk []*http.Cookie) os.Error {
8990
// TODO(petar): c.Value (below) should be unquoted if it is recognized as quoted
9091
fmt.Fprintf(&b, "%s=%s", http.CanonicalHeaderKey(c.Name), c.Value)
9192
if len(c.Path) > 0 {
92-
fmt.Fprintf(&b, "; Path=%s", http.URLEscape(c.Path))
93+
fmt.Fprintf(&b, "; Path=%s", url.QueryEscape(c.Path))
9394
}
9495
if len(c.Domain) > 0 {
95-
fmt.Fprintf(&b, "; Domain=%s", http.URLEscape(c.Domain))
96+
fmt.Fprintf(&b, "; Domain=%s", url.QueryEscape(c.Domain))
9697
}
9798
if len(c.Expires.Zone) > 0 {
9899
fmt.Fprintf(&b, "; Expires=%s", c.Expires.Format(time.RFC1123))
@@ -130,10 +131,10 @@ func writeCookies(w io.Writer, kk []*http.Cookie) os.Error {
130131
// TODO(petar): c.Value (below) should be unquoted if it is recognized as quoted
131132
fmt.Fprintf(&b, "%s=%s", http.CanonicalHeaderKey(n), c.Value)
132133
if len(c.Path) > 0 {
133-
fmt.Fprintf(&b, "; $Path=%s", http.URLEscape(c.Path))
134+
fmt.Fprintf(&b, "; $Path=%s", url.QueryEscape(c.Path))
134135
}
135136
if len(c.Domain) > 0 {
136-
fmt.Fprintf(&b, "; $Domain=%s", http.URLEscape(c.Domain))
137+
fmt.Fprintf(&b, "; $Domain=%s", url.QueryEscape(c.Domain))
137138
}
138139
if c.HttpOnly {
139140
fmt.Fprintf(&b, "; $HttpOnly")
@@ -178,7 +179,7 @@ func readCookies(h http.Header) []*http.Cookie {
178179
var err os.Error
179180
if j := strings.Index(attr, "="); j >= 0 {
180181
attr, val = attr[:j], attr[j+1:]
181-
val, err = http.URLUnescape(val)
182+
val, err = url.QueryUnescape(val)
182183
if err != nil {
183184
continue
184185
}

examples/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include $(GOROOT)/src/Make.inc
22

3-
ALL=hello arcchallenge multipart multiserver params logger methodhandler
3+
ALL=hello arcchallenge multipart multiserver params logger
44

55
all: $(ALL)
66

request.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"reflect"
1515
"strconv"
1616
"strings"
17+
"url"
1718
)
1819

1920
type filedata struct {
@@ -22,12 +23,12 @@ type filedata struct {
2223
}
2324

2425
type Request struct {
25-
Method string // GET, POST, PUT, etc.
26-
RawURL string // The raw URL given in the request.
27-
URL *http.URL // Parsed URL.
28-
Proto string // "HTTP/1.0"
29-
ProtoMajor int // 1
30-
ProtoMinor int // 0
26+
Method string // GET, POST, PUT, etc.
27+
RawURL string // The raw URL given in the request.
28+
URL *url.URL // Parsed URL.
29+
Proto string // "HTTP/1.0"
30+
ProtoMajor int // 1
31+
ProtoMinor int // 0
3132
Headers http.Header
3233
Body io.Reader
3334
Close bool
@@ -44,7 +45,6 @@ type Request struct {
4445
RemotePort int
4546
}
4647

47-
4848
type badStringError struct {
4949
what string
5050
str string
@@ -104,7 +104,7 @@ func newRequestCgi(headers http.Header, body io.Reader) *Request {
104104
port := headers.Get("SERVER_PORT")
105105
proto := headers.Get("SERVER_PROTOCOL")
106106
rawurl := "http://" + host + ":" + port + path
107-
url, _ := http.ParseURL(rawurl)
107+
url_, _ := url.Parse(rawurl)
108108
useragent := headers.Get("USER_AGENT")
109109
remoteAddr := headers.Get("REMOTE_ADDR")
110110
remotePort, _ := strconv.Atoi(headers.Get("REMOTE_PORT"))
@@ -125,7 +125,7 @@ func newRequestCgi(headers http.Header, body io.Reader) *Request {
125125
req := Request{
126126
Method: method,
127127
RawURL: rawurl,
128-
URL: url,
128+
URL: url_,
129129
Proto: proto,
130130
Host: host,
131131
UserAgent: useragent,
@@ -146,9 +146,9 @@ func parseForm(m map[string][]string, query string) (err os.Error) {
146146

147147
var key, value string
148148
var e os.Error
149-
key, e = http.URLUnescape(kvPair[0])
149+
key, e = url.QueryUnescape(kvPair[0])
150150
if e == nil && len(kvPair) > 1 {
151-
value, e = http.URLUnescape(kvPair[1])
151+
value, e = url.QueryUnescape(kvPair[1])
152152
}
153153
if e != nil {
154154
err = e
@@ -355,7 +355,6 @@ func (r *Request) writeToContainer(val reflect.Value) os.Error {
355355
return nil
356356
}
357357

358-
359358
func (r *Request) UnmarshalParams(val interface{}) os.Error {
360359
if strings.HasPrefix(r.Headers.Get("Content-Type"), "application/json") {
361360
return json.Unmarshal(r.ParamData, val)

web.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"strconv"
2121
"strings"
2222
"time"
23+
"url"
2324
)
2425

2526
type conn interface {
@@ -62,10 +63,10 @@ func (ctx *Context) Abort(status int, body string) {
6263
ctx.WriteString(body)
6364
}
6465

65-
func (ctx *Context) Redirect(status int, url string) {
66-
ctx.SetHeader("Location", url, true)
66+
func (ctx *Context) Redirect(status int, url_ string) {
67+
ctx.SetHeader("Location", url_, true)
6768
ctx.StartResponse(status)
68-
ctx.WriteString("Redirecting to: " + url)
69+
ctx.WriteString("Redirecting to: " + url_)
6970
}
7071

7172
func (ctx *Context) NotModified() {
@@ -574,9 +575,9 @@ func fileExists(dir string) bool {
574575
func Urlencode(data map[string]string) string {
575576
var buf bytes.Buffer
576577
for k, v := range data {
577-
buf.WriteString(http.URLEscape(k))
578+
buf.WriteString(url.QueryEscape(k))
578579
buf.WriteByte('=')
579-
buf.WriteString(http.URLEscape(v))
580+
buf.WriteString(url.QueryEscape(v))
580581
buf.WriteByte('&')
581582
}
582583
s := buf.String()

web_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strconv"
1313
"strings"
1414
"testing"
15+
"url"
1516
)
1617

1718
func init() {
@@ -107,7 +108,6 @@ type StructHandler struct {
107108
a string
108109
}
109110

110-
111111
func (s *StructHandler) method() string {
112112
return s.a
113113
}
@@ -210,7 +210,7 @@ func buildTestRequest(method string, path string, body string, headers map[strin
210210
host := "127.0.0.1"
211211
port := "80"
212212
rawurl := "http://" + host + ":" + port + path
213-
url, _ := http.ParseURL(rawurl)
213+
url_, _ := url.Parse(rawurl)
214214

215215
proto := "HTTP/1.1"
216216
useragent := "web.go test framework"
@@ -227,7 +227,7 @@ func buildTestRequest(method string, path string, body string, headers map[strin
227227
req := Request{Method: method,
228228
RawURL: rawurl,
229229
Cookie: cookies,
230-
URL: url,
230+
URL: url_,
231231
Proto: proto,
232232
Host: host,
233233
UserAgent: useragent,
@@ -415,7 +415,6 @@ func TestScgiHead(t *testing.T) {
415415
}
416416
}
417417

418-
419418
func buildFcgiKeyValue(key string, val string) []byte {
420419

421420
var buf bytes.Buffer
@@ -634,7 +633,6 @@ func TestSecureCookie(t *testing.T) {
634633
}
635634
}
636635

637-
638636
func TestSecureCookieFcgi(t *testing.T) {
639637
mainServer.Config.CookieSecret = "7C19QRmwf3mHZ9CPAaPQ0hsWeufKd"
640638

0 commit comments

Comments
 (0)