Skip to content

Commit

Permalink
Merge branch 'main' into http2
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Aug 30, 2023
2 parents 75f6a2c + 111fd23 commit b0a9667
Show file tree
Hide file tree
Showing 186 changed files with 3,482 additions and 664 deletions.
3 changes: 2 additions & 1 deletion docs/api/MockPool.md
Expand Up @@ -35,7 +35,8 @@ const mockPool = mockAgent.get('http://localhost:3000')

### `MockPool.intercept(options)`

This method defines the interception rules for matching against requests for a MockPool or MockPool. We can intercept multiple times on a single instance.
This method defines the interception rules for matching against requests for a MockPool or MockPool. We can intercept multiple times on a single instance, but each intercept is only used once.
For example if you expect to make 2 requests inside a test, you need to call `intercept()` twice. Assuming you use `disableNetConnect()` you will get `MockNotMatchedError` on the second request when you only call `intercept()` once.

When defining interception rules, all the rules must pass for a request to be intercepted. If a request is not intercepted, a real request will be attempted.

Expand Down
2 changes: 1 addition & 1 deletion lib/fetch/response.js
Expand Up @@ -49,7 +49,7 @@ class Response {
}

// https://fetch.spec.whatwg.org/#dom-response-json
static json (data = undefined, init = {}) {
static json (data, init = {}) {
webidl.argumentLengthCheck(arguments, 1, { header: 'Response.json' })

if (init !== null) {
Expand Down
25 changes: 23 additions & 2 deletions lib/fetch/util.js
Expand Up @@ -556,16 +556,37 @@ function bytesMatch (bytes, metadataList) {
const algorithm = item.algo

// 2. Let expectedValue be the val component of item.
const expectedValue = item.hash
let expectedValue = item.hash

// See https://github.com/web-platform-tests/wpt/commit/e4c5cc7a5e48093220528dfdd1c4012dc3837a0e
// "be liberal with padding". This is annoying, and it's not even in the spec.

if (expectedValue.endsWith('==')) {
expectedValue = expectedValue.slice(0, -2)
}

// 3. Let actualValue be the result of applying algorithm to bytes.
const actualValue = crypto.createHash(algorithm).update(bytes).digest('base64')
let actualValue = crypto.createHash(algorithm).update(bytes).digest('base64')

if (actualValue.endsWith('==')) {
actualValue = actualValue.slice(0, -2)
}

// 4. If actualValue is a case-sensitive match for expectedValue,
// return true.
if (actualValue === expectedValue) {
return true
}

let actualBase64URL = crypto.createHash(algorithm).update(bytes).digest('base64url')

if (actualBase64URL.endsWith('==')) {
actualBase64URL = actualBase64URL.slice(0, -2)
}

if (actualBase64URL === expectedValue) {
return true
}
}

// 6. Return false.
Expand Down
2 changes: 2 additions & 0 deletions test/wpt/runner/runner.mjs
Expand Up @@ -312,6 +312,8 @@ export class WPTRunner extends EventEmitter {
`unexpected failures: ${failed - expectedFailures}, ` +
`skipped: ${skipped}`
)

process.exit(0)
}

addInitScript (code) {
Expand Down
8 changes: 7 additions & 1 deletion test/wpt/status/fetch.status.json
Expand Up @@ -2,11 +2,13 @@
"api": {
"abort": {
"general.any.js": {
"note": "TODO(@KhafraDev): Clone aborts with original controller can probably be fixed",
"fail": [
"Already aborted signal rejects immediately",
"Underlying connection is closed when aborting after receiving response - no-cors",
"Stream errors once aborted. Underlying connection closed.",
"Readable stream synchronously cancels with AbortError if aborted before reading"
"Readable stream synchronously cancels with AbortError if aborted before reading",
"Clone aborts with original controller"
]
},
"cache.https.any.js": {
Expand Down Expand Up @@ -128,6 +130,10 @@
]
}
},
"fetch-later": {
"note": "this is not part of the spec, only a proposal",
"skip": true
},
"headers": {
"header-setcookie.any.js": {
"note": "undici doesn't filter headers",
Expand Down

0 comments on commit b0a9667

Please sign in to comment.