Skip to content

Commit

Permalink
[PLAT-12111] Add Access-Control-Max-Age header (#2160)
Browse files Browse the repository at this point in the history
* added Access-Control-Max-Age header to delivery.sendEvent

* added changelog

* changed value to integer

* added condition for req header

* changed startsWith to substring

* fix changelog
  • Loading branch information
AnastasiiaSvietlova authored Sep 23, 2024
1 parent 7e7eb44 commit 6ae56c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ As well as some bug fixes and **breaking changes** described in the [Upgrade Gui

## [7.25.1] - 2024-08-27

### Added

- (delivery-xml-http-request) Add Access-Control-Max-Age header to CORS preflight responses [#2160](https://github.com/bugsnag/bugsnag-js/pull/2160)

### Changed

- (react-native) Update bugsnag-cocoa from v6.29.0 to [v6.30.1](https://github.com/bugsnag/bugsnag-cocoa/blob/master/CHANGELOG.md#6301-2024-07-25)
Expand Down
3 changes: 3 additions & 0 deletions packages/delivery-xml-http-request/delivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module.exports = (client, win = window) => ({
req.setRequestHeader('Bugsnag-Api-Key', event.apiKey || client._config.apiKey)
req.setRequestHeader('Bugsnag-Payload-Version', '4')
req.setRequestHeader('Bugsnag-Sent-At', (new Date()).toISOString())
if (url.substring(0, 5) === 'https') {
req.setRequestHeader('Access-Control-Max-Age', 86400)
}
req.send(body)
} catch (e) {
client._logger.error(e)
Expand Down
5 changes: 3 additions & 2 deletions packages/delivery-xml-http-request/test/delivery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ describe('delivery:XMLHttpRequest', () => {
const payload = { sample: 'payload' } as unknown as EventDeliveryPayload
const config = {
apiKey: 'aaaaaaaa',
endpoints: { notify: '/echo/' },
endpoints: { notify: 'https/echo/' },
redactedKeys: []
}

delivery({ _logger: {}, _config: config } as unknown as Client, { XMLHttpRequest } as unknown as Window).sendEvent(payload, (err: any) => {
expect(err).toBe(null)
expect(requests.length).toBe(1)
expect(requests[0].method).toBe('POST')
expect(requests[0].url).toMatch('/echo/')
expect(requests[0].url).toMatch('https/echo/')
expect(requests[0].headers['Content-Type']).toEqual('application/json')
expect(requests[0].headers['Bugsnag-Api-Key']).toEqual('aaaaaaaa')
expect(requests[0].headers['Bugsnag-Payload-Version']).toEqual('4')
expect(requests[0].headers['Bugsnag-Sent-At']).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/)
expect(requests[0].headers['Access-Control-Max-Age']).toEqual(86400)
expect(requests[0].data).toBe(JSON.stringify(payload))
done()
})
Expand Down

0 comments on commit 6ae56c4

Please sign in to comment.