Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying flood warnings and alerts broken #155

Merged
merged 6 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions server/__tests__/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,36 @@ describe('util.js tests', () => {
expect(error.message).toEqual('Requested resource returned a non 200 status code')
}
})

test('get includes User-Agent header in the request', async () => {
const url = MOCK_URL
const options = {}
const response = { res: { statusCode: STATUS_CODES.HTTP_STATUS_OK }, payload: 'response' }

wreck.get.mockResolvedValue(response)

await util.get(url, options)

expect(wreck.get).toHaveBeenCalledWith(url, expect.objectContaining({
headers: expect.objectContaining({
'User-Agent': 'hapi-wreck/18 (cyltfr-app)'
})
}))
})

test('post includes User-Agent header in the request', async () => {
const url = MOCK_URL
const options = {}
const response = { res: { statusCode: STATUS_CODES.HTTP_STATUS_OK }, payload: 'response' }

wreck.post.mockResolvedValue(response)

await util.post(url, options)

expect(wreck.post).toHaveBeenCalledWith(url, expect.objectContaining({
headers: expect.objectContaining({
'User-Agent': 'hapi-wreck/18 (cyltfr-app)'
})
}))
})
})
18 changes: 15 additions & 3 deletions server/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ if (config.http_proxy) {
agent: new HttpsProxyAgent(config.http_proxy)
})
}

const customUaHeader = 'hapi-wreck/18 (cyltfr-app)'
const { performance } = require('node:perf_hooks')
const get = (url, options, ext = false) => {
const get = (url, options = {}, ext = false) => {
const thisWreck = (ext && wreckExt) ? wreckExt : wreck
const startTick = performance.now()
// Header with UA added for AWS WAF as it is required, otherwise it will block the request
options.headers = {
...options.headers,
'User-Agent': customUaHeader
}

return thisWreck.get(url, options)
.then(response => {
if (config.performanceLogging) {
Expand All @@ -38,9 +44,15 @@ const get = (url, options, ext = false) => {
})
}

const post = (url, options, ext = false) => {
const post = (url, options = {}, ext = false) => {
const thisWreck = (ext && wreckExt) ? wreckExt : wreck
const startTick = performance.now()
// Header with UA added for AWS WAF as it is required, otherwise it will block the request
options.headers = {
...options.headers,
'User-Agent': customUaHeader
}

return thisWreck.post(url, options)
.then(response => {
if (config.performanceLogging) {
Expand Down