Example #1
0
 def handler(self, client, request):
     """
     Process request and serve response
     :param client:
     :param request:
     :return:
     """
     response = Response(content='<h1>It works</h1><hr><small>Cleave serve tool v0.16</small>')
     client.send(response._compile())
     client.flush()
Example #2
0
 def handler(self, client, request):
     """
     Process request and serve response
     :param client:
     :param request:
     :return:
     """
     response = Response(
         content=
         '<h1>It works</h1><hr><small>Cleave serve tool v0.16</small>')
     client.send(response._compile())
     client.flush()
Example #3
0
    def serve_file(client, request):
        if request.path == '/' and FileStorage.BASE_FILE is not None:
            request.path = '/' + str(FileStorage.BASE_FILE)

        filepath = FileStorage.get_file_path(request.path)

        # File not found
        if not os.path.exists(filepath):
            client.send(Response(code=404, content='<h1>Page not found</h1>')._compile())
            client.flush()
            Log.error('File not found {}'.format(filepath))
            return

        # Create response
        response = Response(code=200, headers=FileStorage.create_headers(request.path))

        # Serve directory
        if os.path.isdir(filepath):
            response.set_content(FileStorage.serve_directory(filepath, request.path))
            response.headers['Content-Type'] = 'text/html; charset=utf-8'
        else:
            response.set_content(file(filepath, 'rb').read())

        # Send file
        client.send(response._compile())
        client.flush()