MCPcopy
hub / github.com/node-formidable/formidable / plugin

Function plugin

src/plugins/multipart.js:10–37  ·  view source on GitHub ↗
(formidable, options)

Source from the content-addressed store, hash-verified

8export const multipartType = 'multipart';
9// the `options` is also available through the `options` / `formidable.options`
10export default function plugin(formidable, options) {
11 // the `this` context is always formidable, as the first argument of a plugin
12 // but this allows us to customize/test each plugin
13
14 /* istanbul ignore next */
15 const self = this || formidable;
16
17 // NOTE: we (currently) support both multipart/form-data and multipart/related
18 const multipart = /multipart/i.test(self.headers['content-type']);
19
20 if (multipart) {
21 const m = self.headers['content-type'].match(
22 /boundary=(?:"([^"]+)"|([^;]+))/i,
23 );
24 if (m) {
25 const initMultipart = createInitMultipart(m[1] || m[2]);
26 initMultipart.call(self, self, options); // lgtm [js/superfluous-trailing-arguments]
27 } else {
28 const err = new FormidableError(
29 'bad content-type header, no multipart boundary',
30 errors.missingMultipartBoundary,
31 400,
32 );
33 self._error(err);
34 }
35 }
36 return self;
37}
38
39// Note that it's a good practice (but it's up to you) to use the `this.options` instead
40// of the passed `options` (second) param, because when you decide

Callers

nothing calls this directly

Calls 2

createInitMultipartFunction · 0.85
_errorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…