HTTP cache control headers

I had to do two things today. One was to make sure that in production all of my resources were cached. The other was to make sure that in development none of my resources were cached. I ended up with these two functions, which seem to be doing the trick to disable/enable caching:

function set_nocache() {
  header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
  header("Cache-Control: post-check=0, pre-check=0", false);
  header("Pragma: no-cache");
}

function set_cache() {
  header('Expires: ' . gmdate( 'D, d M Y H:i:s', time()+31536000 ) . ' GMT');
  header('Cache-Control: max-age=31536000');
}

Reference: Completely disable any browser caching.

bzr_hookless_email configuration bug

I ran into this bug using bzr_hookless_email, fortunately someone had published a patch which seems to have fixed the issue:

=== modified file 'bzr_hookless_email.py'
--- bzr_hookless_email.py 2012-03-22 15:15:15 +0000
+++ bzr_hookless_email.py 2012-04-25 06:05:55 +0000
@@ -159,7 +159,7 @@
         self._config = self._branch.get_config()

     def update(self):
- smtp = SMTPConnection(self._config)
+ smtp = SMTPConnection(self._branch.get_config_stack())
         smtp_from = None
         for revision in self._revisions_to_send():
             msg = self._compose_email(revision)

Error: post-commit hook failed (exit code 255) with no output

In subversion I was getting the error “post-commit hook failed (exit code 255) with no output” after trying to configure my post-commit hook to send email notifications. At first I thought the problem must have been related to the mailer, but I ran the mail command manually and it worked fine. Eventually I figured out that the problem was that the hooks/post-commit file hadn’t been marked executable. So it was a simple chmod +x to fix the problem.

Binding Postfix to particular IP addresses

I had a problem where my postfix mail system wasn’t listening on its IP address 10.1.1.123 but it was listening on 127.0.0.1. I checked my firewall settings and made sure port 25 was open, but I still couldn’t connect.

I read an article, Bind Postfix Mail Server To Localhost or Specific IP Address Only, which gave me the hint I needed.

The trick was to comment out inet_interfaces in /etc/postfix/main.cf because it was specifying loopback-only which meant postfix wasn’t listening on its other IP addresses.