-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dotnet, node, php, python): exclude OPTIONS requests from being …
…logged (#1070) | 🚥 Resolves #58 | | :------------------- | ## 🧰 Changes Add a middleware checks for skipping OPTIONS requests
- Loading branch information
1 parent
b073f7d
commit 642c293
Showing
9 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { ExtendedIncomingMessage, ExtendedResponse, Options } from 'src/lib/log'; | ||
import type { GroupingObject } from 'src/lib/metrics-log'; | ||
|
||
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'; | ||
|
||
import { log } from '../../src/lib/log'; | ||
import { metricsAPICall } from '../../src/lib/metrics-log'; | ||
|
||
describe('log', function () { | ||
vi.mock('../../src/lib/metrics-log'); | ||
|
||
let req: ExtendedIncomingMessage; | ||
let res: ExtendedResponse; | ||
let group: GroupingObject; | ||
let options: Options; | ||
|
||
beforeEach(() => { | ||
req = { | ||
method: 'GET', | ||
headers: {}, | ||
url: '/', | ||
} as ExtendedIncomingMessage; | ||
|
||
res = { | ||
statusCode: 200, | ||
getHeader: vi.fn(), | ||
setHeader: vi.fn(), | ||
removeListener: vi.fn(), | ||
once: vi.fn(), | ||
} as unknown as ExtendedResponse; | ||
|
||
group = { apiKey: 'test-api-key' }; | ||
options = { bufferLength: 1 }; | ||
}); | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
it('should not log OPTIONS requests', function () { | ||
req.method = 'OPTIONS'; | ||
const logId = log('api-key', req, res, group, options); | ||
expect(logId).toBeUndefined(); | ||
expect(metricsAPICall).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters