Skip to content

Commit

Permalink
feat(followRedirect): add followRedirect option for request
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Gantelmi authored and Raphaël Benitte committed Apr 12, 2018
1 parent 9158874 commit f968b3b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,16 @@ httpApi.install({
```yaml
Given:
- /^(?:I )?set request headers$/
- /^(?:I )? do not follow redirect$/
- /^(?:I )? follow redirect$/
- /^(?:I )?assign request headers$/
- /^(?:I )?set ([a-zA-Z0-9-]+) request header to (.+)$/
- /^(?:I )?clear request headers/
- /^(?:I )?set request json body$/
- /^(?:I )?set request json body from (.+)$/
- /^(?:I )?set request form body$/
- /^(?:I )?set request form body from (.+)$/
- /^(?:I )?set request multipart body from (.+)$/
- /^(?:I )?clear request body$/
- /^(?:I )?set request query$/
- /^(?:I )?pick response json (.+) as (.+)$/
Expand Down
13 changes: 12 additions & 1 deletion src/extensions/http_api/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HttpApiClient {
this.query = null
this.cookies = []
this.cookieJar = null
this.followRedirect = true

// RESPONSE INFORMATION
this.response = null
Expand All @@ -45,6 +46,7 @@ class HttpApiClient {

this.cookies = []
this.cookieJar = null
this.followRedirect = true

this.response = null
this.responseCookies = {}
Expand All @@ -70,6 +72,14 @@ class HttpApiClient {
this.body = payload
}

/**
* Sets Follow Redirect option.
*
*/
setFollowRedirect(isEnabled) {
this.followRedirect = isEnabled
}

/**
* Sets request body for multipart form data
*
Expand Down Expand Up @@ -213,7 +223,8 @@ class HttpApiClient {
method,
qs: this.query || {},
headers: this.headers,
jar: this.cookieJar
jar: this.cookieJar,
followRedirect: this.followRedirect
}

const fullUri = `${baseUrl}${path}`
Expand Down
14 changes: 14 additions & 0 deletions src/extensions/http_api/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ module.exports = ({ baseUrl = '' } = {}) => ({ Given, When, Then }) => {
this.httpApiClient.setHeaders(Cast.object(this.state.populateObject(step.rowsHash())))
})

/**
* Setting http option followRedirect to false
*/
Given(/^(?:I )? do not follow redirect$/, function() {
this.httpApiClient.setFollowRedirect(false)
})

/**
* Setting http option followRedirect to true
*/
Given(/^(?:I )? follow redirect$/, function() {
this.httpApiClient.setFollowRedirect(true)
})

/**
* Assign http headers
* The difference from "set request headers" is that "set" set the whole headers object
Expand Down

0 comments on commit f968b3b

Please sign in to comment.