Archive for the ‘Apache’ Category

Expires header doesn’t work on the iPhone / iPad

Posted on December 17th, 2010 in Apache, iOS, iPhone | No Comments »

I’m optimizing the web views of an iPhone app in preparation for Christmas traffic and one of the ideas I had was to use small increments of Expires header to cache files client-side. I assumed this would be no problem as all my work with Safari on the iPhone has shown it a very capable browser—as good as any desktop one.

Turns out after some testing that using Expires Header isn’t possible— not because of cache size limitations as one would assume. It looks like the guys in Cupertino wanted to limit this ability on the iOS as every HTTP request made by an iOS device issues a pragma: no-cache directive. I’ve yet to understand why. Better fire up more memcache servers.

Here’s the raw headers if interested:

GET /expires/ HTTP/1.1
User-Agent: Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Cookie: __utma=244034822.428964265.1285289496.1290546798.1290723961.13; __utmz=244034822.1285289496.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=1.1229958817.1285277083.1288920090.1292540519.14; __utmc=1; __utmz=1.1285277083.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Pragma: no-cache
Connection: keep-alive

Always remember: you can’t “expires header” an HTTP POST

Posted on December 17th, 2010 in Apache | 1 Comment »

This includes ajax content (which to the server is just a standard HTTP request.) This makes sense since POST should only be used for storing or updating data.

Thanks to this page.

How to add Ruby (.rhtml) support to your existing MAMP setup with eRuby

Posted on August 18th, 2008 in Apache, ruby | No Comments »

Adding Ruby HTML support to your existing MAMP setup is great for experimenting and for building quick single serving apps where a whole Rails setup would be overkill. This is how I added Ruby RHTML page support to my current MAMP setup:

Download and compile eRuby

  1. Download and unzip
  2. Go to the unzipped directory in terminal
  3. type ./configure.rb
  4. type make
  5. type make install
  6. Copy the generated eruby file to your local cgi-bin

Modify your httpd.conf settings

  1. add this line to add the rhtml support:
    AddType application/x-httpd-eruby .rhtml
    Action application/x-httpd-eruby /cgi-bin/eruby
  2. And modify this line so your server will look for index.rhtml pages in directories:
    DirectoryIndex index.html index.shtml index.rhtml

Running straight .rb files outside your cgi-bin folder (optional)

You can run any scripts from your cgi-bin if you properly add the #!(she bang) location to your ruby intepreter at the top of your scripts, but you can also make these scrips run outside of your cgi-bin by just adding this line to your httpd.config, just add the .rb extension to the filename:

AddHandler cgi-script .rb

I was doing this for awhile so I could execute scripts through the web but the RHTML method is better. Still, there could be applicable reasons for a person to want to do this. Just keep in mind, that when accessing Ruby scripts directly from a webpage you must at least specify a content-type (puts: “content-type: text/plain\n”) in your header or use the convenient cgi class from the Ruby standard library that does that (and a whole lot more) for you.

Improving Performance (optional)

The above is a really quick way to add Ruby support to your local webserver however, there’s one downside – it has to start up the Ruby interpreter everytime you hit an rhtml file with your browser. If you want something a little more dedicated look into the mod_ruby apache module which embeds a Ruby interpreter into Apache’s (inside your web server’s memory), to let Ruby CGI scripts execute natively, so scripts start up and run far faster. This is the equivalent as mod_php for PHP, that’s built into your MAMP setup.

Additionally, as a speed boost, you could use fast cgi to keep the eRuby interpreter instantiated, if for some reason you can’t use mod_ruby.

Helpful links: