Commit 156cc31e authored by Thomas Tsiakalakis's avatar Thomas Tsiakalakis

detect SVG by content type header

parent 663b4174
......@@ -44,13 +44,27 @@ class Server(BaseHTTPRequestHandler):
self.send_response(204)
self.end_headers()
elif self.path == '/off':
display_off()
self.send_response(204)
self.end_headers()
length = int(self.headers['content-length'])
if length:
self.send_response(400)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(bytes('no payload allowed', 'utf-8'))
else:
display_off()
self.send_response(204)
self.end_headers()
elif self.path == '/on':
display_on()
self.send_response(204)
self.end_headers()
length = int(self.headers['content-length'])
if length:
self.send_response(400)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(bytes('no payload allowed', 'utf-8'))
else:
display_on()
self.send_response(204)
self.end_headers()
elif self.path == '/fill':
display_on()
length = int(self.headers['content-length'])
......@@ -86,9 +100,10 @@ class Server(BaseHTTPRequestHandler):
return process(post_data, self)
def process(svg, http):
def process(payload, http):
is_svg = http.headers('content-type') == 'image/svg+xml'
try:
image = render(svg)
image = render(payload, is_svg)
except OSError as e:
print(e)
http.send_response(500)
......@@ -104,8 +119,8 @@ def process(svg, http):
print('done')
return True
def render(payload):
if payload[0:4] == b'<?xm':
def render(payload, is_svg):
if is_svg:
print('detected SVG')
print('rendering')
args = [RSVGCONVERT] + RSVGCONVERT_ARGS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment