From 9cc86fe7d956bce1a9fbdb941a38117d556044c8 Mon Sep 17 00:00:00 2001 From: YanagiEiichi Date: Thu, 27 Dec 2018 01:53:40 +0800 Subject: [PATCH] Fix empty mime --- index.js | 3 ++- tests/404.html | 8 ++++++++ tests/raw-404.html | 8 ++++++++ tests/raw-basic.html | 13 +++++++++++++ tests/raw-json.html | 12 ++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/404.html create mode 100644 tests/raw-404.html create mode 100644 tests/raw-basic.html create mode 100644 tests/raw-json.html diff --git a/index.js b/index.js index d40a32f..65b34be 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,8 @@ class API extends Function { // eslint-disable-line no-unused-vars Object.defineProperty(response, 'auto', { configurable: true, async value() { - const type = this.headers.get('Content-Type').match(/\b(json|text)\b/g).sort()[0] || 'blob'; + const mime = this.headers.get('Content-Type') || 'unknown'; + const type = mime.match(/\b(json|text|$)\b/g).filter(Boolean).sort()[0] || 'blob'; switch (true) { case this.status === 204: return null; case this.ok: return this[type](); diff --git a/tests/404.html b/tests/404.html new file mode 100644 index 0000000..e1660c5 --- /dev/null +++ b/tests/404.html @@ -0,0 +1,8 @@ + + + diff --git a/tests/raw-404.html b/tests/raw-404.html new file mode 100644 index 0000000..df785f1 --- /dev/null +++ b/tests/raw-404.html @@ -0,0 +1,8 @@ + + + diff --git a/tests/raw-basic.html b/tests/raw-basic.html new file mode 100644 index 0000000..0bfc505 --- /dev/null +++ b/tests/raw-basic.html @@ -0,0 +1,13 @@ + + + diff --git a/tests/raw-json.html b/tests/raw-json.html new file mode 100644 index 0000000..64f245c --- /dev/null +++ b/tests/raw-json.html @@ -0,0 +1,12 @@ + + +