def getBridgeRequestAnswer(self, request): """Respond to a client HTTP request for bridges. :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. :rtype: str :returns: A plaintext or HTML response to serve. """ bridgeLines = None interval = self.schedule.intervalStart(time.time()) ip = self.getClientIP(request) logging.info("Replying to web request from %s. Parameters were %r" % (ip, request.args)) if ip: bridgeRequest = HTTPSBridgeRequest() bridgeRequest.client = ip bridgeRequest.isValid(True) bridgeRequest.withIPversion(request.args) bridgeRequest.withPluggableTransportType(request.args) bridgeRequest.withoutBlockInCountry(request) bridgeRequest.generateFilters() bridges = self.distributor.getBridges(bridgeRequest, interval) bridgeLines = [replaceControlChars(bridge.getBridgeLine( bridgeRequest, self.includeFingerprints)) for bridge in bridges] return self.renderAnswer(request, bridgeLines)
def getBridgeLines(self, bridgeRequest, bridges): """ :type bridgeRequest: :class:`MoatBridgeRequest` :param bridgeRequest: A valid bridge request object with pre-generated filters (as returned by :meth:`createBridgeRequest`). :param list bridges: A list of :class:`~bridgedb.bridges.Bridge` objects. :rtype: list :return: A list of bridge lines. """ return [ replaceControlChars(bridge.getBridgeLine(bridgeRequest)) for bridge in bridges ]
def getBridgeLines(self, bridgeRequest): """Get bridge lines for a client's HTTP request. :type bridgeRequest: :class:`MoatBridgeRequest` :param bridgeRequest: A valid bridge request object with pre-generated filters (as returned by :meth:`createBridgeRequest`). :rtype: list :returns: A list of bridge lines. """ bridgeLines = list() interval = self.schedule.intervalStart(time.time()) logging.debug("Replying to JSON API request from %s." % bridgeRequest.client) if bridgeRequest.isValid(): bridges = self.distributor.getBridges(bridgeRequest, interval) bridgeLines = [replaceControlChars(bridge.getBridgeLine(bridgeRequest)) for bridge in bridges] return bridgeLines
def getBridgeLines(self, bridgeRequest): """Get bridge lines for a client's HTTP request. :type bridgeRequest: :class:`MoatBridgeRequest` :param bridgeRequest: A valid bridge request object with pre-generated filters (as returned by :meth:`createBridgeRequest`). :rtype: list :returns: A list of bridge lines. """ bridgeLines = list() interval = self.schedule.intervalStart(time.time()) logging.debug("Replying to JSON API request from %s." % bridgeRequest.client) if bridgeRequest.isValid(): bridges = self.distributor.getBridges(bridgeRequest, interval) bridgeLines = [ replaceControlChars(bridge.getBridgeLine(bridgeRequest)) for bridge in bridges ] return bridgeLines