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

add request Close #30

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _cgo_gotypes.go
_cgo_export.*

_testmain.go
.idea

*.exe
*.test
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@

### Bugfixes

* Fix "http.Client don't use original Header when it do redirect" [#6](https://github.com/mozillazg/request/issues/6)
* Fix "http.Client don't use original Header when it do redirect" [#6](https://github.com/melonwool/request/issues/6)


## 0.1.0 (2015-01-08)

* Initial Release

[#23]: https://github.com/mozillazg/request/pull/23
[#23]: https://github.com/melonwool/request/pull/23
[@DavidCai1993]: https://github.com/DavidCai1993
[#26]: https://github.com/mozillazg/request/pull/26
[#26]: https://github.com/melonwool/request/pull/26
4 changes: 2 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ request
=======
[![Build Status](https://travis-ci.org/mozillazg/request.svg?branch=master)](https://travis-ci.org/mozillazg/request)
[![Coverage Status](https://coveralls.io/repos/mozillazg/request/badge.png?branch=master)](https://coveralls.io/r/mozillazg/request?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/mozillazg/request)](https://goreportcard.com/report/github.com/mozillazg/request)
[![GoDoc](https://godoc.org/github.com/mozillazg/request?status.svg)](https://godoc.org/github.com/mozillazg/request)
[![Go Report Card](https://goreportcard.com/badge/github.com/melonwool/request)](https://goreportcard.com/report/github.com/melonwool/request)
[![GoDoc](https://godoc.org/github.com/melonwool/request?status.svg)](https://godoc.org/github.com/melonwool/request)

A developer-friendly HTTP request library for Gopher. Inspired by [Python-Requests](https://github.com/kennethreitz/requests).

Expand All @@ -12,23 +12,23 @@ Installation
------------

```
go get -u github.com/mozillazg/request
go get -u github.com/melonwool/request
```


Documentation
--------------

API documentation can be found here:
https://godoc.org/github.com/mozillazg/request
https://godoc.org/github.com/melonwool/request


Usage
-------

```go
import (
"github.com/mozillazg/request"
"github.com/melonwool/request"
)
```

Expand Down Expand Up @@ -107,7 +107,7 @@ req.Proxy = "http://127.0.0.1:8080"
// req.Proxy = "socks5://127.0.0.1:57341"
resp, err := req.Get("http://httpbin.org/get")
```
or https://github.com/mozillazg/request/tree/develop/_example/proxy
or https://github.com/melonwool/request/tree/develop/_example/proxy

**HTTP Basic Authentication**:
```go
Expand Down
2 changes: 1 addition & 1 deletion _example/hooks_dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"net/http/httputil"

"github.com/mozillazg/request"
"github.com/melonwool/request"
)

type dumpHook struct {
Expand Down
2 changes: 1 addition & 1 deletion _example/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"regexp"

"github.com/mozillazg/request"
"github.com/melonwool/request"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion _example/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"net/url"

"github.com/mozillazg/request"
"github.com/melonwool/request"
)

func httpProxy(URL string) {
Expand Down
2 changes: 1 addition & 1 deletion _example/timeout/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"time"

"github.com/mozillazg/request"
"github.com/melonwool/request"
)

func diff(req *request.Request) {
Expand Down
26 changes: 13 additions & 13 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ import (
"os"
"strings"

"github.com/mozillazg/request"
"github.com/melonwool/request"
)

func ExampleRequest_Get() {
c := new(http.Client)
req := request.NewRequest(c)
url := "http://httpbin.org/get"
url := "https://httpbin.org/get"
resp, _ := req.Get(url)
d, _ := resp.Json()
defer resp.Body.Close()
fmt.Println(resp.Ok())
fmt.Println(d.Get("url").MustString())
// Output:
//true
//http://httpbin.org/get
//https://httpbin.org/get
}

func ExampleGet() {
c := new(http.Client)
args := request.NewArgs(c)
url := "http://httpbin.org/get"
url := "https://httpbin.org/get"
resp, _ := request.Get(url, args)
d, _ := resp.Json()
defer resp.Body.Close()
fmt.Println(resp.Ok())
fmt.Println(d.Get("url").MustString())
// Output:
//true
//http://httpbin.org/get
//https://httpbin.org/get
}

func ExampleRequest_Get_params() {
Expand All @@ -44,13 +44,13 @@ func ExampleRequest_Get_params() {
"a": "1",
"b": "2",
}
url := "http://httpbin.org/get"
url := "https://httpbin.org/get"
resp, _ := req.Get(url)
d, _ := resp.Json()
defer resp.Body.Close()
fmt.Println(d.Get("url").MustString())
// Output:
//http://httpbin.org/get?a=1&b=2
//https://httpbin.org/get?a=1&b=2
}

func ExampleRequest_Get_customHeaders() {
Expand All @@ -60,7 +60,7 @@ func ExampleRequest_Get_customHeaders() {
"X-Abc": "abc",
"User-Agent": "go-request-test",
}
url := "http://httpbin.org/get"
url := "https://httpbin.org/get"
resp, _ := req.Get(url)
d, _ := resp.Json()
defer resp.Body.Close()
Expand All @@ -78,7 +78,7 @@ func ExampleRequest_Post() {
"a": "1",
"b": "2",
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.Post(url)
defer resp.Body.Close()
}
Expand All @@ -90,7 +90,7 @@ func ExamplePost() {
"a": "1",
"b": "2",
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := request.Post(url, args)
defer resp.Body.Close()
}
Expand All @@ -102,7 +102,7 @@ func ExampleRequest_Get_cookies() {
"name": "value",
"foo": "bar",
}
url := "http://httpbin.org/cookies"
url := "https://httpbin.org/cookies"
resp, _ := req.Get(url)
defer resp.Body.Close()
}
Expand All @@ -115,7 +115,7 @@ func ExampleRequest_Post_files() {
req.Files = []request.FileField{
{FieldName: "abc", FileName: "abc.txt", File: f},
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.Post(url)
defer resp.Body.Close()
}
Expand All @@ -127,7 +127,7 @@ func ExampleRequest_Post_rawBody() {
req.Headers = map[string]string{
"Content-Type": request.DefaultContentType,
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.Post(url)
defer resp.Body.Close()
}
41 changes: 31 additions & 10 deletions form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestPost(t *testing.T) {
"a": "A",
"foo": "bar",
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.Post(url)
d, _ := resp.Json()
defer resp.Body.Close()
Expand All @@ -33,6 +33,27 @@ func TestPost(t *testing.T) {
}, true)
}

func TestPostResult(t *testing.T) {
c := new(http.Client)
req := NewRequest(c)
req.Data = map[string]string{
"a": "A",
"foo": "bar",
}
url := "https://httpbin.org/post"
out := &struct {
URL string `json:"url"`
Form struct {
A string `json:"a"`
Foo string `json:"foo"`
} `json:"form"`
}{}
_ = req.PostResult(url, out)
assert.Equal(t, out.URL, url)
assert.Equal(t, out.Form.A, "A")
assert.Equal(t, out.Form.Foo, "bar")
}

func TestPostFiles(t *testing.T) {
c := new(http.Client)
req := NewRequest(c)
Expand All @@ -56,7 +77,7 @@ func TestPostFiles(t *testing.T) {
{"abc", "abc.txt", b},
{"test", "test.txt", f2},
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.Post(url)
d, _ := resp.Json()
defer resp.Body.Close()
Expand All @@ -80,7 +101,7 @@ func TestPostRawBody(t *testing.T) {
req.Headers = map[string]string{
"Content-Type": DefaultContentType,
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.Post(url)
defer resp.Body.Close()

Expand All @@ -97,7 +118,7 @@ func TestPostXML(t *testing.T) {
req := NewRequest(c)
xml := "<xml><a>abc</a></xml"
req.Body = strings.NewReader(xml)
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.Post(url)
defer resp.Body.Close()

Expand All @@ -110,7 +131,7 @@ func TestPostFormIO(t *testing.T) {
c := new(http.Client)
req := NewRequest(c)
body := strings.NewReader("a=1&b=2")
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.PostForm(url, body)
defer resp.Body.Close()

Expand All @@ -126,7 +147,7 @@ func TestPostFormString(t *testing.T) {
c := new(http.Client)
req := NewRequest(c)
s := "a=1&b=2"
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.PostForm(url, s)
defer resp.Body.Close()

Expand All @@ -145,7 +166,7 @@ func TestPostFormStructA(t *testing.T) {
"a": "1",
"b": "2",
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.PostForm(url, s)
defer resp.Body.Close()

Expand All @@ -164,7 +185,7 @@ func TestPostFormStructB(t *testing.T) {
"a": {"1", "2"},
"b": {"2", "3"},
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.PostForm(url, s)
defer resp.Body.Close()

Expand Down Expand Up @@ -203,7 +224,7 @@ func TestPostFormFileA(t *testing.T) {
req.Files = []FileField{
{"abc", "abc.txt", b},
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.PostForm(url, nil)
d, _ := resp.Json()
defer resp.Body.Close()
Expand Down Expand Up @@ -233,7 +254,7 @@ func TestPostFormFileB(t *testing.T) {
req.Files = []FileField{
{"abc", "abc.txt", b},
}
url := "http://httpbin.org/post"
url := "https://httpbin.org/post"
resp, _ := req.PostForm(url, data)
d, _ := resp.Json()
defer resp.Body.Close()
Expand Down
2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package: github.com/mozillazg/request
package: github.com/melonwool/request
import:
- package: github.com/bitly/go-simplejson
version: aabad6e819789e569bd6aabf444c935aa9ba1e44
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/melonwool/request

go 1.12

require (
github.com/bitly/go-simplejson v0.5.0
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
github.com/kr/pretty v0.0.0-20160325215624-add1dbc86daf
github.com/kr/text v0.0.0-20160504234017-7cafcd837844
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20120716205630-e17e99893cb6/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/kr/pretty v0.0.0-20160325215624-add1dbc86daf h1:FpLJsEsdtsfWNJ+m+MECl0mSzLu9korRoIKSVbYhwFI=
github.com/kr/pretty v0.0.0-20160325215624-add1dbc86daf/go.mod h1:Bvhd+E3laJ0AVkG0c9rmtZcnhV0HQ3+c3YxxqTvc/gA=
github.com/kr/text v0.0.0-20160504234017-7cafcd837844 h1:kpzneEBeC0dMewP3gr/fADv1OlblH9r1goWVwpOt3TU=
github.com/kr/text v0.0.0-20160504234017-7cafcd837844/go.mod h1:sjUstKUATFIcff4qlB53Kml0wQPtJVc/3fWrmuUmcfA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Loading