feat(net-stubbing): add followRedirect to request interception (#8282) (#8524)

This commit is contained in:
Zach Bloomquist
2020-09-08 13:11:35 -04:00
committed by GitHub
parent 7706670caf
commit cd22300cb5
5 changed files with 25 additions and 1 deletions

View File

@@ -928,6 +928,22 @@ describe('network stubbing', function () {
.wait('@dest')
})
// @see https://github.com/cypress-io/cypress/issues/7967
it('can skip redirects via followRedirect', function () {
const href = `/fixtures/generic.html?t=${Date.now()}`
const url = `/redirect?href=${encodeURIComponent(href)}`
cy.route2('/redirect', (req) => {
req.followRedirect = true
req.reply((res) => {
expect(res.body).to.include('Some generic content')
expect(res.statusCode).to.eq(200)
res.send()
})
})
.then(() => fetch(url))
})
it('intercepts cached responses as expected', {
browser: '!firefox', // TODO: why does firefox behave differently? transparently returns cached response
}, function () {

View File

@@ -39,6 +39,11 @@ export namespace CyHttpMessages {
export type IncomingRequest = BaseMessage & {
responseTimeout?: number
/**
* Set if redirects should be followed when this request is made. By default, requests will
* not follow redirects before yielding the response (the 3xx redirect is yielded)
*/
followRedirect?: boolean
}
export interface IncomingHttpRequest extends IncomingRequest {

View File

@@ -19,6 +19,7 @@ export const SERIALIZABLE_REQ_PROPS = [
'method',
'httpVersion',
'responseTimeout',
'followRedirect',
]
export const SERIALIZABLE_RES_PROPS = _.concat(
@@ -89,6 +90,7 @@ export declare namespace NetEventFrames {
// Millisecond timestamp for when the response should continue
continueResponseAt?: number
throttleKbps?: number
followRedirect?: boolean
}
// fired when a response has been sent completely by the server to an intercepted request

View File

@@ -103,7 +103,7 @@ const SendRequestOutgoing: RequestMiddleware = function () {
const requestOptions = {
timeout: this.req.responseTimeout,
strictSSL: false,
followRedirect: false,
followRedirect: this.req.followRedirect || false,
retryIntervals: [0, 100, 200, 200],
url: this.req.proxiedUrl,
}

View File

@@ -10,6 +10,7 @@ export type CypressIncomingRequest = Request & {
requestId: string
body?: string
responseTimeout?: number
followRedirect?: boolean
}
/**