(formidable, options)
| 8 | export const multipartType = 'multipart'; |
| 9 | // the `options` is also available through the `options` / `formidable.options` |
| 10 | export 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…