Overview
Features
Download
Documentation
Community
Add-Ons & Services

HTTPServer cache control directive

Please post support and help requests here.

HTTPServer cache control directive

Postby Budric » 21 Aug 2007, 17:23

Hi,
first let me complement the developers of this library. Very clean design and I like the coding style (eg. names compared to some of the things from Boost). I hope this library grows.

My question is as follows: I have implemented an HTTP server based on the example. When a request for an image comes in, I read in the image file and stream it to the user. Here's the bit of code:

response.setChunkedTransferEncoding(true);
std::string contentType("image/");
contentType.append(fileType);
response.setContentType(contentType);
response.send().write((char *)blob.data(), blob.length());

For some reason the client browsers do not cache the images. I read in the specification about HTTP caching directives and I was wondering how those extra headers can be set in the response so the client caches the image. I looked over the API docs but no luck finding it.

Thanks
Budric
 
Posts: 5
Joined: 03 Aug 2007, 18:35

Re: HTTPServer cache control directive

Postby Budric » 21 Aug 2007, 17:39

P.S.
I know about sendFile() method. I do some image manupulation and need to send the blob (bytes). Just want to know how to access the response header and add some more stuff to it.
Budric
 
Posts: 5
Joined: 03 Aug 2007, 18:35

Re: HTTPServer cache control directive

Postby alex » 21 Aug 2007, 17:50

> For some reason the client browsers do not cache the images. I read in the specification about HTTP caching directives and I was wondering how those extra headers can be set in the response so the client caches the image. I looked over the API docs but no luck finding it.

Code: Select all

response.add("Cache-Control: ", "max-age=86400");

Alternative is via html meta tags:

Code: Select all

<meta http-equiv="cache-control" content="Wed, 22 Aug 2007 08:21:57 GMT" > )


Alex

PS: I recall reading somewhere that IE cheats on this particular issue by ignoring cache directives in order to pump up the statistics for browser usage.
alex
 
Posts: 1046
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Re: HTTPServer cache control directive

Postby alex » 21 Aug 2007, 17:54

Code: Select all

> <meta http-equiv="cache-control" content="Wed, 22 Aug 2007 08:21:57 GMT" > )


Sorry, I meant "expires":

Code: Select all

<meta http-equiv="expires" content="Wed, 22 Aug 2007 08:21:57 GMT" > )
alex
 
Posts: 1046
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests