Skip to content

Commit

Permalink
fix: use cache-content-type (#2793)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored and fengmk2 committed Jul 12, 2018
1 parent 2ca8f01 commit 9f8926d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
14 changes: 1 addition & 13 deletions app/extend/response.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
'use strict';

const contentType = require('mime-types').contentType;
const getType = require('cache-content-type');
const isJSON = require('koa-is-json');
const LRU = require('ylru');

const REAL_STATUS = Symbol('Context#realStatus');

const typeLRUCache = new LRU(100);
function getType(type) {
let mimeType = typeLRUCache.get(type);
if (!mimeType) {
mimeType = contentType(type);
typeLRUCache.set(type, mimeType);
}
return mimeType;
}

module.exports = {

/**
Expand Down Expand Up @@ -64,7 +53,6 @@ module.exports = {
// copy from koa
// Different:
// - change header name to lower case
// - improve mimeType detect by local lru cache
type = getType(type);
if (type) {
this.set('content-type', type);
Expand Down
43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,59 @@
],
"dependencies": {
"@types/accepts": "^1.3.5",
"@types/koa": "^2.0.45",
"@types/koa-router": "^7.0.27",
"@types/urllib": "^2.25.0",
"@types/koa": "^2.0.46",
"@types/koa-router": "^7.0.30",
"@types/urllib": "^2.28.0",
"accepts": "^1.3.5",
"agentkeepalive": "^3.4.1",
"circular-json": "^0.5.3",
"cluster-client": "^2.1.0",
"cache-content-type": "^1.0.0",
"circular-json": "^0.5.5",
"cluster-client": "^2.1.1",
"debug": "^3.1.0",
"delegates": "^1.0.0",
"egg-cluster": "^1.16.0",
"egg-cluster": "^1.18.0",
"egg-cookies": "^2.2.2",
"egg-core": "^4.6.0",
"egg-development": "^2.2.0",
"egg-core": "^4.8.0",
"egg-development": "^2.3.1",
"egg-i18n": "^2.0.0",
"egg-jsonp": "^2.0.0",
"egg-logger": "^1.6.2",
"egg-logger": "^1.7.1",
"egg-logrotator": "^3.0.3",
"egg-multipart": "^2.0.0",
"egg-onerror": "^2.0.0",
"egg-onerror": "^2.1.0",
"egg-schedule": "^3.3.0",
"egg-security": "^2.2.2",
"egg-security": "^2.2.3",
"egg-session": "^3.1.0",
"egg-static": "^2.1.0",
"egg-static": "^2.1.1",
"egg-view": "^2.1.0",
"egg-watcher": "^3.0.0",
"extend2": "^1.0.0",
"graceful": "^1.0.1",
"humanize-ms": "^1.2.1",
"is-type-of": "^1.2.0",
"koa-bodyparser": "^4.2.0",
"koa-bodyparser": "^4.2.1",
"koa-is-json": "^1.0.0",
"koa-override": "^3.0.0",
"mime-types": "^2.1.18",
"ms": "^2.1.1",
"on-finished": "^2.3.0",
"sendmessage": "^1.1.0",
"urllib": "^2.27.0",
"utility": "^1.13.1",
"ylru": "^1.2.0"
"urllib": "^2.29.0",
"utility": "^1.14.0",
"ylru": "^1.2.1"
},
"devDependencies": {
"address": "^1.0.3",
"autod": "^3.0.1",
"autod-egg": "^1.1.0",
"coffee": "^4.1.0",
"egg-alinode": "^1.0.3",
"egg-bin": "^4.7.0",
"egg-bin": "^4.7.1",
"egg-doctools": "^2.3.1",
"egg-mock": "^3.17.0",
"egg-mock": "^3.17.2",
"egg-plugin-puml": "^2.4.0",
"egg-tracer": "^1.1.0",
"egg-view-nunjucks": "^2.2.0",
"eslint": "^4.19.1",
"eslint": "^5.1.0",
"eslint-config-egg": "^7.0.0",
"findlinks": "^1.1.0",
"formstream": "^1.1.0",
Expand All @@ -76,7 +77,7 @@
"pedding": "^1.1.0",
"runscript": "^1.3.0",
"spy": "^1.0.0",
"supertest": "^3.0.0",
"supertest": "^3.1.0",
"ts-node": "^3.0.6",
"typescript": "^2.8.0",
"webstorm-disable-index": "^1.1.2"
Expand Down

0 comments on commit 9f8926d

Please sign in to comment.