add mime information to universal path; include content type in static server
This commit is contained in:
parent
34863a26a7
commit
d383cebe78
@ -38,6 +38,7 @@ export default class FileResponseFactory extends ResponseFactory {
|
|||||||
if ( content.headers && content.body && length ) {
|
if ( content.headers && content.body && length ) {
|
||||||
request.response.body = content.body
|
request.response.body = content.body
|
||||||
request.response.headers.set('Content-Length', length)
|
request.response.headers.set('Content-Length', length)
|
||||||
|
request.response.headers.set('Content-Type', path.content_type)
|
||||||
} else {
|
} else {
|
||||||
this.logger.debug(`Tried to serve file that does not exist: ${path}`)
|
this.logger.debug(`Tried to serve file that does not exist: ${path}`)
|
||||||
request.response.status = HTTPStatus.NOT_FOUND
|
request.response.status = HTTPStatus.NOT_FOUND
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { path as deno_path } from '../external/std.ts'
|
import { path as deno_path } from '../external/std.ts'
|
||||||
|
import * as Mime from 'https://deno.land/x/media_types/mod.ts'
|
||||||
|
|
||||||
export enum UniversalPathPrefix {
|
export enum UniversalPathPrefix {
|
||||||
HTTP = 'http://',
|
HTTP = 'http://',
|
||||||
@ -87,4 +88,20 @@ export class UniversalPath {
|
|||||||
toString() {
|
toString() {
|
||||||
return `${this.prefix}${this._local}`
|
return `${this.prefix}${this._local}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get ext() {
|
||||||
|
return deno_path.extname(this._local)
|
||||||
|
}
|
||||||
|
|
||||||
|
get mime_type() {
|
||||||
|
return Mime.lookup(this.ext)
|
||||||
|
}
|
||||||
|
|
||||||
|
get content_type() {
|
||||||
|
return Mime.contentType(this.ext)
|
||||||
|
}
|
||||||
|
|
||||||
|
get charset() {
|
||||||
|
return Mime.charset(this.mime_type)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user