Today I realized that the twisted server records a None value if
there's no corresponding header. This means that
..get_environ('HTTP_REFERER', 'default') never returns 'default',
because there's always a key for HTTP_REFERER. I think this behaviour
is unexpected; certainly I was expecting there to be no key at all if
a certain header wasn't present.
--amk
diff -C2 -r Quixote-1.2-orig/server/twisted_http.py
Quixote-1.2/server/twisted_http.py
*** Quixote-1.2-orig/server/twisted_http.py Thu Sep 30 13:36:19 2004
--- Quixote-1.2/server/twisted_http.py Tue Nov 2 10:47:40 2004
***************
*** 89,100 ****
"REQUEST_URI": self.uri,
"HTTPS": (self.isSecure() and 'on') or 'off',
- "ACCEPT_ENCODING": self.getHeader('Accept-encoding'),
- 'CONTENT_TYPE': self.getHeader('Content-type'),
- 'HTTP_COOKIE': self.getHeader('Cookie'),
- 'HTTP_REFERER': self.getHeader('Referer'),
- 'HTTP_USER_AGENT': self.getHeader('User-agent'),
'SERVER_PROTOCOL': 'HTTP/1.1',
}
client = self.getClient()
if client is not None:
--- 89,104 ----
"REQUEST_URI": self.uri,
"HTTPS": (self.isSecure() and 'on') or 'off',
'SERVER_PROTOCOL': 'HTTP/1.1',
}
+ for env_var, header in [('ACCEPT_ENCODING', 'Accept-encoding'),
+ ('CONTENT_TYPE', 'Content-type'),
+ ('HTTP_COOKIE', 'Cookie'),
+ ('HTTP_REFERER', 'Referer'),
+ ('HTTP_USER_AGENT', 'User-agent')]:
+ value = self.getHeader(header)
+ if value is not None:
+ env[env_var] = value
+
client = self.getClient()
if client is not None: