Skip to content

Commit

Permalink
fix: match pre-requests in reverse order
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Dec 7, 2021
1 parent 008613f commit 6292de3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/proxy/lib/http/util/prerequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ process.once('exit', () => {
})

function removeOne<T> (a: Array<T>, predicate: (v: T) => boolean): T | void {
for (const i in a) {
for (let i = a.length - 1; i >= 0; i--) {
const v = a[i]

if (predicate(v)) {
a.splice(i as unknown as number, 1)
a.splice(i, 1)

return v
}
Expand Down
2 changes: 2 additions & 0 deletions packages/proxy/test/unit/http/util/prerequests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('http/util/prerequests', () => {
})

it('synchronously matches a pre-request that existed at the time of the request', () => {
// should match in reverse order
preRequests.addPending({ requestId: '1234', url: 'foo', method: 'WRONGMETHOD' } as BrowserPreRequest)
preRequests.addPending({ requestId: '1234', url: 'foo', method: 'GET' } as BrowserPreRequest)

const cb = sinon.stub()
Expand Down

0 comments on commit 6292de3

Please sign in to comment.