@@ -6,6 +6,8 @@ import * as util from "util";
66import * as url from "url" ;
77
88import { Emitter } from "vs/base/common/event" ;
9+ import { getMediaMime } from "vs/base/common/mime" ;
10+ import { extname } from "vs/base/common/path" ;
911import { IPCServer , ClientConnectionEvent } from "vs/base/parts/ipc/common/ipc" ;
1012import { validatePaths } from "vs/code/node/paths" ;
1113import { parseMainProcessArgv } from "vs/platform/environment/node/argvHelper" ;
@@ -59,10 +61,11 @@ export class Server implements IServer {
5961 public constructor ( ) {
6062 this . server = http . createServer ( async ( request , response ) : Promise < void > => {
6163 try {
62- const content = await this . handleRequest ( request ) ;
64+ const [ content , headers ] = await this . handleRequest ( request ) ;
6365 response . writeHead ( HttpCode . Ok , {
6466 "Cache-Control" : "max-age=86400" ,
6567 // TODO: ETag?
68+ ...headers ,
6669 } ) ;
6770 response . end ( content ) ;
6871 } catch ( error ) {
@@ -113,7 +116,7 @@ export class Server implements IServer {
113116 } ) ;
114117 }
115118
116- private async handleRequest ( request : http . IncomingMessage ) : Promise < string | Buffer > {
119+ private async handleRequest ( request : http . IncomingMessage ) : Promise < [ string | Buffer , http . OutgoingHttpHeaders ] > {
117120 if ( request . method !== "GET" ) {
118121 throw new HttpError (
119122 `Unsupported method ${ request . method } ` ,
@@ -150,14 +153,23 @@ export class Server implements IServer {
150153
151154 html = html . replace ( '{{WEBVIEW_ENDPOINT}}' , JSON . stringify ( options . WEBVIEW_ENDPOINT ) ) ;
152155
153- return html ;
156+ return [ html , {
157+ "Content-Type" : "text/html" ,
158+ } ] ;
154159 }
155160
156161 try {
157162 const content = await util . promisify ( fs . readFile ) (
158163 path . join ( this . rootPath , requestPath ) ,
159164 ) ;
160- return content ;
165+ return [ content , {
166+ "Content-Type" : getMediaMime ( requestPath ) || {
167+ ".css" : "text/css" ,
168+ ".html" : "text/html" ,
169+ ".js" : "text/javascript" ,
170+ ".json" : "application/json" ,
171+ } [ extname ( requestPath ) ] || "text/plain" ,
172+ } ] ;
161173 } catch ( error ) {
162174 if ( error . code === "ENOENT" || error . code === "EISDIR" ) {
163175 throw new HttpError ( "Not found" , HttpCode . NotFound ) ;
0 commit comments