diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4e42345 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.http -text diff --git a/README.md b/README.md index db1890f..032bffe 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Build Status][travis-image]][travis-url] [![Test Coverage][coveralls-image]][coveralls-url] -Parse http requests with content-type `multipart/form-data`, also known as file uploads. +Parse http requests with content-type `multipart/form-data`, also known as file uploads, or `multipart/mixed`. See also [busboy](https://github.com/mscdex/busboy) - a [faster](https://github.com/mscdex/dicer/wiki/Benchmarks) alternative diff --git a/index.js b/index.js index 41bfeb0..3dd6316 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ var COLON = 58; var A = 97; var Z = 122; -var CONTENT_TYPE_RE = /^multipart\/(?:form-data|related)(?:;|$)/i; +var CONTENT_TYPE_RE = /^multipart\/(?:form-data|related|mixed)(?:;|$)/i; var CONTENT_TYPE_PARAM_RE = /;\s*([^=]+)=(?:"([^"]+)"|([^;]+))/gi; var FILE_EXT_RE = /(\.[_\-a-zA-Z0-9]{0,16}).*/; var LAST_BOUNDARY_SUFFIX_LEN = 4; // --\r\n diff --git a/test/fixture/http/content-type/multipart-mixed.http b/test/fixture/http/content-type/multipart-mixed.http new file mode 100644 index 0000000..0a046f1 --- /dev/null +++ b/test/fixture/http/content-type/multipart-mixed.http @@ -0,0 +1,13 @@ +POST /upload HTTP/1.1 +Host: localhost:8080 +Content-Type: multipart/form-data; custom=stuff; boundary=----TLV0SrKD4z1TRxRhAPUvZ +Content-Length: 213 + +------TLV0SrKD4z1TRxRhAPUvZ +Content-Disposition: form-data; name="file"; filename="plain.txt" +Content-Type: text/plain +Content-Transfer-Encoding: 7bit + +I am a plain text file + +------TLV0SrKD4z1TRxRhAPUvZ-- diff --git a/test/fixture/js/content-type.js b/test/fixture/js/content-type.js index fc5f0a0..ca3db08 100644 --- a/test/fixture/js/content-type.js +++ b/test/fixture/js/content-type.js @@ -42,3 +42,14 @@ module.exports['custom-equal-sign.http'] = [ size: 24, } ]; + +module.exports['multipart-mixed.http'] = [ + { + type: 'file', + name: 'file', + filename: 'plain.txt', + fixture: 'plain.txt', + sha1: 'b31d07bac24ac32734de88b3687dddb10e976872', + size: 23, + } +];