mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-08 05:14:00 +02:00
proof of concept brmbar server
This commit is contained in:
parent
fd6e33a390
commit
99893f58a0
2 changed files with 41 additions and 0 deletions
41
server/brmbar-server
Executable file
41
server/brmbar-server
Executable file
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import BaseHTTPServer
|
||||||
|
|
||||||
|
class BrmbarHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
|
action = self.path.split('/')[1:]
|
||||||
|
|
||||||
|
if action[0] == 'code':
|
||||||
|
self.code(action[1])
|
||||||
|
return
|
||||||
|
|
||||||
|
if action[0] == 'favicon.ico':
|
||||||
|
self.send_file('favicon.png', 'image/png')
|
||||||
|
return
|
||||||
|
|
||||||
|
self.send_response(404)
|
||||||
|
|
||||||
|
def code(self, code):
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header('Content-type', 'text/plain')
|
||||||
|
self.end_headers()
|
||||||
|
self.wfile.write('CODE "%s" received\n' % code)
|
||||||
|
|
||||||
|
def send_file(self, filename, mimetype):
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header('Content-type', mimetype)
|
||||||
|
self.end_headers()
|
||||||
|
f = open(filename, 'r')
|
||||||
|
self.wfile.write(f.read())
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
try:
|
||||||
|
server_address = ('', 8000)
|
||||||
|
httpd = BaseHTTPServer.HTTPServer(server_address, BrmbarHandler)
|
||||||
|
print 'Starting BrmBar server ...'
|
||||||
|
httpd.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print 'Shutting down ...'
|
||||||
|
httpd.socket.close()
|
BIN
server/favicon.png
Normal file
BIN
server/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Loading…
Add table
Add a link
Reference in a new issue