passthrough
按原样执行拦截的请求。
调用签名
¥Call signature
function passthrough(): Response {}
passthrough.ts
Source code for the `passthrough` namespace.
用法
¥Usage
import { http, passthrough, HttpResponse } from 'msw'
export const handlers = [
http.get('/resource', ({ request }) => {
if (request.headers.has('x-my-header')) {
return passthrough()
}
return HttpResponse.text('Mocked response')
}),
]
与 bypass()
不同,passthrough()
函数不会导致额外的请求,并且旨在明确传递响应解析器中的拦截请求。因此,passthrough()
函数不能用于执行其他请求,只能用于处理已拦截的请求。
¥Unlike bypass()
, the passthrough()
function does not result in an additional request, and is designed to explicitly pass through an intercepted request within the response resolver. Because of this, the passthrough()
function cannot be used to perform an additional request, only to handle an already intercepted one.
相关材料
¥Related materials
bypass
Perform an additional request outside of the interception algorithm.