From ebb3b91df9bcc7595147de7d8b49cf420bac3a24 Mon Sep 17 00:00:00 2001 From: CurveSoft Date: Tue, 3 Jun 2014 21:20:10 +0800 Subject: [PATCH 1/5] =?UTF-8?q?1=E3=80=81=E5=A2=9E=E5=8A=A0cookiejar?= =?UTF-8?q?=E6=94=AF=E6=8C=81=202=E3=80=81=E5=A2=9E=E5=8A=A0Setting?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=8C=E4=BE=BF=E4=BA=8E=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0=203?= =?UTF-8?q?=E3=80=81=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E7=AB=AF=E6=B5=8B?= =?UTF-8?q?=E8=AF=95php=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httplib/httplib.go | 127 ++++++++++++++++++++++++++++----------- httplib/httplib_test.go | 61 +++++++++++++++++-- httplib/httplib_test.php | 26 ++++++++ 3 files changed, 174 insertions(+), 40 deletions(-) create mode 100644 httplib/httplib_test.php diff --git a/httplib/httplib.go b/httplib/httplib.go index 18995283..cee8efcb 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -17,21 +17,44 @@ import ( "net" "net/http" "net/http/httputil" + "net/http/cookiejar" "net/url" "os" "strings" "time" + "sync" ) -var defaultUserAgent = "beegoServer" +var defaultSetting = BeegoHttpSettings{false, "beegoServer", 60 * time.Second, 60 * time.Second, nil, nil, nil, false} +var defaultCookieJar http.CookieJar +var settingMutex sync.Mutex + +// createDefaultCookieJar creates a global cookiejar to store cookies. +func createDefaultCookie() { + settingMutex.Lock() + defer settingMutex.Unlock() + defaultCookieJar, _ = cookiejar.New(nil) +} + +// Overwrite default settings +func SetDefaultSetting(setting BeegoHttpSettings) { + settingMutex.Lock() + defer settingMutex.Unlock() + defaultSetting = setting + if defaultSetting.ConnectTimeout == 0 { + defaultSetting.ConnectTimeout = 60*time.Second + } + if defaultSetting.ReadWriteTimeout == 0 { + defaultSetting.ReadWriteTimeout = 60*time.Second + } +} // Get returns *BeegoHttpRequest with GET method. func Get(url string) *BeegoHttpRequest { var req http.Request req.Method = "GET" req.Header = http.Header{} - req.Header.Set("User-Agent", defaultUserAgent) - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } } // Post returns *BeegoHttpRequest with POST method. @@ -39,8 +62,7 @@ func Post(url string) *BeegoHttpRequest { var req http.Request req.Method = "POST" req.Header = http.Header{} - req.Header.Set("User-Agent", defaultUserAgent) - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } } // Put returns *BeegoHttpRequest with PUT method. @@ -48,8 +70,7 @@ func Put(url string) *BeegoHttpRequest { var req http.Request req.Method = "PUT" req.Header = http.Header{} - req.Header.Set("User-Agent", defaultUserAgent) - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } } // Delete returns *BeegoHttpRequest DELETE GET method. @@ -57,8 +78,7 @@ func Delete(url string) *BeegoHttpRequest { var req http.Request req.Method = "DELETE" req.Header = http.Header{} - req.Header.Set("User-Agent", defaultUserAgent) - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } } // Head returns *BeegoHttpRequest with HEAD method. @@ -66,8 +86,19 @@ func Head(url string) *BeegoHttpRequest { var req http.Request req.Method = "HEAD" req.Header = http.Header{} - req.Header.Set("User-Agent", defaultUserAgent) - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } +} + +// BeegoHttpSettings +type BeegoHttpSettings struct{ + ShowDebug bool + UserAgent string + ConnectTimeout time.Duration + ReadWriteTimeout time.Duration + TlsClientConfig *tls.Config + Proxy func(*http.Request) (*url.URL, error) + Transport http.RoundTripper + EnableCookie bool } // BeegoHttpRequest provides more useful methods for requesting one url than http.Request. @@ -76,30 +107,43 @@ type BeegoHttpRequest struct { req *http.Request params map[string]string files map[string]string - showdebug bool - connectTimeout time.Duration - readWriteTimeout time.Duration - tlsClientConfig *tls.Config - proxy func(*http.Request) (*url.URL, error) - transport http.RoundTripper + setting BeegoHttpSettings +} + +// Change request settings +func (b *BeegoHttpRequest) Setting(setting BeegoHttpSettings) *BeegoHttpRequest { + b.setting = setting + return b +} + +// SetEnableCookie sets enable/disable cookiejar +func (b *BeegoHttpRequest) SetEnableCookie(enable bool) *BeegoHttpRequest { + b.setting.EnableCookie = enable + return b +} + +// SetUserAgent sets User-Agent header field +func (b *BeegoHttpRequest) SetAgent(useragent string) *BeegoHttpRequest { + b.setting.UserAgent = useragent + return b } // Debug sets show debug or not when executing request. func (b *BeegoHttpRequest) Debug(isdebug bool) *BeegoHttpRequest { - b.showdebug = isdebug + b.setting.ShowDebug = isdebug return b } // SetTimeout sets connect time out and read-write time out for BeegoRequest. func (b *BeegoHttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHttpRequest { - b.connectTimeout = connectTimeout - b.readWriteTimeout = readWriteTimeout + b.setting.ConnectTimeout = connectTimeout + b.setting.ReadWriteTimeout = readWriteTimeout return b } // SetTLSClientConfig sets tls connection configurations if visiting https url. func (b *BeegoHttpRequest) SetTLSClientConfig(config *tls.Config) *BeegoHttpRequest { - b.tlsClientConfig = config + b.setting.TlsClientConfig = config return b } @@ -134,7 +178,7 @@ func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest { // Set transport to func (b *BeegoHttpRequest) SetTransport(transport http.RoundTripper) *BeegoHttpRequest { - b.transport = transport + b.setting.Transport = transport return b } @@ -146,7 +190,7 @@ func (b *BeegoHttpRequest) SetTransport(transport http.RoundTripper) *BeegoHttpR // return u, nil // } func (b *BeegoHttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHttpRequest { - b.proxy = proxy + b.setting.Proxy = proxy return b } @@ -194,9 +238,9 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { if b.req.Method == "GET" && len(paramBody) > 0 { if strings.Index(b.url, "?") != -1 { - b.url += "&" + paramBody + b.url += "&"+paramBody } else { - b.url = b.url + "?" + paramBody + b.url = b.url+"?"+paramBody } } else if b.req.Method == "POST" && b.req.Body == nil && len(paramBody) > 0 { if len(b.files) > 0 { @@ -234,7 +278,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { url, err := url.Parse(b.url) if url.Scheme == "" { - b.url = "http://" + b.url + b.url = "http://"+b.url url, err = url.Parse(b.url) } if err != nil { @@ -242,7 +286,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { } b.req.URL = url - if b.showdebug { + if b.setting.ShowDebug { dump, err := httputil.DumpRequest(b.req, true) if err != nil { println(err.Error()) @@ -250,32 +294,47 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { println(string(dump)) } - trans := b.transport + trans := b.setting.Transport if trans == nil { // create default transport trans = &http.Transport{ - TLSClientConfig: b.tlsClientConfig, - Proxy: b.proxy, - Dial: TimeoutDialer(b.connectTimeout, b.readWriteTimeout), + TLSClientConfig: b.setting.TlsClientConfig, + Proxy: b.setting.Proxy, + Dial: TimeoutDialer(b.setting.ConnectTimeout, b.setting.ReadWriteTimeout), } } else { // if b.transport is *http.Transport then set the settings. if t, ok := trans.(*http.Transport); ok { if t.TLSClientConfig == nil { - t.TLSClientConfig = b.tlsClientConfig + t.TLSClientConfig = b.setting.TlsClientConfig } if t.Proxy == nil { - t.Proxy = b.proxy + t.Proxy = b.setting.Proxy } if t.Dial == nil { - t.Dial = TimeoutDialer(b.connectTimeout, b.readWriteTimeout) + t.Dial = TimeoutDialer(b.setting.ConnectTimeout, b.setting.ReadWriteTimeout) } } } + var jar http.CookieJar + if b.setting.EnableCookie { + if defaultCookieJar == nil { + createDefaultCookie() + } + jar = defaultCookieJar + }else { + jar = nil + } + client := &http.Client{ Transport: trans, + Jar:jar, + } + + if b.setting.UserAgent != "" { + b.req.Header.Set("User-Agent", b.setting.UserAgent) } resp, err := client.Do(b.req) diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index 4689910a..27498c7a 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -1,4 +1,4 @@ -// Beego (http://beego.me/) +// Beego (http://localhost/httplib_test.php) // @description beego is an open-source, high-performance web framework for the Go programming language. // @link http://github.com/astaxie/beego for the canonical source repository // @license http://github.com/astaxie/beego/blob/master/LICENSE @@ -7,13 +7,13 @@ package httplib import ( + "testing" "fmt" "io/ioutil" - "testing" ) func TestGetUrl(t *testing.T) { - resp, err := Get("http://beego.me/").Debug(true).Response() + resp, err := Get("http://localhost/httplib_test.php").Debug(true).Response() if err != nil { t.Fatal(err) } @@ -29,7 +29,7 @@ func TestGetUrl(t *testing.T) { t.Fatal("data is no") } - str, err := Get("http://beego.me/").String() + str, err := Get("http://localhost/httplib_test.php").String() if err != nil { t.Fatal(err) } @@ -39,13 +39,62 @@ func TestGetUrl(t *testing.T) { } func TestPost(t *testing.T) { - b := Post("http://beego.me/").Debug(true) + b := Post("http://localhost/httplib_test.php").Debug(true) b.Param("username", "astaxie") b.Param("password", "hello") - b.PostFile("uploadfile", "httplib.go") + b.PostFile("uploadfile", "httplib_test.php") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) } + +func TestSimpleGetString(t *testing.T) { + fmt.Println("TestSimpleGetString==========================================") + html, err := Get("http://localhost/httplib_test.php").SetAgent("beegoooooo").String() + if err != nil { + t.Fatal(err) + } + fmt.Println(html) + fmt.Println("TestSimpleGetString==========================================") +} + +func TestSimpleGetStringWithDefaultCookie(t *testing.T) { + fmt.Println("TestSimpleGetStringWithDefaultCookie==========================================") + html, err := Get("http://localhost/httplib_test.php").SetEnableCookie(true).String() + if err != nil { + t.Fatal(err) + } + fmt.Println(html) + html, err = Get("http://localhost/httplib_test.php").SetEnableCookie(true).String() + if err != nil { + t.Fatal(err) + } + fmt.Println(html) + fmt.Println("TestSimpleGetStringWithDefaultCookie==========================================") +} + +func TestDefaultSetting(t *testing.T) { + fmt.Println("TestDefaultSetting==========================================") + var def BeegoHttpSettings + def.EnableCookie = true + //def.ShowDebug = true + def.UserAgent = "UserAgent" + //def.ConnectTimeout = 60*time.Second + //def.ReadWriteTimeout = 60*time.Second + def.Transport = nil//http.DefaultTransport + SetDefaultSetting(def) + + html, err := Get("http://localhost/httplib_test.php").String() + if err != nil { + t.Fatal(err) + } + fmt.Println(html) + html, err = Get("http://localhost/httplib_test.php").String() + if err != nil { + t.Fatal(err) + } + fmt.Println(html) + fmt.Println("TestDefaultSetting==========================================") +} diff --git a/httplib/httplib_test.php b/httplib/httplib_test.php new file mode 100644 index 00000000..db9861b0 --- /dev/null +++ b/httplib/httplib_test.php @@ -0,0 +1,26 @@ + $value) { + if (strpos($head, "HTTP_") === 0) { + $HTTP[$head] = $value; + } +} +$data['HTTP'] = $HTTP; +$data['GET'] = $_GET; +$data['POST'] = $_POST; +$data['REQUEST'] = $_REQUEST; +$data['SESSION'] = $_SESSION; +$data['COOKIE'] = $_COOKIE; +$data['FILES'] = $_FILES; +$data['SERVER'] = $_SERVER; +$data['ENV'] = $_ENV; + +//echo json_encode($data); +//echo "
";
+print_r($data);
+//echo "
"; From bd537554ea50b6eb8faf9f775b3749433417fb56 Mon Sep 17 00:00:00 2001 From: CurveSoft Date: Wed, 4 Jun 2014 21:04:50 +0800 Subject: [PATCH 2/5] 1.gofmt httplib.go httplib_test.go 2.replace test url to http://httpbin.org functions --- .idea/go_settings.xml | 7 +++++++ httplib/httplib.go | 40 ++++++++++++++++++++-------------------- httplib/httplib_test.go | 22 +++++++++++----------- 3 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 .idea/go_settings.xml diff --git a/.idea/go_settings.xml b/.idea/go_settings.xml new file mode 100644 index 00000000..32bd5fde --- /dev/null +++ b/.idea/go_settings.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/httplib/httplib.go b/httplib/httplib.go index cee8efcb..f7d083f2 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -16,13 +16,13 @@ import ( "mime/multipart" "net" "net/http" - "net/http/httputil" "net/http/cookiejar" + "net/http/httputil" "net/url" "os" "strings" - "time" "sync" + "time" ) var defaultSetting = BeegoHttpSettings{false, "beegoServer", 60 * time.Second, 60 * time.Second, nil, nil, nil, false} @@ -42,10 +42,10 @@ func SetDefaultSetting(setting BeegoHttpSettings) { defer settingMutex.Unlock() defaultSetting = setting if defaultSetting.ConnectTimeout == 0 { - defaultSetting.ConnectTimeout = 60*time.Second + defaultSetting.ConnectTimeout = 60 * time.Second } if defaultSetting.ReadWriteTimeout == 0 { - defaultSetting.ReadWriteTimeout = 60*time.Second + defaultSetting.ReadWriteTimeout = 60 * time.Second } } @@ -54,7 +54,7 @@ func Get(url string) *BeegoHttpRequest { var req http.Request req.Method = "GET" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} } // Post returns *BeegoHttpRequest with POST method. @@ -62,7 +62,7 @@ func Post(url string) *BeegoHttpRequest { var req http.Request req.Method = "POST" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} } // Put returns *BeegoHttpRequest with PUT method. @@ -70,7 +70,7 @@ func Put(url string) *BeegoHttpRequest { var req http.Request req.Method = "PUT" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} } // Delete returns *BeegoHttpRequest DELETE GET method. @@ -78,7 +78,7 @@ func Delete(url string) *BeegoHttpRequest { var req http.Request req.Method = "DELETE" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} } // Head returns *BeegoHttpRequest with HEAD method. @@ -86,11 +86,11 @@ func Head(url string) *BeegoHttpRequest { var req http.Request req.Method = "HEAD" req.Header = http.Header{} - return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } + return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting} } // BeegoHttpSettings -type BeegoHttpSettings struct{ +type BeegoHttpSettings struct { ShowDebug bool UserAgent string ConnectTimeout time.Duration @@ -103,11 +103,11 @@ type BeegoHttpSettings struct{ // BeegoHttpRequest provides more useful methods for requesting one url than http.Request. type BeegoHttpRequest struct { - url string - req *http.Request - params map[string]string - files map[string]string - setting BeegoHttpSettings + url string + req *http.Request + params map[string]string + files map[string]string + setting BeegoHttpSettings } // Change request settings @@ -238,9 +238,9 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { if b.req.Method == "GET" && len(paramBody) > 0 { if strings.Index(b.url, "?") != -1 { - b.url += "&"+paramBody + b.url += "&" + paramBody } else { - b.url = b.url+"?"+paramBody + b.url = b.url + "?" + paramBody } } else if b.req.Method == "POST" && b.req.Body == nil && len(paramBody) > 0 { if len(b.files) > 0 { @@ -278,7 +278,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { url, err := url.Parse(b.url) if url.Scheme == "" { - b.url = "http://"+b.url + b.url = "http://" + b.url url, err = url.Parse(b.url) } if err != nil { @@ -324,13 +324,13 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { createDefaultCookie() } jar = defaultCookieJar - }else { + } else { jar = nil } client := &http.Client{ Transport: trans, - Jar:jar, + Jar: jar, } if b.setting.UserAgent != "" { diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index 27498c7a..0e274c5a 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -1,4 +1,4 @@ -// Beego (http://localhost/httplib_test.php) +// Beego (http://beego.me) // @description beego is an open-source, high-performance web framework for the Go programming language. // @link http://github.com/astaxie/beego for the canonical source repository // @license http://github.com/astaxie/beego/blob/master/LICENSE @@ -7,13 +7,13 @@ package httplib import ( - "testing" "fmt" "io/ioutil" + "testing" ) func TestGetUrl(t *testing.T) { - resp, err := Get("http://localhost/httplib_test.php").Debug(true).Response() + resp, err := Get("http://beego.me").Debug(true).Response() if err != nil { t.Fatal(err) } @@ -29,7 +29,7 @@ func TestGetUrl(t *testing.T) { t.Fatal("data is no") } - str, err := Get("http://localhost/httplib_test.php").String() + str, err := Get("http://beego.me").String() if err != nil { t.Fatal(err) } @@ -39,7 +39,7 @@ func TestGetUrl(t *testing.T) { } func TestPost(t *testing.T) { - b := Post("http://localhost/httplib_test.php").Debug(true) + b := Post("http://beego.me").Debug(true) b.Param("username", "astaxie") b.Param("password", "hello") b.PostFile("uploadfile", "httplib_test.php") @@ -52,7 +52,7 @@ func TestPost(t *testing.T) { func TestSimpleGetString(t *testing.T) { fmt.Println("TestSimpleGetString==========================================") - html, err := Get("http://localhost/httplib_test.php").SetAgent("beegoooooo").String() + html, err := Get("http://httpbin.org/headers").SetAgent("beegoooooo").String() if err != nil { t.Fatal(err) } @@ -62,12 +62,12 @@ func TestSimpleGetString(t *testing.T) { func TestSimpleGetStringWithDefaultCookie(t *testing.T) { fmt.Println("TestSimpleGetStringWithDefaultCookie==========================================") - html, err := Get("http://localhost/httplib_test.php").SetEnableCookie(true).String() + html, err := Get("http://httpbin.org/cookies/set?k1=v1").SetEnableCookie(true).String() if err != nil { t.Fatal(err) } fmt.Println(html) - html, err = Get("http://localhost/httplib_test.php").SetEnableCookie(true).String() + html, err = Get("http://httpbin.org/cookies").SetEnableCookie(true).String() if err != nil { t.Fatal(err) } @@ -83,15 +83,15 @@ func TestDefaultSetting(t *testing.T) { def.UserAgent = "UserAgent" //def.ConnectTimeout = 60*time.Second //def.ReadWriteTimeout = 60*time.Second - def.Transport = nil//http.DefaultTransport + def.Transport = nil //http.DefaultTransport SetDefaultSetting(def) - html, err := Get("http://localhost/httplib_test.php").String() + html, err := Get("http://httpbin.org/headers").String() if err != nil { t.Fatal(err) } fmt.Println(html) - html, err = Get("http://localhost/httplib_test.php").String() + html, err = Get("http://httpbin.org/headers").String() if err != nil { t.Fatal(err) } From e3033b57a6a206f81575f909ed30ba84b45cba6d Mon Sep 17 00:00:00 2001 From: CurveSoft Date: Wed, 4 Jun 2014 21:15:24 +0800 Subject: [PATCH 3/5] 1.gofmt httplib.go httplib_test.go 2.replace test url to http://httpbin.org functions --- .idea/go_settings.xml | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .idea/go_settings.xml diff --git a/.idea/go_settings.xml b/.idea/go_settings.xml deleted file mode 100644 index 32bd5fde..00000000 --- a/.idea/go_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - From 7b110a0b739c9cf32f2c9576d16f48813b7d2664 Mon Sep 17 00:00:00 2001 From: CurveSoft Date: Wed, 4 Jun 2014 22:09:43 +0800 Subject: [PATCH 4/5] remove httplib_test.php --- httplib/httplib_test.php | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 httplib/httplib_test.php diff --git a/httplib/httplib_test.php b/httplib/httplib_test.php deleted file mode 100644 index db9861b0..00000000 --- a/httplib/httplib_test.php +++ /dev/null @@ -1,26 +0,0 @@ - $value) { - if (strpos($head, "HTTP_") === 0) { - $HTTP[$head] = $value; - } -} -$data['HTTP'] = $HTTP; -$data['GET'] = $_GET; -$data['POST'] = $_POST; -$data['REQUEST'] = $_REQUEST; -$data['SESSION'] = $_SESSION; -$data['COOKIE'] = $_COOKIE; -$data['FILES'] = $_FILES; -$data['SERVER'] = $_SERVER; -$data['ENV'] = $_ENV; - -//echo json_encode($data); -//echo "
";
-print_r($data);
-//echo "
"; From d689be30e87ac8a2d9d14696bf32e850aa7bcc9d Mon Sep 17 00:00:00 2001 From: CurveSoft Date: Wed, 4 Jun 2014 22:12:37 +0800 Subject: [PATCH 5/5] remove httplib_test.php --- httplib/httplib_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httplib/httplib_test.go b/httplib/httplib_test.go index 0e274c5a..b275894c 100644 --- a/httplib/httplib_test.go +++ b/httplib/httplib_test.go @@ -42,7 +42,7 @@ func TestPost(t *testing.T) { b := Post("http://beego.me").Debug(true) b.Param("username", "astaxie") b.Param("password", "hello") - b.PostFile("uploadfile", "httplib_test.php") + b.PostFile("uploadfile", "httplib_test.go") str, err := b.String() if err != nil { t.Fatal(err)