Skip to content

Commit

Permalink
Add Option, Trace, and Connect HTTP methods
Browse files Browse the repository at this point in the history
* Add HTTP verbs per RFC 7231 and RFC 5789
  • Loading branch information
dihedron authored and dghubble committed Jun 3, 2018
1 parent 4970a62 commit c519674
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Use `Path` to set or extend the URL for created Requests. Extension means the pa
req, err := sling.New().Base("https://example.com/").Path("foo/").Path("bar").Request()
```

Use `Get`, `Post`, `Put`, `Patch`, `Delete`, or `Head` which are exactly the same as `Path` except they set the HTTP method too.
Use `Get`, `Post`, `Put`, `Patch`, `Delete`, `Head`, `Options`, `Trace`, or `Connect` which are exactly the same as `Path` except they set the HTTP method too.

```go
req, err := sling.New().Post("http://upload.com/gophers")
Expand Down
18 changes: 18 additions & 0 deletions sling.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,24 @@ func (s *Sling) Delete(pathURL string) *Sling {
return s.Path(pathURL)
}

// Options sets the Sling method to OPTIONS and sets the given pathURL.
func (s *Sling) Options(pathURL string) *Sling {
s.method = "OPTIONS"
return s.Path(pathURL)
}

// Trace sets the Sling method to TRACE and sets the given pathURL.
func (s *Sling) Trace(pathURL string) *Sling {
s.method = "TRACE"
return s.Path(pathURL)
}

// Connect sets the Sling method to CONNECT and sets the given pathURL.
func (s *Sling) Connect(pathURL string) *Sling {
s.method = "CONNECT"
return s.Path(pathURL)
}

// Header

// Add adds the key, value pair in Headers, appending values for existing keys
Expand Down
3 changes: 3 additions & 0 deletions sling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ func TestMethodSetters(t *testing.T) {
{New().Put("http://a.io"), "PUT"},
{New().Patch("http://a.io"), "PATCH"},
{New().Delete("http://a.io"), "DELETE"},
{New().Options("http://a.io"), "OPTIONS"},
{New().Trace("http://a.io"), "TRACE"},
{New().Connect("http://a.io"), "CONNECT"},
}
for _, c := range cases {
if c.sling.method != c.expectedMethod {
Expand Down

0 comments on commit c519674

Please sign in to comment.