How to compare HTTP headers with time fields in Python?
<p>I am using Python to construct a proxy server as an exercise and
I want to compare two different strings of time received from a server. 
For example,</p>

<pre><code>Date: Sun, 24 Nov 2013 18:34:30 GMT
Expires: Sat, 23 Nov 2013 18:34:30 GMT
</code></pre>

<p>How can I compare whether the expiry time is earlier than the current time? Do I have to parse it using the <code>strptime</code> method of the <code>datetime</code> module or is there an easier way to do so? </p>

<p>Convert each of the strings to a timestamp and compare these, for example as follows:</p>

<pre><code>from datetime import datetime    

date1 = "Date: Sun, 24 Nov 2013 18:34:30 GMT"
date2 = "Expires: Sat, 23 Nov 2013 18:34:30 GMT"
format = "%a, %d %b %Y %H:%M:%S %Z"

if datetime.strptime(date1, "Date: " + format) &gt;= datetime.strptime(date2, "Expires: " + format):
    print "Expired"
</code></pre>

python time http-headers compare http-proxy