app-catalog/tools/testserver.py
Kevin Fox 2f200e65b9 More CORS support
This adds CORS preflight support to the test server.

Change-Id: I0029e4f8a7056e86dc8a2b6df6f7d935f9ee772d
2015-09-01 09:23:00 -07:00

42 lines
1.5 KiB
Python

#!/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import SimpleHTTPServer
import SocketServer
class AllowOriginRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
print("App Catalog Versions:",
self.headers.get('X-App-Catalog-Versions', ''))
return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def end_headers(self):
self.send_header("Access-Control-Allow-Origin", "*")
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def do_OPTIONS(self):
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Headers",
"X-App-Catalog-Versions")
self.send_header("Allow", "GET")
if __name__ == '__main__':
PORT = 18001
httpd = SocketServer.TCPServer(("", PORT), AllowOriginRequestHandler)
print("serving at port", PORT)
httpd.serve_forever()