Skip to content

Instantly share code, notes, and snippets.

@chibisov
Last active December 22, 2015 19:49
Show Gist options
  • Save chibisov/6522525 to your computer and use it in GitHub Desktop.
Save chibisov/6522525 to your computer and use it in GitHub Desktop.

Revisions

  1. chibisov revised this gist Sep 24, 2013. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions python
    Original file line number Diff line number Diff line change
    @@ -26,10 +26,17 @@ import tornado.web
    class MainHandler(tornado.web.RequestHandler):
    def get(self):
    self.set_header('Content-Type', 'text/plain')
    self.set_header('Access-Control-Allow-Origin', '*')
    self.set_header('Access-Control-Allow-Headers', 'accept, origin, x-requested-with, x-csrftoken, content-type')
    response = self._get_response()
    print response
    self.write(response)
    head = get
    post = get
    put = get
    patch = get
    delete = get
    options = get

    def _get_response(self):
    headers_text = '\n'.join(
  2. chibisov revised this gist Sep 11, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion python
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,9 @@ import tornado.web
    class MainHandler(tornado.web.RequestHandler):
    def get(self):
    self.set_header('Content-Type', 'text/plain')
    self.write(self._get_response())
    response = self._get_response()
    print response
    self.write(response)
    post = get

    def _get_response(self):
  3. chibisov revised this gist Sep 11, 2013. 1 changed file with 26 additions and 1 deletion.
    27 changes: 26 additions & 1 deletion python
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,25 @@
    #!/usr/bin/env python
    """
    $ curl -d 'hello=world' http://localhost:8888/path/?someparam=1
    Request URL: http://localhost:8888/path/?someparam=1
    Request Method: POST
    Request Headers:
    Host: localhost:8888
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 11
    Accept: */*
    User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
    Request Body:
    hello=world
    Query String Parameters:
    {"someparam": ["1"], "hello": ["world"]}
    """
    import json

    import tornado.ioloop
    import tornado.web

    @@ -23,11 +44,15 @@ Request Headers:
    Request Body:
    {body}
    Query String Parameters:
    {query_string_parameters}
    """.format(
    request_url=self.request.full_url(),
    request_method=self.request.method,
    headers=headers_text,
    body=self.request.body
    body=self.request.body,
    query_string_parameters=json.dumps(self.request.arguments)
    ).lstrip()

    application = tornado.web.Application([
  4. chibisov created this gist Sep 11, 2013.
    39 changes: 39 additions & 0 deletions python
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/usr/bin/env python
    import tornado.ioloop
    import tornado.web

    class MainHandler(tornado.web.RequestHandler):
    def get(self):
    self.set_header('Content-Type', 'text/plain')
    self.write(self._get_response())
    post = get

    def _get_response(self):
    headers_text = '\n'.join(
    ['%s: %s' % (header_name, value)
    for header_name, value
    in self.request.headers.items()]
    )
    return """
    Request URL: {request_url}
    Request Method: {request_method}
    Request Headers:
    {headers}
    Request Body:
    {body}
    """.format(
    request_url=self.request.full_url(),
    request_method=self.request.method,
    headers=headers_text,
    body=self.request.body
    ).lstrip()

    application = tornado.web.Application([
    (r".*", MainHandler),
    ])

    if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()