From 7c0304f340f55352c584be7e6c32af3fc886468b Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Fri, 1 Nov 2019 17:28:56 -0400 Subject: [PATCH] return Promise for followRedirect, not req.init wrap --- packages/server/lib/request.coffee | 42 ++++++++++-------------------- packages/server/package.json | 2 +- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/packages/server/lib/request.coffee b/packages/server/lib/request.coffee index 4b31948d8985..2b9fcf1f351b 100644 --- a/packages/server/lib/request.coffee +++ b/packages/server/lib/request.coffee @@ -435,7 +435,7 @@ module.exports = (options = {}) -> cookies = [cookies] parsedUrl = url.parse(resUrl) - debug('setting cookies on browser %o', { url: parsedUrl, cookies }) + debug('setting cookies on browser %o', { url: parsedUrl.href, cookies }) Promise.map cookies, (cookie) -> cookie = tough.Cookie.parse(cookie, { loose: true }) @@ -478,24 +478,18 @@ module.exports = (options = {}) -> currentUrl = options.url options.followRedirect = (incomingRes) -> - req = @ - newUrl = url.resolve(currentUrl, incomingRes.headers.location) ## and when we know we should follow the redirect ## we need to override the init method and ## first set the received cookies on the browser ## and then grab the cookies for the new url - req.init = _.wrap req.init, (orig, opts) => - options.onBeforeReqInit -> - self.setCookiesOnBrowser(incomingRes, currentUrl, automationFn) - .then (cookies) -> - self.setRequestCookieHeader(req, newUrl, automationFn) - .then (cookieHeader) -> - currentUrl = newUrl - orig.call(req, opts) - - followRedirect.call(req, incomingRes) + self.setCookiesOnBrowser(incomingRes, currentUrl, automationFn) + .then (cookies) => + self.setRequestCookieHeader(@, newUrl, automationFn) + .then => + currentUrl = newUrl + true @setRequestCookieHeader(options, options.url, automationFn) .then => @@ -565,24 +559,16 @@ module.exports = (options = {}) -> push(incomingRes) - req = @ - ## and when we know we should follow the redirect ## we need to override the init method and ## first set the new cookies on the browser ## and then grab the cookies for the new url - req.init = _.wrap req.init, (orig, opts) => - self.setCookiesOnBrowser(incomingRes, currentUrl, automationFn) - .then -> - self.setRequestCookieHeader(req, newUrl, automationFn) - .then -> - currentUrl = newUrl - orig.call(req, opts) - - ## cause the redirect to happen - ## but swallow up the incomingRes - ## so we can build an array of responses - return true + self.setCookiesOnBrowser(incomingRes, currentUrl, automationFn) + .then => + self.setRequestCookieHeader(@, newUrl, automationFn) + .then => + currentUrl = newUrl + true @create(options, true) .then(@normalizeResponse.bind(@, push)) @@ -602,7 +588,7 @@ module.exports = (options = {}) -> ## the current url resp.redirectedToUrl = url.resolve(options.url, loc) - @setCookiesOnBrowser(resp, options.url, automationFn) + @setCookiesOnBrowser(resp, currentUrl, automationFn) .return(resp) if c = options.cookies diff --git a/packages/server/package.json b/packages/server/package.json index 6876a5a36dca..b6db52e0e5dc 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -115,7 +115,7 @@ "pumpify": "1.5.1", "ramda": "0.24.1", "randomstring": "1.1.5", - "request": "2.88.0", + "request": "cypress-io/request#47cdc67085c9fddc8d39d3172538f3f86c96bb8b", "request-promise": "4.2.4", "return-deep-diff": "0.3.0", "sanitize-filename": "1.6.3",