示例#1
0
文件: server.py 项目: zasfe/pol
    def writeResponse(
        self, sresponse
    ):  #, response_str='PolitePol: Local page processing is failed'
        sresponse = HttpCompressionMiddleware().process_response(
            Request(sresponse.url), sresponse, None)
        sresponse = DecompressionMiddleware().process_response(
            None, sresponse, None)

        response_headers = self.prepare_response_headers(sresponse.headers)

        if (isinstance(sresponse, TextResponse)):
            ip = self.request.getHeader(
                'x-real-ip') or self.request.client.host
            response_str = self.prepare_response_str(
                sresponse.selector, sresponse.headers,
                sresponse.body_as_unicode(), sresponse.url, ip)
            if self.feed_config:
                response_headers = {
                    b"Content-Type": b'text/xml; charset=utf-8'
                }
        else:  # images and such
            response_str = sresponse.body

        for k, v in response_headers.items():
            self.request.setHeader(k, v)

        self.request.write(response_str)
        self.request.finish()
示例#2
0
    def writeResponse(
            self,
            request,
            response,
            feed_config,
            response_str='PolitePol: Local page processing is failed'):
        response = HttpCompressionMiddleware().process_response(
            Request(response.url), response, None)
        response = DecompressionMiddleware().process_response(
            None, response, None)

        if (isinstance(response, TextResponse)):
            ip = request.getHeader('x-real-ip') or request.client.host
            response_str = self.prepare_response_str(
                response.selector, response.headers,
                response.body_as_unicode(), response.url, feed_config, ip)
            if feed_config:
                request.setHeader(b"Content-Type", b'text/xml; charset=utf-8')

        request.write(response_str)
        request.finish()
示例#3
0
文件: server.py 项目: taroved/pol
    def writeResponse(self, sresponse): #, response_str='PolitePol: Local page processing is failed'
        sresponse = HttpCompressionMiddleware().process_response(Request(sresponse.url), sresponse, None)
        sresponse = DecompressionMiddleware().process_response(None, sresponse, None)

        response_headers = self.prepare_response_headers(sresponse.headers)

        if (isinstance(sresponse, TextResponse)):
            ip = self.request.getHeader('x-real-ip') or self.request.client.host
            response_str = self.prepare_response_str(sresponse.selector, sresponse.headers, sresponse.body_as_unicode(), sresponse.url, ip)
            if self.feed_config:
                response_headers = {b"Content-Type": b'text/xml; charset=utf-8'}
        else: # images and such
            response_str = sresponse.body

        for k, v in response_headers.items():
            self.request.setHeader(k, v)

        self.request.write(response_str)
        self.request.finish()