MCPcopy
hub / github.com/mswjs/msw / parse

Method parse

src/core/handlers/HttpHandler.ts:123–163  ·  view source on GitHub ↗
(args: {
    request: Request
    resolutionContext?: ResponseResolutionContext
  })

Source from the content-addressed store, hash-verified

121 }
122
123 async parse(args: {
124 request: Request
125 resolutionContext?: ResponseResolutionContext
126 }) {
127 const url = new URL(args.request.url)
128 const cookies = getAllRequestCookies(args.request)
129
130 /**
131 * Handle custom predicate functions.
132 * @note Invoke this during parsing so the user can parse the path parameters
133 * manually. Otherwise, `params` is always an empty object, which isn't nice.
134 */
135 if (typeof this.info.path === 'function') {
136 const customPredicateResult = await this.info.path({
137 request: args.request,
138 cookies,
139 })
140
141 const match =
142 typeof customPredicateResult === 'boolean'
143 ? {
144 matches: customPredicateResult,
145 params: {},
146 }
147 : customPredicateResult
148
149 return {
150 match,
151 cookies,
152 }
153 }
154
155 const match = this.info.path
156 ? matchRequestUrl(url, this.info.path, args.resolutionContext?.baseUrl)
157 : { matches: false, params: {} }
158
159 return {
160 match,
161 cookies,
162 }
163 }
164
165 async predicate(args: {
166 request: Request

Callers 15

initFunction · 0.45
saveWorkerDirectoryFunction · 0.45
body.mocks.tsFile · 0.45
countConstructorsFunction · 0.45
readJsonFunction · 0.45
xhr.node.test.tsFile · 0.45
jsonParseFunction · 0.45
testFunction · 0.45
runFunction · 0.45

Calls 2

getAllRequestCookiesFunction · 0.90
matchRequestUrlFunction · 0.90

Tested by 3

countConstructorsFunction · 0.36
readJsonFunction · 0.36
testFunction · 0.36