Skip to content

Commit

Permalink
Change renderAnswer() to take bridge lines, not Bridge classes.
Browse files Browse the repository at this point in the history
Otherwise, we'd also have to pass the `transport`, and `addressClass`
parameters to renderAnswer().
  • Loading branch information
isislovecruft committed Jan 12, 2014
1 parent 8ebb475 commit 9111b70
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions lib/bridgedb/HTTPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def getBridgeRequestAnswer(self, request):
% (Util.logSafely(ip), request.args))

rules = []
bridges = None
bridgeLines = None

if ip:
if ipv6:
Expand All @@ -252,23 +252,27 @@ def getBridgeRequestAnswer(self, request):
self.nBridgesToGive,
countryCode,
bridgeFilterRules=rules)
bridgeLines = "".join(" %s\n" % b.getConfigLine(
includeFingerprint=self.includeFingerprints,
addressClass=addressClass,
transport=transport,
request=bridgedb.Dist.uniformMap(ip)
) for b in bridges)

answer = self.renderAnswer(request, ip, bridges, rtl, format)
answer = self.renderAnswer(request, bridgeLines, rtl, format)
return answer

def renderAnswer(self, request, ip=None, bridges=None,
rtl=False, format=None):
def renderAnswer(self, request, bridgeLines=None, rtl=False, format=None):
"""Generate a response for a client which includes **bridges**.
The generated response can be plaintext or HTML.
:type request: :api:`twisted.web.http.Request`
:param request: A ``Request`` object containing the HTTP method, full
URI, and any URL/POST arguments and headers present.
:type ip: str or None
:param ip: The IP address of the client we're responding to.
:type bridges: list or None
:param bridges: A list of :class:`~bridgedb.Bridges.Bridge`s.
:type bridgeLines: list or None
:param bridgeLines: A list of strings used to configure a Tor client
to use a bridge.
:param bool rtl: If ``True``, the language used for the response to
the client should be rendered right-to-left.
:type format: str or None
Expand All @@ -279,22 +283,12 @@ def renderAnswer(self, request, ip=None, bridges=None,
:rtype: str
:returns: A plaintext or HTML response to serve.
"""
answer = None

if bridges and ip:
answer = "".join(" %s\n" % b.getConfigLine(
includeFingerprint=self.includeFingerprints,
addressClass=addressClass,
transport=transport,
request=bridgedb.Dist.uniformMap(ip)
) for b in bridges)

if format == 'plain':
request.setHeader("Content-Type", "text/plain")
return answer
else:
request.setHeader("Content-Type", "text/html; charset=utf-8")
return lookup.get_template('bridges.html').render(answer=answer,
return lookup.get_template('bridges.html').render(answer=bridgeLines,
rtl=rtl)

class WebRoot(twisted.web.resource.Resource):
Expand Down

0 comments on commit 9111b70

Please sign in to comment.