Esempio n. 1
0
    def replay(self, url):
        """
        Replay a previously recorded preset, and save the request in history
        """
        request_info = RequestSerialiser(url, bottle.request)
        body = request_info.serialize()
        LOGGER.info("Replaying URL for request: \n{0}".format(body))
        boss_response = self.store_history_retrieve_preset(body)

        if boss_response.status == 200:
            preset = Preset(boss_response.read())
            return preset.as_http_response(bottle.response)
        else:
            LOGGER.error("Cannot find matching request\n{0}".format(body))
            raise HTTPResponse(boss_response.read(),
                               status=boss_response.status)
Esempio n. 2
0
    def replay(self, url):
        """
        Replay a previously recorded preset, and save the request in history
        """
        request_info = RequestSerialiser(url, bottle.request)
        body = request_info.serialize()
        LOGGER.info("Replaying URL for request: \n{0}".format(body))
        boss_response = self.store_history_retrieve_preset(body)

        if boss_response.status == 200:
            preset = Preset(boss_response.read())
            return preset.as_http_response(bottle.response)
        else:
            LOGGER.error("Cannot find matching request\n{0}".format(body))
            raise HTTPResponse(boss_response.read(),
                               status=boss_response.status)
Esempio n. 3
0
def replay_http(uid, url):
    """
    Replay a previously recorded preset, and save the request in history
    """

    request_info = RequestSerialiser(url, bottle.request)
    body = request_info.serialize()

    boss_response = replay(uid, body)
    preset = Preset(boss_response.as_json().encode('ascii'))
    # ^ Any suggestions about what we can do here?
    # Preset expects a string like object that can be decoded.
    # in py3k that means a 'bytes' object. in py2.X that means a string.
    # So the above works, but it looks ugly - ideally we'd handle both in
    # Preset constructor.
    return preset.as_http_response(bottle.response)