Skip to content

Commit

Permalink
Updates for Go r.59
Browse files Browse the repository at this point in the history
  • Loading branch information
kpumuk committed Aug 3, 2011
1 parent 9e4be1f commit 111463f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cookie.go
Expand Up @@ -108,7 +108,7 @@ func writeSetCookies(w io.Writer, kk []*http.Cookie) os.Error {
} }
lines = append(lines, "Set-Cookie: "+b.String()+"\r\n") lines = append(lines, "Set-Cookie: "+b.String()+"\r\n")
} }
sort.SortStrings(lines) sort.Strings(lines)
for _, l := range lines { for _, l := range lines {
if _, err := io.WriteString(w, l); err != nil { if _, err := io.WriteString(w, l); err != nil {
return err return err
Expand Down Expand Up @@ -140,7 +140,7 @@ func writeCookies(w io.Writer, kk []*http.Cookie) os.Error {
} }
lines = append(lines, "Cookie: "+b.String()+"\r\n") lines = append(lines, "Cookie: "+b.String()+"\r\n")
} }
sort.SortStrings(lines) sort.Strings(lines)
for _, l := range lines { for _, l := range lines {
if _, err := io.WriteString(w, l); err != nil { if _, err := io.WriteString(w, l); err != nil {
return err return err
Expand All @@ -160,7 +160,7 @@ func readCookies(h http.Header) []*http.Cookie {
} }
unparsedLines := []string{} unparsedLines := []string{}
for _, line := range lines { for _, line := range lines {
parts := strings.Split(strings.TrimSpace(line), ";", -1) parts := strings.Split(strings.TrimSpace(line), ";")
if len(parts) == 1 && parts[0] == "" { if len(parts) == 1 && parts[0] == "" {
continue continue
} }
Expand Down
12 changes: 6 additions & 6 deletions request.go
Expand Up @@ -77,10 +77,10 @@ func newRequest(hr *http.Request, hc http.ResponseWriter) *Request {
Body: hr.Body, Body: hr.Body,
Close: hr.Close, Close: hr.Close,
Host: hr.Host, Host: hr.Host,
Referer: hr.Referer, Referer: hr.Referer(),
UserAgent: hr.UserAgent, UserAgent: hr.UserAgent(),
FullParams: hr.Form, FullParams: hr.Form,
Cookie: hr.Cookie, Cookie: hr.Cookies(),
RemoteAddr: remoteAddr.IP.String(), RemoteAddr: remoteAddr.IP.String(),
RemotePort: remoteAddr.Port, RemotePort: remoteAddr.Port,
} }
Expand Down Expand Up @@ -141,8 +141,8 @@ func newRequestCgi(headers http.Header, body io.Reader) *Request {


func parseForm(m map[string][]string, query string) (err os.Error) { func parseForm(m map[string][]string, query string) (err os.Error) {
data := make(map[string]*vector.StringVector) data := make(map[string]*vector.StringVector)
for _, kv := range strings.Split(query, "&", -1) { for _, kv := range strings.Split(query, "&") {
kvPair := strings.Split(kv, "=", 2) kvPair := strings.SplitN(kv, "=", 2)


var key, value string var key, value string
var e os.Error var e os.Error
Expand Down Expand Up @@ -185,7 +185,7 @@ func (r *Request) parseParams() (err os.Error) {
} }


ct := r.Headers.Get("Content-Type") ct := r.Headers.Get("Content-Type")
switch strings.Split(ct, ";", 2)[0] { switch strings.SplitN(ct, ";", 2)[0] {
case "text/plain", "application/x-www-form-urlencoded", "": case "text/plain", "application/x-www-form-urlencoded", "":
var b []byte var b []byte
if b, err = ioutil.ReadAll(r.Body); err != nil { if b, err = ioutil.ReadAll(r.Body); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions scgi.go
Expand Up @@ -89,7 +89,7 @@ func readScgiRequest(buf *bytes.Buffer) (*Request, os.Error) {
var err os.Error var err os.Error
//find the CONTENT_LENGTH //find the CONTENT_LENGTH


clfields := bytes.Split(data, []byte{0}, 3) clfields := bytes.SplitN(data, []byte{0}, 3)
if len(clfields) != 3 { if len(clfields) != 3 {
return nil, os.NewError("Invalid SCGI Request -- no fields") return nil, os.NewError("Invalid SCGI Request -- no fields")
} }
Expand All @@ -105,7 +105,7 @@ func readScgiRequest(buf *bytes.Buffer) (*Request, os.Error) {


content := data[len(data)-clen:] content := data[len(data)-clen:]


fields := bytes.Split(data[0:len(data)-clen], []byte{0}, -1) fields := bytes.Split(data[0:len(data)-clen], []byte{0})


for i := 0; i < len(fields)-1; i += 2 { for i := 0; i < len(fields)-1; i += 2 {
key := string(fields[i]) key := string(fields[i])
Expand Down
2 changes: 1 addition & 1 deletion web.go
Expand Up @@ -136,7 +136,7 @@ func (ctx *Context) GetSecureCookie(name string) (string, bool) {
continue continue
} }


parts := strings.Split(cookie.Value, "|", 3) parts := strings.SplitN(cookie.Value, "|", 3)


val := parts[0] val := parts[0]
timestamp := parts[1] timestamp := parts[1]
Expand Down
10 changes: 5 additions & 5 deletions web_test.go
Expand Up @@ -46,21 +46,21 @@ func buildTestResponse(buf *bytes.Buffer) *testResponse {
response := testResponse{headers: make(map[string][]string), cookies: make(map[string]string)} response := testResponse{headers: make(map[string][]string), cookies: make(map[string]string)}
s := buf.String() s := buf.String()


contents := strings.Split(s, "\r\n\r\n", 2) contents := strings.SplitN(s, "\r\n\r\n", 2)


header := contents[0] header := contents[0]


if len(contents) > 1 { if len(contents) > 1 {
response.body = contents[1] response.body = contents[1]
} }


headers := strings.Split(header, "\r\n", -1) headers := strings.Split(header, "\r\n")


statusParts := strings.Split(headers[0], " ", 3) statusParts := strings.SplitN(headers[0], " ", 3)
response.statusCode, _ = strconv.Atoi(statusParts[1]) response.statusCode, _ = strconv.Atoi(statusParts[1])


for _, h := range headers[1:] { for _, h := range headers[1:] {
split := strings.Split(h, ":", 2) split := strings.SplitN(h, ":", 2)
name := strings.TrimSpace(split[0]) name := strings.TrimSpace(split[0])
value := strings.TrimSpace(split[1]) value := strings.TrimSpace(split[1])
if _, ok := response.headers[name]; !ok { if _, ok := response.headers[name]; !ok {
Expand All @@ -76,7 +76,7 @@ func buildTestResponse(buf *bytes.Buffer) *testResponse {
if name == "Set-Cookie" { if name == "Set-Cookie" {
i := strings.Index(value, ";") i := strings.Index(value, ";")
cookie := value[0:i] cookie := value[0:i]
cookieParts := strings.Split(cookie, "=", 2) cookieParts := strings.SplitN(cookie, "=", 2)
response.cookies[strings.TrimSpace(cookieParts[0])] = strings.TrimSpace(cookieParts[1]) response.cookies[strings.TrimSpace(cookieParts[0])] = strings.TrimSpace(cookieParts[1])
} }
} }
Expand Down

0 comments on commit 111463f

Please sign in to comment.