Created
July 3, 2016 23:30
-
-
Save tcgarvin/c3ca9cfdf41d306b38ec8d639f9579f4 to your computer and use it in GitHub Desktop.
Maybe a little less minimal than you wanted..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from growler import App | |
from growler.middleware import (Logger, Static, StringRenderer) | |
loop = asyncio.get_event_loop() | |
# Construct our application with name GrowlerServer | |
app = App('GrowlerServer', loop=loop) | |
# Add some growler middleware to the application | |
app.use(Logger()) | |
app.use(Static(path='public')) | |
app.use(StringRenderer('views/')) | |
@app.get('/') | |
def index(req, res): | |
res.render("index") | |
@app.post('/alpha-signup') | |
def signup(req, res): | |
print("Test") | |
res.render('thankyou') | |
print("I ought to have rendered. " + str(res.has_ended)) | |
@app.get('/something') | |
def getsignup(req, res): | |
res.render('thankyou') | |
# Create the server - this automatically adds it to the asyncio event loop | |
Server = app.create_server(host='0.0.0.0', port=8000) | |
# Tell the event loop to run forever - this will listen to the server's | |
# socket and wake up the growler application upon each connection | |
print("Starting Server.") | |
loop.run_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Headers | |
HTTP/1.1 400 Bad Request | |
Content-Type: text/html; charset=UTF-8 | |
Content-Length: 77 | |
Date: Sun, 03 Jul 2016 23:28:19 GMT | |
// Body | |
<html><head></head><body><h1>HTTP Error : 400 Bad Request </h1></body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Starting Server. | |
Test | |
I ought to have rendered. True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>RoboDwarf</title> | |
</head> | |
<body> | |
<div class="splash"> | |
<p>Sweet, thanks! | |
</div> | |
</body> | |
</html> |
Copying that request to to request.txt causes a response like:
$ nc localhost 8000 < request.txt
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=UTF-8
Content-Length: 77
Date: Mon, 04 Jul 2016 00:11:11 GMT
<html><head></head><body><h1>HTTP Error : 400 Bad Request </h1></body></html>HTTP/1.1 200 OK
Content-Type: text/html
Date: Mon, 04 Jul 2016 00:11:11 GMT
Server: Growler/0.7.4 Python/3.4
Content-Length: 126
X-Powered-By: Growler
<html>
<head>
<title>RoboDwarf</title>
</head>
<body>
<div class="splash">
<p>Sweet, thanks!
</div>
</body>
</html>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, forgot the request:
`POST /alpha-signup HTTP/1.1
Host: localhost:8000
Connection: keep-alive
Content-Length: 11
Cache-Control: max-age=0
Origin: http://localhost:8000
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
Referer: http://localhost:8000/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
email=dgfhf`