Last active
January 2, 2016 02:29
-
-
Save johanforssell/8237848 to your computer and use it in GitHub Desktop.
Simple web server which accepts chunked uploads and responds with a dummy json
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
#!/usr/bin/python | |
import time | |
import BaseHTTPServer | |
import json | |
from pprint import pprint | |
HOST_NAME = '192.168.1.89' | |
PORT_NUMBER = 9494 | |
media_results = { | |
"media_results": [ | |
{ | |
"filename": "4711.jpg", | |
"image": { | |
"media_id": "/public/media/ad/12345678", | |
"base_url": "http://localhost/images/", | |
"media_path": "12/12345678.jpg", | |
"height": 480, | |
"width": 640 | |
} | |
} | |
], | |
"media_statistics": { | |
"failed_process": 0, | |
"failed_store": 0, | |
"ignored": 0, | |
"ok": 1, | |
"processed": 1 | |
} | |
} | |
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
def do_GET(s): | |
"""Respond to a GET request by doing nothing at all""" | |
s.send_response(200) | |
def do_POST(s): | |
"""Respond to a POST request.""" | |
s.send_response(200) | |
s.send_header("Content-type", "application/json") | |
s.end_headers() | |
json.dump(media_results, s.wfile) | |
pprint(vars(s.headers)) | |
print('') | |
print('') | |
print('########################################################################') | |
if __name__ == '__main__': | |
server_class = BaseHTTPServer.HTTPServer | |
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler) | |
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER) | |
try: | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
pass | |
httpd.server_close() | |
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would also need
-H "Expect: " \
to mimic how NSURLSession sends things, but it generates an error when used with curl for some reason