101
101
host = fields.getfirst("host").value
102
102
port = fields.getfirst("port").value
103
103
digest = fields.getfirst("digest").value
104
except AttributeError:
105
# Any of the getfirsts returned None
106
req.throw_error(req.HTTP_BAD_REQUEST)
107
# If text is None, it was probably just an empty line
104
109
text = fields.getfirst("text").value
105
110
except AttributeError:
106
# Any of the getfirsts returned None
107
req.throw_error(req.HTTP_BAD_REQUEST)
109
113
# Open an HTTP connection
110
114
url = ("http://" + urllib.quote(host) + ":" + urllib.quote(port)
112
116
body = ("digest=" + urllib.quote(digest)
113
+ "&text=" + urllib.quote(text) + '\n\n')
117
+ "&text=" + urllib.quote(text))
114
118
headers = {"Content-Type": "application/x-www-form-urlencoded"}
116
120
conn = httplib.HTTPConnection(host, port)
117
conn.request("POST", url, body, headers)
119
response = conn.getresponse()
121
req.status = response.status
122
# NOTE: Ignoring arbitrary headers returned by the server
123
# Probably not necessary to proxy them
124
req.content_type = response.getheader("Content-Type", "text/plain")
125
req.write(response.read())
128
122
req.throw_error(req.HTTP_BAD_REQUEST)
123
conn.request("POST", url, body, headers)
125
response = conn.getresponse()
127
req.status = response.status
128
# NOTE: Ignoring arbitrary headers returned by the server
129
# Probably not necessary to proxy them
130
req.content_type = response.getheader("Content-Type", "text/plain")
131
req.write(response.read())