Skip to content

Commit 5fadd48

Browse files
zhangruizhuohaoxin
authored and
haoxin
committedJun 19, 2018
fix bug that set Content-Type not working. (#105)
1 parent 0ce9e23 commit 5fadd48

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async function send (ctx, path, opts = {}) {
136136
}
137137
ctx.set('Cache-Control', directives.join(','))
138138
}
139-
ctx.type = type(path, encodingExt)
139+
if (!ctx.type) ctx.type = type(path, encodingExt)
140140
ctx.body = fs.createReadStream(path)
141141

142142
return path

‎test/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,22 @@ describe('send(ctx, file)', function () {
725725
.end(done)
726726
})
727727

728+
it('should set the Content-Type', function (done) {
729+
const app = new Koa()
730+
731+
const testFilePath = path.normalize('/test/fixtures/world/index.html')
732+
733+
app.use(async (ctx) => {
734+
ctx.type = 'text/plain'
735+
await send(ctx, testFilePath)
736+
})
737+
738+
request(app.listen())
739+
.get('/')
740+
.expect('Content-Type', /text\/plain/)
741+
.end(done)
742+
})
743+
728744
it('should set Last-Modified', function (done) {
729745
const app = new Koa()
730746

0 commit comments

Comments
 (0)
Please sign in to comment.