Skip to content

Commit

Permalink
Add TLS example to README
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Jun 4, 2020
1 parent 585df53 commit 3dd83fc
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions README.md
Expand Up @@ -407,26 +407,6 @@ e := httpexpect.WithConfig(httpexpect.Config{
})
```

##### Session support

```go
// cookie jar is used to store cookies from server
e := httpexpect.WithConfig(httpexpect.Config{
Reporter: httpexpect.NewAssertReporter(t),
Client: &http.Client{
Jar: httpexpect.NewJar(), // used by default if Client is nil
},
})

// cookies are disabled
e := httpexpect.WithConfig(httpexpect.Config{
Reporter: httpexpect.NewAssertReporter(t),
Client: &http.Client{
Jar: nil,
},
})
```

##### Use HTTP handler directly

```go
Expand Down Expand Up @@ -475,6 +455,54 @@ e.GET("/path").WithHandler(handler).
Status(http.StatusOK)
```

##### Session support

```go
// cookie jar is used to store cookies from server
e := httpexpect.WithConfig(httpexpect.Config{
Reporter: httpexpect.NewAssertReporter(t),
Client: &http.Client{
Jar: httpexpect.NewJar(), // used by default if Client is nil
},
})

// cookies are disabled
e := httpexpect.WithConfig(httpexpect.Config{
Reporter: httpexpect.NewAssertReporter(t),
Client: &http.Client{
Jar: nil,
},
})
```

##### TLS support

```go
// use TLS with http.Transport
e := httpexpect.WithConfig(httpexpect.Config{
Reporter: httpexpect.NewAssertReporter(t),
Client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
// accept any certificate; for testing only!
InsecureSkipVerify: true,
},
},
},
})

// use TLS with http.Handler
e := httpexpect.WithConfig(httpexpect.Config{
Reporter: httpexpect.NewAssertReporter(t),
Client: &http.Client{
Transport: &httpexpect.Binder{
Handler: myHandler,
TLS: &tls.ConnectionState{},
},
},
})
```

## Similar packages

* [`gorequest`](https://github.com/parnurzeal/gorequest)
Expand Down

0 comments on commit 3dd83fc

Please sign in to comment.