#1 2011-03-23 10:05:29

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

http.sys content type

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

#2 2011-03-23 12:04:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,492
Website

Re: http.sys content type

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';

Offline

#3 2011-03-23 21:08:41

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: http.sys content type

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

#4 2011-03-24 09:47:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,492
Website

Re: http.sys content type

Yes it seems OK.

Offline

#5 2011-08-16 15:11:51

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: http.sys content type

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

#6 2011-08-16 15:21:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,492
Website

Re: http.sys content type

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.

Offline

Board footer

Powered by FluxBB