static private MakeContentTypeHeader ( string fileName ) : String | ||
fileName | string | |
Résultat | String |
static String MakeContentTypeHeader(string fileName)
{
Debug.Assert(File.Exists(fileName));
string contentType = null;
var info = new FileInfo(fileName);
string extension = info.Extension.ToLowerInvariant();
switch (extension) {
case ".bmp":
contentType = "image/bmp";
break;
case ".css":
contentType = "text/css";
break;
case ".gif":
contentType = "image/gif";
break;
case ".ico":
contentType = "image/x-icon";
break;
case ".htm" :
case ".html":
contentType = "text/html";
break;
case ".jpe":
case ".jpeg":
case ".jpg":
contentType = "image/jpeg";
break;
case ".js":
contentType = "application/x-javascript";
break;
default:
break;
}
if (contentType == null) {
return null;
}
return "Content-Type: " + contentType + "\r\n";
}
public override void SendKnownResponseHeader(int index, string value) { if (_headersSent) { return; } switch (index) { case HttpWorkerRequest.HeaderServer: case HttpWorkerRequest.HeaderDate: case HttpWorkerRequest.HeaderConnection: // ignore these return; case HttpWorkerRequest.HeaderAcceptRanges: if (value == "bytes") { // use this header to detect when we're processing a static file _specialCaseStaticFileHeaders = true; return; } break; case HttpWorkerRequest.HeaderExpires: case HttpWorkerRequest.HeaderLastModified: if (_specialCaseStaticFileHeaders) { // NOTE: Ignore these for static files. These are generated // by the StaticFileHandler, but they shouldn't be. return; } break; case HttpWorkerRequest.HeaderContentType: /* * MakeContentTypeHeader handles some mime types, noteably SVG, * that are not automagically handled via SimpleRequest, and returns * null otherwise. */ string contentType = Connection.MakeContentTypeHeader(_pathTranslated); value = contentType ?? value; break; } _responseHeadersBuilder.Append(GetKnownResponseHeaderName(index)); _responseHeadersBuilder.Append(": "); _responseHeadersBuilder.Append(value); _responseHeadersBuilder.Append("\r\n"); }