Skip to content

Commit

Permalink
made content-type check case insensitive
Browse files Browse the repository at this point in the history
added hack for application/json when doing transform check
  • Loading branch information
pakak-ndouba committed Jul 12, 2018
1 parent 74b1498 commit 93451b6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/canari/resources/templates/create_aws_lambda/app.py.bob
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ else:
# noinspection PyUnresolvedReferences
from ConfigParser import NoSectionError

import chalice.app
from chalice import Chalice, Response

import canari
Expand All @@ -23,6 +24,17 @@ from canari.maltego.message import (MaltegoMessage, MaltegoTransformResponseMess
from canari.maltego.transform import Transform
from canari.mode import set_canari_mode, CanariMode


def _matches_content_type(content_type, valid_content_types):
if ';' in content_type:
content_type = [c.lower() for c in content_type.split(';', 1)[0].strip()]
else:
content_type = content_type.lower()
return content_type in valid_content_types


chalice.app._matches_content_type = _matches_content_type

app = Chalice('Canari Lambda: {{{ project.name }}}')

global_config = load_config(os.path.join('chalicelib', 'canari.conf'))
Expand Down Expand Up @@ -117,9 +129,10 @@ def get_{{{ transform.name.replace('.', '_') }}}():
return Response('Yes?', status_code=200)


@app.route('/{{{ transform.name }}}', methods=['POST'])
@app.route('/{{{ transform.name }}}', methods=['POST'],
content_types=['text/xml', 'application/xml', 'application/json'])
def post_{{{ transform.name.replace('.', '_') }}}():
if not app.current_request.headers.get('Content-Length', 0):
if not app.current_request.raw_body:
return Response('Yes?', status_code=200)
from {{{ transform.__module__ }}} import {{{ transform.__class__.__name__ }}}
return do_transform({{{ transform.__class__.__name__ }}})
Expand Down

0 comments on commit 93451b6

Please sign in to comment.