-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add an onIdentifyRequest hook to allow adapter level serializat…
…ion (#140)
- Loading branch information
1 parent
19147f7
commit 548002c
Showing
23 changed files
with
318 additions
and
132 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
File renamed without changes.
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
File renamed without changes.
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
51 changes: 0 additions & 51 deletions
51
packages/@pollyjs/core/src/utils/serialize-request-body.js
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
packages/@pollyjs/core/tests/browser/unit/utils/serialize-request-body-test.js
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,26 @@ | ||
export const supportsBlob = (() => { | ||
try { | ||
return !!new Blob(); | ||
} catch (e) { | ||
return false; | ||
} | ||
})(); | ||
|
||
export function readBlob(blob) { | ||
return new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
|
||
reader.onend = reject; | ||
reader.onabort = reject; | ||
reader.onload = () => resolve(reader.result); | ||
reader.readAsDataURL(new Blob([blob], { type: blob.type })); | ||
}); | ||
} | ||
|
||
export async function serialize(body) { | ||
if (supportsBlob && body instanceof Blob) { | ||
return await readBlob(body); | ||
} | ||
|
||
return body; | ||
} |
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,29 @@ | ||
/* eslint-env node */ | ||
|
||
export const supportsBuffer = typeof Buffer !== 'undefined'; | ||
export const supportsArrayBuffer = typeof ArrayBuffer !== 'undefined'; | ||
|
||
export function serialize(body) { | ||
if (supportsBuffer && body) { | ||
let buffer; | ||
|
||
if (Buffer.isBuffer(body)) { | ||
buffer = body; | ||
} else if (Array.isArray(body) && body.some(c => Buffer.isBuffer(c))) { | ||
// Body is a chunked array | ||
const chunks = body.map(c => Buffer.from(c)); | ||
|
||
buffer = Buffer.concat(chunks); | ||
} else if (`${body}` === '[object ArrayBuffer]') { | ||
buffer = Buffer.from(body); | ||
} else if (supportsArrayBuffer && ArrayBuffer.isView(body)) { | ||
buffer = Buffer.from(body.buffer, body.byteOffset, body.byteLength); | ||
} | ||
|
||
if (Buffer.isBuffer(buffer)) { | ||
return buffer.toString('hex'); | ||
} | ||
} | ||
|
||
return body; | ||
} |
Oops, something went wrong.