Skip to content

Commit

Permalink
Merge pull request #31958 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
  • Loading branch information
docs-bot authored Mar 5, 2024
2 parents 1107301 + 3468553 commit 0f5f1f9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@
"sass": "^1.52.3",
"start-server-and-test": "^2.0.3",
"ts-jest": "29.1.1",
"tsx": "4.7.0",
"typescript": "^5.2.2",
"tsx": "4.7.1",
"typescript": "^5.3.3",
"unist-util-remove": "^4.0.0",
"unist-util-visit-parents": "6.0.1",
"website-scraper": "^5.3.1"
Expand Down
16 changes: 3 additions & 13 deletions src/shielding/middleware/handle-invalid-headers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import statsd from '#src/observability/lib/statsd.js'
import { errorCacheControl } from '#src/frame/middleware/cache-control.js'

const STATSD_KEY = 'middleware.handle_invalid_headers'

const INVALID_HEADER_KEYS = [
// Next.js will pick this up and override the status code.
// We don't want that to happen because `x-invoke-status: 203` can
Expand All @@ -15,14 +10,9 @@ const INVALID_HEADER_KEYS = [
export default function handleInvalidNextPaths(req, res, next) {
const header = INVALID_HEADER_KEYS.find((key) => req.headers[key])
if (header) {
// This way you can't hammer the backend with invalid requests.
// Since the CDN will cache based on the status code not being one
// of success, we don't have to worry about this being cached when
// the URL is the same but the headers *not invalid*.
errorCacheControl(res)

const tags = [`ip:${req.ip}`, `path:${req.path}`, `header:${header}`]
statsd.increment(STATSD_KEY, 1, tags)
// There's no point attempting to set a cache-control on this.
// The CDN will not cache if the status code is not a success
// and not a 404.

return res.status(400).type('text').send('Invalid request headers')
}
Expand Down
4 changes: 0 additions & 4 deletions src/shielding/tests/invalid-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ describe('invalid headers', () => {
test('400 if containing x-invoke-status (instead of redirecting)', async () => {
const res = await get('/', { headers: { 'x-invoke-status': '203' } })
expect(res.statusCode).toBe(400)
expect(res.headers['cache-control']).toMatch('public')
expect(res.headers['cache-control']).toMatch(/max-age=[1-9]/)
})
test('400 if containing x-invoke-status (instead of 200)', async () => {
const res = await get('/en', { headers: { 'x-invoke-status': '203' } })
expect(res.statusCode).toBe(400)
expect(res.headers['cache-control']).toMatch('public')
expect(res.headers['cache-control']).toMatch(/max-age=[1-9]/)
})
})

0 comments on commit 0f5f1f9

Please sign in to comment.