Skip to content

Commit f948c81

Browse files
authored
Upgrade got (github#28617)
* Upgrade got * Update e2etest.js * Skip following redirects on redirect tests * Update deprecated-enterprise-versions.js
1 parent ee460f5 commit f948c81

File tree

9 files changed

+153
-60
lines changed

9 files changed

+153
-60
lines changed

lib/failbot.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ async function retryingGot(url, args) {
1010
// With the timeout at 3000 (milliseconds) and the retry.limit
1111
// at 4 (times), the total worst-case is:
1212
// 3000 * 4 + 1000 + 2000 + 3000 + 4000 + 8000 = 30 seconds
13-
timeout: 3000,
13+
timeout: {
14+
response: 3000,
15+
},
1416
retry: {
1517
// This means it will wait...
1618
// 1. 1000ms

lib/hydro.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ export default class Hydro {
106106
// Because we prefer to handle the status code manually below
107107
throwHttpErrors: false,
108108
// The default is no timeout.
109-
timeout: POST_TIMEOUT_MS,
109+
timeout: {
110+
response: POST_TIMEOUT_MS,
111+
},
110112
agent: {
111113
// Deliberately not setting up a `http` or `http2` agent
112114
// because it won't be used for this particular `got` request.

middleware/archived-enterprise-versions.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ const cacheAggressively = (res) => {
7272
// Our own timeout, in ./middleware/timeout.js defaults to 10 seconds.
7373
// So there's no point in trying more attempts than 3 because it would
7474
// just timeout on the 10s. (i.e. 1000 + 2000 + 4000 + 8000 > 10,000)
75-
const retryConfiguration = {
76-
limit: 3,
77-
}
75+
const retryConfiguration = { limit: 3 }
7876
// According to our Datadog metrics, the *average* time for the
7977
// the 'archive_enterprise_proxy' metric is ~70ms (excluding spikes)
8078
// which much less than 500ms.
81-
const timeoutConfiguration = 500
79+
const timeoutConfiguration = { response: 500 }
8280

8381
async function getRemoteJSON(url, config) {
8482
if (_getRemoteJSONCache.has(url)) {
@@ -121,7 +119,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
121119
// useful because it caches so well.
122120
// And, as of 2021 that `redirects.json` is 10MB so it's more likely
123121
// to time out.
124-
timeout: 1000,
122+
timeout: { response: 1000 },
125123
})
126124
const [language, withoutLanguage] = splitPathByLanguage(req.path, req.context.userLanguage)
127125
const newRedirectTo = redirectJson[withoutLanguage]
@@ -182,7 +180,7 @@ export default async function archivedEnterpriseVersions(req, res, next) {
182180
// useful because it caches so well.
183181
// And, as of 2021 that `redirects.json` is 10MB so it's more likely
184182
// to time out.
185-
timeout: 1000,
183+
timeout: { response: 1000 },
186184
})
187185

188186
// make redirects found via redirects.json redirect with a 301

package-lock.json

Lines changed: 113 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"express-timeout-handler": "^2.2.2",
3030
"flat": "^5.0.2",
3131
"github-slugger": "^1.4.0",
32-
"got": "^11.8.5",
32+
"got": "^12.1.0",
3333
"gray-matter": "^4.0.3",
3434
"hast-util-from-parse5": "^7.1.0",
3535
"hast-util-parse-selector": "^3.1.0",

tests/helpers/e2etest.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cheerio from 'cheerio'
22
import got from 'got'
3+
import { omitBy, isUndefined } from 'lodash-es'
34

45
export async function get(
56
route,
@@ -16,14 +17,18 @@ export async function get(
1617
const fn = got[method]
1718
if (!fn || typeof fn !== 'function') throw new Error(`No method function for '${method}'`)
1819
const absURL = `http://localhost:4000${route}`
19-
const res = await fn(absURL, {
20-
body: opts.body,
21-
headers: opts.headers,
22-
retry: { limit: 0 },
23-
cookieJar: opts.cookieJar,
24-
throwHttpErrors: false,
25-
followRedirect: opts.followAllRedirects || opts.followRedirects,
26-
})
20+
const xopts = omitBy(
21+
{
22+
body: opts.body,
23+
headers: opts.headers,
24+
retry: { limit: 0 },
25+
cookieJar: opts.cookieJar,
26+
throwHttpErrors: false,
27+
followRedirect: opts.followAllRedirects || opts.followRedirects,
28+
},
29+
isUndefined
30+
)
31+
const res = await fn(absURL, xopts)
2732
// follow all redirects, or just follow one
2833
if (opts.followAllRedirects && [301, 302].includes(res.status)) {
2934
// res = await get(res.headers.location, opts)

tests/rendering/server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ describe('server', () => {
613613

614614
describe('redirects', () => {
615615
test('redirects old articles to their English URL', async () => {
616-
const res = await get('/articles/deleting-a-team')
616+
const res = await get('/articles/deleting-a-team', { followRedirects: false })
617617
expect(res.statusCode).toBe(302)
618618
expect(res.headers['set-cookie']).toBeUndefined()
619619
// no cache control because a language prefix had to be injected
@@ -642,6 +642,7 @@ describe('server', () => {
642642
headers: {
643643
'accept-language': `${languageKey}`,
644644
},
645+
followRedirects: false,
645646
})
646647
expect(res.statusCode).toBe(302)
647648
expect(res.headers.location).toBe(`/${languageKey}`)
@@ -661,6 +662,7 @@ describe('server', () => {
661662
headers: {
662663
'accept-language': 'ldfir;',
663664
},
665+
followRedirects: false,
664666
})
665667

666668
expect(res.statusCode).toBe(302)
@@ -675,6 +677,7 @@ describe('server', () => {
675677
// Tagalog: https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1=tl
676678
'accept-language': 'tl',
677679
},
680+
followRedirects: false,
678681
})
679682
expect(res.statusCode).toBe(302)
680683
expect(res.headers.location).toBe('/en')

0 commit comments

Comments
 (0)