You are not logged in.
Pages: 1
I've been trying the http.sys implementation using HTTP_RESP_STATICFILE to send files which works great. Only small niggle is *.css and *.js are being sent with a content type of text/plain which can give a warning in the web browser. Html and jpeg static files get sent with the right content type.
Is this a problem in http.sys or should I set the content type as a custom header?
Offline
You should set definitively a 'Content-type: ......' corresponding to the file in the OutCustomHeader parameter.
I've now specified this in this comment:
const
/// used by THttpApiServer.Request for http.sys to send a static file
// - the OutCustomHeader should contain the proper 'Content-type: ....'
// corresponding to the file
HTTP_RESP_STATICFILE = '!STATICFILE';
Online
Thanks, got it working but noticed you must put a space between 'Content-Type' and ':' otherwise the colon gets repeated in the final header.
Could it be worth mentioning GetMimeContentType function in SynCommons.pas in the source code comment as a way to get the content type?
I've put a function below to get the content type from a file extension instead which might be useful - does this look a sensible way to go about it?
function GetMIMEfromFileExt(ext: string): string;
const
extList = 'HTMLJSCSSJPGIFPDFZIPNG';
begin
result := '';
case posex(uppercase(ext), extList) of
1 : result := 'text/html';
5 : result := 'application/javascript';
7 : result := 'text/css';
10 : result := 'image/jpeg';
12 : result := 'image/gif';
15 : result := 'application/pdf';
18 : result := 'application/zip';
20 : result := 'image/png';
end;
end;
Offline
Worked out why I'm getting two colons after the content-type response header. It looks like there needs to be
inc(P);
after line 3621 of HTTP_RESPONSE.SetHeaders in synCRTsocks.pas. If that's right could you change it.
Out of interest why does it need to distinguish between known and unknown headers?
Thanks
Offline
Nice catch! There was a missing line here...
See http://synopse.info/fossil/info/481e6424bd
About the distinction, it's what http.sys expects: some standard headers are parsed within the http.sys library, whereas some custom headers need to be parsed manually.
Online
Pages: 1