def parse(request, more_id=None): r_dict = {} # Build headers from request in request dict r_dict['headers'] = get_headers(request.META) # Traditional authorization should be passed in headers r_dict['auth'] = {} if 'Authorization' in r_dict['headers']: # OAuth will always be dict, not http auth. Set required fields for oauth module and type for authentication # module set_authorization(r_dict, request) elif 'Authorization' in request.body or 'HTTP_AUTHORIZATION' in request.body: # Authorization could be passed into body if cross origin request r_dict['auth']['type'] = 'http' else: r_dict['auth']['type'] = 'none' r_dict['params'] = {} if request.method == 'POST' and 'method' in request.GET: bdy = convert_post_body_to_dict(request.body) if 'content' in bdy: # body is in 'content' for the IE cors POST r_dict['body'] = urllib.unquote(bdy.pop('content')) r_dict['headers'].update(get_headers(bdy)) for h in r_dict['headers']: bdy.pop(h, None) r_dict['params'].update(bdy) for k in request.GET: if k == 'method': r_dict[k] = request.GET[k] r_dict['params'][k] = request.GET[k] else: r_dict = parse_body(r_dict, request) # Update dict with any GET data r_dict['params'].update(request.GET.dict()) # A 'POST' can actually be a GET if 'method' not in r_dict['params']: if request.method == "POST" and "application/json" not in r_dict[ 'headers']['CONTENT_TYPE'] and "multipart/mixed" not in r_dict[ 'headers']['CONTENT_TYPE']: r_dict['method'] = 'GET' else: r_dict['method'] = request.method # Set if someone is hitting the statements/more endpoint if more_id: r_dict['more_id'] = more_id return r_dict
def parse(request, more_id=None): r_dict = {} # Build headers from request in request dict r_dict['headers'] = get_headers(request.META) # Traditional authorization should be passed in headers r_dict['auth'] = {} if 'Authorization' in r_dict['headers']: # OAuth will always be dict, not http auth. Set required fields for oauth module and type for authentication # module set_authorization(r_dict, request) elif 'Authorization' in request.body or 'HTTP_AUTHORIZATION' in request.body: # Authorization could be passed into body if cross origin request r_dict['auth']['type'] = 'http' else: r_dict['auth']['type'] = 'none' r_dict['params'] = {} if request.method == 'POST' and 'method' in request.GET: bdy = convert_post_body_to_dict(request.body) if 'content' in bdy: # body is in 'content' for the IE cors POST r_dict['body'] = urllib.unquote(bdy.pop('content')) r_dict['headers'].update(get_headers(bdy)) for h in r_dict['headers']: bdy.pop(h, None) r_dict['params'].update(bdy) for k in request.GET: if k == 'method': r_dict[k] = request.GET[k] r_dict['params'][k] = request.GET[k] else: r_dict = parse_body(r_dict, request) # Update dict with any GET data r_dict['params'].update(request.GET.dict()) # A 'POST' can actually be a GET if 'method' not in r_dict['params']: if request.method == "POST" and "application/json" not in r_dict['headers']['CONTENT_TYPE'] and "multipart/mixed" not in r_dict['headers']['CONTENT_TYPE']: r_dict['method'] = 'GET' else: r_dict['method'] = request.method # Set if someone is hitting the statements/more endpoint if more_id: r_dict['more_id'] = more_id return r_dict
def parse(request, more_id=None): r_dict = {} # Build headers from request in request dict r_dict['headers'] = get_headers(request.META) # Traditional authorization should be passed in headers r_dict['auth'] = {} if 'Authorization' in r_dict['headers']: # OAuth will always be dict, not http auth. Set required fields for oauth module and type for authentication # module set_authorization(r_dict, request) elif 'Authorization' in request.body or 'HTTP_AUTHORIZATION' in request.body: # Authorization could be passed into body if cross origin request r_dict['auth']['type'] = 'http' else: r_dict['auth']['type'] = 'none' r_dict['params'] = {} # lookin for weird IE CORS stuff.. it'll be a post with a 'method' url param if request.method == 'POST' and 'method' in request.GET: bdy = convert_post_body_to_dict(request.body) # 'content' is in body for the IE cors POST if 'content' in bdy: r_dict['body'] = urllib.unquote(bdy.pop('content')) # headers are in the body too for IE CORS, we removes them r_dict['headers'].update(get_headers(bdy)) for h in r_dict['headers']: bdy.pop(h, None) # remove extras from body bdy.pop('X-Experience-API-Version', None) bdy.pop('Content-Type', None) bdy.pop('If-Match', None) bdy.pop('If-None-Match', None) # all that should be left are params for the request, # we adds them to the params object r_dict['params'].update(bdy) for k in request.GET: if k == 'method': # make sure the method param goes in the special method spot r_dict[k] = request.GET[k] else: r_dict['params'][k] = request.GET[k] # Just parse body for all non IE CORS stuff else: r_dict = parse_body(r_dict, request) # Update dict with any GET data r_dict['params'].update(request.GET.dict()) # Method gets set for cors already if 'method' not in r_dict: # Differentiate GET and POST if request.method == "POST" and (request.path[6:] == 'statements' or request.path[6:] == 'statements/'): # Can have empty body for POST (acts like GET) if 'body' in r_dict: # If body is a list, it's a post if not isinstance(r_dict['body'], list): if not isinstance(r_dict['body'], dict): raise BadRequest("Cannot evaluate data into dictionary to parse -- Error: %s" % r_dict['body']) # If actor verb and object not in body - means it's a GET or invalid POST if not ('actor' in r_dict['body'] and 'verb' in r_dict['body'] and 'object' in r_dict['body']): # If body keys are in get params - GET - else invalid request if set(r_dict['body'].keys()).issubset(['statementId', 'voidedStatementId', 'agent', 'verb', 'activity', 'registration', 'related_activities', 'related_agents', 'since', 'until', 'limit', 'format', 'attachments', 'ascending']): r_dict['method'] = 'GET' else: raise BadRequest("Statement is missing actor, verb, or object") else: r_dict['method'] = 'POST' else: r_dict['method'] = 'POST' else: r_dict['method'] = 'GET' else: r_dict['method'] = request.method # Set if someone is hitting the statements/more endpoint if more_id: r_dict['more_id'] = more_id return r_dict
def parse(request, more_id=None): r_dict = {} # Build headers from request in request dict r_dict['headers'] = get_headers(request.META) # Traditional authorization should be passed in headers r_dict['auth'] = {} if 'Authorization' in r_dict['headers']: # OAuth will always be dict, not http auth. Set required fields for oauth module and type for authentication # module set_authorization(r_dict, request) elif 'Authorization' in request.body or 'HTTP_AUTHORIZATION' in request.body: # Authorization could be passed into body if cross origin request r_dict['auth']['type'] = 'http' else: r_dict['auth']['type'] = 'none' r_dict['params'] = {} # lookin for weird IE CORS stuff.. it'll be a post with a 'method' url param if request.method == 'POST' and 'method' in request.GET: bdy = convert_post_body_to_dict(request.body) # 'content' is in body for the IE cors POST if 'content' in bdy: r_dict['body'] = urllib.unquote(bdy.pop('content')) # headers are in the body too for IE CORS, we removes them r_dict['headers'].update(get_headers(bdy)) for h in r_dict['headers']: bdy.pop(h, None) r_dict['params'].update(bdy) # all that should be left are params for the request, # we adds them to the params object for k in request.GET: if k == 'method': # make sure the method param goes in the special method spot r_dict[k] = request.GET[k] r_dict['params'][k] = request.GET[k] # Just parse body for all non IE CORS stuff else: r_dict = parse_body(r_dict, request) # Update dict with any GET data r_dict['params'].update(request.GET.dict()) # Method gets set for cors already if 'method' not in r_dict['params']: # Differentiate GET and POST if request.method == "POST" and (request.path[6:] == 'statements' or request.path[6:] == 'statements/'): # Can have empty body for POST (acts like GET) if 'body' in r_dict: # If body is a list, it's a post if not isinstance(r_dict['body'], list): # If actor verb and object not in body - means it's a GET or invalid POST if not ('actor' in r_dict['body'] and 'verb' in r_dict['body'] and 'object' in r_dict['body']): # If body keys are in get params - GET - else invalid request if set(r_dict['body'].keys()).issubset([ 'statementId', 'voidedStatementId', 'agent', 'verb', 'activity', 'registration', 'related_activities', 'related_agents', 'since', 'until', 'limit', 'format', 'attachments', 'ascending' ]): r_dict['method'] = 'GET' else: raise BadRequest( "Statement is missing actor, verb, or object") else: r_dict['method'] = 'POST' else: r_dict['method'] = 'POST' else: r_dict['method'] = 'GET' else: r_dict['method'] = request.method # Set if someone is hitting the statements/more endpoint if more_id: r_dict['more_id'] = more_id return r_dict
def parse(request, more_id=None): r_dict = {} # Build headers from request in request dict r_dict["headers"] = get_headers(request.META) # Traditional authorization should be passed in headers r_dict["auth"] = {} if "Authorization" in r_dict["headers"]: # OAuth will always be dict, not http auth. Set required fields for oauth module and type for authentication # module set_authorization(r_dict, request) elif "Authorization" in request.body or "HTTP_AUTHORIZATION" in request.body: # Authorization could be passed into body if cross origin request r_dict["auth"]["type"] = "http" else: r_dict["auth"]["type"] = "none" r_dict["params"] = {} # lookin for weird IE CORS stuff.. it'll be a post with a 'method' url param if request.method == "POST" and "method" in request.GET: bdy = convert_post_body_to_dict(request.body) # 'content' is in body for the IE cors POST if "content" in bdy: r_dict["body"] = urllib.unquote(bdy.pop("content")) # headers are in the body too for IE CORS, we removes them r_dict["headers"].update(get_headers(bdy)) for h in r_dict["headers"]: bdy.pop(h, None) # remove extras from body bdy.pop("X-Experience-API-Version", None) bdy.pop("Content-Type", None) bdy.pop("If-Match", None) bdy.pop("If-None-Match", None) # all that should be left are params for the request, # we adds them to the params object r_dict["params"].update(bdy) for k in request.GET: if k == "method": # make sure the method param goes in the special method spot r_dict[k] = request.GET[k] else: r_dict["params"][k] = request.GET[k] # Just parse body for all non IE CORS stuff else: r_dict = parse_body(r_dict, request) # Update dict with any GET data r_dict["params"].update(request.GET.dict()) # Method gets set for cors already if "method" not in r_dict: # Differentiate GET and POST if request.method == "POST" and (request.path[6:] == "statements" or request.path[6:] == "statements/"): # Can have empty body for POST (acts like GET) if "body" in r_dict: # If body is a list, it's a post if not isinstance(r_dict["body"], list): if not isinstance(r_dict["body"], dict): raise BadRequest("Cannot evaluate data into dictionary to parse -- Error: %s" % r_dict["body"]) # If actor verb and object not in body - means it's a GET or invalid POST if not ("actor" in r_dict["body"] and "verb" in r_dict["body"] and "object" in r_dict["body"]): # If body keys are in get params - GET - else invalid request if set(r_dict["body"].keys()).issubset( [ "statementId", "voidedStatementId", "agent", "verb", "activity", "registration", "related_activities", "related_agents", "since", "until", "limit", "format", "attachments", "ascending", ] ): r_dict["method"] = "GET" else: raise BadRequest("Statement is missing actor, verb, or object") else: r_dict["method"] = "POST" else: r_dict["method"] = "POST" else: r_dict["method"] = "GET" else: r_dict["method"] = request.method # Set if someone is hitting the statements/more endpoint if more_id: r_dict["more_id"] = more_id return r_dict