import time
from urllib import urlencode
from urllib2 import build_opener, Request, urlopen, URLError
from urlparse import urlparse

class URLResponse(object):
    def __init__(self, body, domain):
        self.body = body
        self.domain = domain

def fetchURL(url, extraHeaders=None):
    headers = [{ "User-agent" , "Mozilla/5.0" }]
    if extraHeaders:
        for header in extraHeaders:
            # For whatever reason headers are defined in different way in opener than they are in a normal urlopen
            headers.append({ header, extraHeaders[header] })
    try:
        opener = build_opener()
        opener.addheaders = headers
        response = opener.open(url)
        return URLResponse(response.read(), urlparse(response.geturl()).hostname)

    except URLError as e:
        today = time.strftime("[%H:%M:%S]")
        reason = None
        if hasattr(e, "reason"):
            reason = "We failed to reach the server, reason: {}".format(e.reason)
        elif hasattr(e, "code"):
            reason = "The server couldn't fulfill the request, code: {}".format(e.code)
        print "{} *** ERROR: Fetch from \"{} \" failed: {}".format(today, url, reason)

def postURL(url, values, extraHeaders=None):
    headers = { "User-agent" : "Mozilla/5.0" }
    if extraHeaders:
        for header in extraHeaders:
            headers[header] = extraHeaders[header]
    data = urlencode(values)
    try:
        request = Request(url, data, headers)
        response = urlopen(request)
        return URLResponse(response.read(), urlparse(response.geturl()).hostname)

    except URLError as e:
        today = time.strftime("[%H:%M:%S]")
        reason = None
        if hasattr(e, "reason"):
            reason = "We failed to reach the server, reason: {}".format(e.reason)
        elif hasattr(e, "code"):
            reason = "The server couldn't fulfill the request, code: {}".format(e.code)
        print "{} *** ERROR: Post to \"{} \" failed: {}".format(today, url, reason)

@@ -1,14 +1,18 @@
 import
+ re,
  time%0Afr
@@ -192,16 +192,33 @@
 , domain
+, responseHeaders
 ):%0A     
@@ -265,16 +265,63 @@
 = domain
+%0A        self.responseHeaders = responseHeaders
 %0A%0Adef fe
@@ -367,17 +367,17 @@
 ders = %5B
-%7B
+(
  %22User-a
@@ -381,17 +381,16 @@
 r-agent%22
- 
 , %22Mozil
@@ -397,17 +397,17 @@
 la/5.0%22 
-%7D
+)
 %5D%0A    if
@@ -599,18 +599,17 @@
 .append(
-%7B 
+(
 header, 
@@ -628,18 +628,17 @@
 %5Bheader%5D
- %7D
+)
 )%0A    tr
@@ -758,78 +758,510 @@
   re
-turn URLResponse(response.read(), urlparse(response.geturl()).hostname
+sponseHeaders = response.info().dict%0A        print responseHeaders%0A        pageType = responseHeaders%5B%22content-type%22%5D%0A%0A        # Make sure we don't download any unwanted things%0A        if re.match(%22%5E(text/.*%7Capplication/((rss%7Catom%7Crdf)%5C+)?xml(;.*)?%7Capplication/(.*)json(;.*)?)$%22, pageType):%0A            urlResponse = URLResponse(response.read(), urlparse(response.geturl()).hostname, responseHeaders)%0A            response.close()%0A            return urlResponse%0A        else:%0A            response.close(
 )%0A%0A 
@@ -1875,16 +1875,17 @@
 header%5D%0A
+%0A
     data
@@ -1905,16 +1905,17 @@
 values)%0A
+%0A
     try:
@@ -2011,78 +2011,480 @@
   re
-turn URLResponse(response.read(), urlparse(response.geturl()).hostname
+sponseHeaders = response.info().dict%0A        pageType = responseHeaders%5B%22content-type%22%5D%0A%0A        # Make sure we don't download any unwanted things%0A        if re.match('%5E(text/.*%7Capplication/((rss%7Catom%7Crdf)%5C+)?xml(;.*)?%7Capplication/(.*)json(;.*)?)$', pageType):%0A            urlResponse = URLResponse(response.read(), urlparse(response.geturl()).hostname, responseHeaders)%0A            response.close()%0A            return urlResponse%0A        else:%0A            response.close(
 )%0A%0A 
@@ -2874,28 +2874,108 @@
 .format(today, url, reason)%0A
+%0Aprint fetchURL(%22http://heufneutje.net%22, %7B %22Cache-Control%22 : %22no-cache%22 %7D).body%0A

Make headers a tupel list and restrict response types