Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web.go สำหรับ release r.60 #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"reflect"
"strconv"
"strings"
"url"
)

type filedata struct {
Expand All @@ -24,7 +25,7 @@ type filedata struct {
type Request struct {
Method string // GET, POST, PUT, etc.
RawURL string // The raw URL given in the request.
URL *http.URL // Parsed URL.
URL *url.URL // Parsed URL.
Proto string // "HTTP/1.0"
ProtoMajor int // 1
ProtoMinor int // 0
Expand Down Expand Up @@ -104,7 +105,7 @@ func newRequestCgi(headers http.Header, body io.Reader) *Request {
port := headers.Get("SERVER_PORT")
proto := headers.Get("SERVER_PROTOCOL")
rawurl := "http://" + host + ":" + port + path
url, _ := http.ParseURL(rawurl)
url, _ := url.Parse(rawurl)
useragent := headers.Get("USER_AGENT")
remoteAddr := headers.Get("REMOTE_ADDR")
remotePort, _ := strconv.Atoi(headers.Get("REMOTE_PORT"))
Expand Down Expand Up @@ -146,9 +147,9 @@ func parseForm(m map[string][]string, query string) (err os.Error) {

var key, value string
var e os.Error
key, e = http.URLUnescape(kvPair[0])
key, e = url.QueryUnescape(kvPair[0])
if e == nil && len(kvPair) > 1 {
value, e = http.URLUnescape(kvPair[1])
value, e = url.QueryUnescape(kvPair[1])
}
if e != nil {
err = e
Expand Down
5 changes: 3 additions & 2 deletions web.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strconv"
"strings"
"time"
"url"
)

type conn interface {
Expand Down Expand Up @@ -591,9 +592,9 @@ func fileExists(dir string) bool {
func Urlencode(data map[string]string) string {
var buf bytes.Buffer
for k, v := range data {
buf.WriteString(http.URLEscape(k))
buf.WriteString(url.QueryEscape(k))
buf.WriteByte('=')
buf.WriteString(http.URLEscape(v))
buf.WriteString(url.QueryEscape(v))
buf.WriteByte('&')
}
s := buf.String()
Expand Down
21 changes: 12 additions & 9 deletions web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strconv"
"strings"
"testing"
"url"
//"dump"
)

func init() {
Expand Down Expand Up @@ -46,21 +48,22 @@ func buildTestResponse(buf *bytes.Buffer) *testResponse {
response := testResponse{headers: make(map[string][]string), cookies: make(map[string]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]

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

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

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


for _, h := range headers[1:] {
split := strings.Split(h, ":", 2)
split := strings.SplitN(h, ":", 2)
name := strings.TrimSpace(split[0])
value := strings.TrimSpace(split[1])
if _, ok := response.headers[name]; !ok {
Expand All @@ -71,12 +74,11 @@ func buildTestResponse(buf *bytes.Buffer) *testResponse {
copy(newheaders, response.headers[name])
newheaders[len(newheaders)-1] = value
response.headers[name] = newheaders

//if the header is a cookie, set it
if name == "Set-Cookie" {
i := strings.Index(value, ";")
cookie := value[0:i]
cookieParts := strings.Split(cookie, "=", 2)
cookieParts := strings.SplitN(cookie, "=", 2)
response.cookies[strings.TrimSpace(cookieParts[0])] = strings.TrimSpace(cookieParts[1])
}
}
Expand Down Expand Up @@ -209,7 +211,7 @@ func buildTestRequest(method string, path string, body string, headers map[strin
host := "127.0.0.1"
port := "80"
rawurl := "http://" + host + ":" + port + path
url, _ := http.ParseURL(rawurl)
url, _ := url.Parse(rawurl)

proto := "HTTP/1.1"
useragent := "web.go test framework"
Expand Down Expand Up @@ -347,7 +349,7 @@ func buildTestScgiRequest(method string, path string, body string, headers map[s

return &buf
}

/*
func TestScgi(t *testing.T) {
for _, test := range tests {
req := buildTestScgiRequest(test.method, test.path, test.body, make(map[string]string))
Expand Down Expand Up @@ -413,7 +415,7 @@ func TestScgiHead(t *testing.T) {
}
}
}

*/

func buildFcgiKeyValue(key string, val string) []byte {

Expand Down Expand Up @@ -680,3 +682,4 @@ func TestCloseServer(t *testing.T) {
}
}
*/