Ticket #317: server-name-317.patch

File server-name-317.patch, 9.1 KB (added by thijs, 5 months ago)

Updated patch for Server header

  • pyamf/remoting/gateway/wsgi.py

     
    6060        start_response('400 Bad Request', [ 
    6161            ('Content-Type', 'text/plain'), 
    6262            ('Content-Length', str(len(response))), 
     63            ('Server', gateway.SERVER_NAME), 
    6364        ]) 
    6465 
    6566        return [response] 
     
    8182        try: 
    8283            request = remoting.decode(body, context) 
    8384        except pyamf.DecodeError: 
    84             self.logger.error(gateway.format_exception()) 
     85            self.logger.exception(gateway.format_exception()) 
    8586 
    8687            response = "400 Bad Request\n\nThe request body was unable to " \ 
    8788                "be successfully decoded." 
     
    9293            start_response('400 Bad Request', [ 
    9394                ('Content-Type', 'text/plain'), 
    9495                ('Content-Length', str(len(response))), 
     96                ('Server', gateway.SERVER_NAME), 
    9597            ]) 
    9698 
    9799            return [response] 
     
    104106        except (KeyboardInterrupt, SystemExit): 
    105107            raise 
    106108        except: 
    107             self.logger.error(gateway.format_exception()) 
     109            self.logger.exception(gateway.format_exception()) 
    108110 
    109111            response = "500 Internal Server Error\n\nThe request was " \ 
    110112                "unable to be successfully processed." 
     
    115117            start_response('500 Internal Server Error', [ 
    116118                ('Content-Type', 'text/plain'), 
    117119                ('Content-Length', str(len(response))), 
     120                ('Server', gateway.SERVER_NAME), 
    118121            ]) 
    119122 
    120123            return [response] 
     
    125128        try: 
    126129            stream = remoting.encode(response, context) 
    127130        except pyamf.EncodeError: 
    128             self.logger.error(gateway.format_exception()) 
     131            self.logger.exception(gateway.format_exception()) 
    129132 
    130133            response = "500 Internal Server Error\n\nThe request was " \ 
    131134                "unable to be encoded." 
     
    136139            start_response('500 Internal Server Error', [ 
    137140                ('Content-Type', 'text/plain'), 
    138141                ('Content-Length', str(len(response))), 
     142                ('Server', gateway.SERVER_NAME), 
    139143            ]) 
    140144 
    141145            return [response] 
     
    145149        start_response('200 OK', [ 
    146150            ('Content-Type', remoting.CONTENT_TYPE), 
    147151            ('Content-Length', str(len(response))), 
     152            ('Server', gateway.SERVER_NAME), 
    148153        ]) 
    149154 
    150155        return [response] 
  • pyamf/remoting/gateway/google.py

     
    5959 
    6060    def get(self): 
    6161        self.response.headers['Content-Type'] = 'text/plain' 
     62        self.response.headers['Server'] = gateway.SERVER_NAME 
    6263        self.error(405) 
    6364        self.response.out.write("405 Method Not Allowed\n\n" + \ 
    6465            "To access this PyAMF gateway you must use POST requests " + \ 
     
    7475        try: 
    7576            request = remoting.decode(body, context) 
    7677        except pyamf.DecodeError: 
    77             self.logger.error(gateway.format_exception()) 
     78            self.logger.exception(gateway.format_exception()) 
    7879 
    7980            response = "400 Bad Request\n\nThe request body was unable to " \ 
    8081                "be successfully decoded." 
     
    8485 
    8586            self.error(400) 
    8687            self.response.headers['Content-Type'] = 'text/plain' 
     88            self.response.headers['Server'] = gateway.SERVER_NAME 
    8789            self.response.out.write(response) 
    8890 
    8991            return 
     
    9698        except (KeyboardInterrupt, SystemExit): 
    9799            raise 
    98100        except: 
    99             self.logger.error(gateway.format_exception()) 
     101            self.logger.exception(gateway.format_exception()) 
    100102 
    101103            response = "500 Internal Server Error\n\nThe request was " \ 
    102104                "unable to be successfully processed." 
     
    106108 
    107109            self.error(500) 
    108110            self.response.headers['Content-Type'] = 'text/plain' 
     111            self.response.headers['Server'] = gateway.SERVER_NAME 
    109112            self.response.out.write(response) 
    110113 
    111114            return 
     
    116119        try: 
    117120            stream = remoting.encode(response, context) 
    118121        except pyamf.EncodeError: 
    119             self.logger.error(gateway.format_exception()) 
     122            self.logger.exception(gateway.format_exception()) 
    120123 
    121124            response = "500 Internal Server Error\n\nThe request was " \ 
    122125                "unable to be encoded." 
     
    126129 
    127130            self.error(500) 
    128131            self.response.headers['Content-Type'] = 'text/plain' 
     132            self.response.headers['Server'] = gateway.SERVER_NAME 
    129133            self.response.out.write(response) 
    130134 
    131135            return 
     
    134138 
    135139        self.response.headers['Content-Type'] = remoting.CONTENT_TYPE 
    136140        self.response.headers['Content-Length'] = str(len(response)) 
     141        self.response.headers['Server'] = gateway.SERVER_NAME 
     142         
    137143        self.response.out.write(response) 
    138144 
    139145    def __call__(self, *args, **kwargs): 
  • pyamf/remoting/gateway/__init__.py

     
    77@since: 0.1.0 
    88""" 
    99 
     10import platform 
    1011import types 
    1112 
    1213import pyamf 
    1314from pyamf import remoting, logging, util 
    1415 
     16SERVER_NAME = 'PyAMF/%s Python/%s' % ( 
     17    '.'.join(map(lambda x: str(x), pyamf.__version__)), 
     18    platform.python_version() 
     19) 
     20 
    1521fault_alias = pyamf.get_class_alias(remoting.ErrorFault) 
    1622 
    1723class BaseServiceError(pyamf.BaseError): 
  • pyamf/remoting/gateway/django.py

     
    8686        try: 
    8787            request = remoting.decode(http_request.raw_post_data, context) 
    8888        except pyamf.DecodeError: 
    89             self.logger.error(gateway.format_exception()) 
     89            self.logger.exception(gateway.format_exception()) 
    9090            http_response.status_code = 400 
    9191 
    9292            return http_response 
     
    9999        except (KeyboardInterrupt, SystemExit): 
    100100            raise 
    101101        except: 
    102             self.logger.error(gateway.format_exception()) 
     102            self.logger.exception(gateway.format_exception()) 
    103103 
    104104            return http.HttpResponseServerError() 
    105105 
     
    109109        try: 
    110110            stream = remoting.encode(response, context) 
    111111        except pyamf.EncodeError: 
    112             self.logger.error(gateway.format_exception()) 
     112            self.logger.exception(gateway.format_exception()) 
    113113 
    114114            return http.HttpResponseServerError('Unable to encode the response') 
    115115 
    116116        buf = stream.getvalue() 
    117117        http_response['Content-Type'] = remoting.CONTENT_TYPE 
    118118        http_response['Content-Length'] = str(len(buf)) 
     119        http_response['Server'] = gateway.SERVER_NAME 
    119120        http_response.write(buf) 
    120121 
    121122        return http_response 
  • pyamf/remoting/gateway/twisted.py

     
    6868                request, (failure.type, failure.value, failure.tb))) 
    6969 
    7070        def response_cb(result): 
    71             self.gateway.logger.debug("AMF Response: %r" % result) 
    7271            response.body = result 
     72 
     73            self.gateway.logger.debug("AMF Response: %r" % response) 
    7374            deferred_response.callback(response) 
    7475 
    7576        def preprocess_cb(result): 
     
    123124            deferred_response.callback(remoting.Response(ro_response, status=remoting.STATUS_ERROR)) 
    124125 
    125126        def response_cb(result): 
    126             self.gateway.logger.debug("AMF Response: %r" % result) 
     127             
    127128            ro_response.body = result 
    128             deferred_response.callback(remoting.Response(ro_response)) 
     129            res = remoting.Response(ro_response) 
     130            self.gateway.logger.debug("AMF Response: %r" % res) 
     131             
     132            deferred_response.callback(res) 
    129133 
    130134        def process_cb(result): 
    131135            d = defer.maybeDeferred(self.gateway.callServiceRequest, service_request, *ro_request.body, **kwargs) 
     
    194198 
    195199        request.setHeader("Content-Type", mimetype) 
    196200        request.setHeader("Content-Length", str(len(content))) 
     201        request.setHeader("Server", gateway.SERVER_NAME) 
    197202 
    198203        request.write(content) 
    199204        request.finish() 
     
    209214            """ 
    210215            Return HTTP 400 Bad Request. 
    211216            """ 
    212             self.logger.error(failure.printDetailedTraceback()) 
     217            self.logger.exception(failure.printDetailedTraceback()) 
    213218 
    214219            body = "400 Bad Request\n\nThe request body was unable to " \ 
    215220                "be successfully decoded."