def get_headers(headers): r = {} if 'HTTP_UPDATED' in headers: try: r['updated'] = parse_datetime(headers['HTTP_UPDATED']) except (Exception, ISO8601Error): raise ParamError("Updated header was not a valid ISO8601 timestamp") elif 'updated' in headers: try: r['updated'] = parse_datetime(headers['updated']) except (Exception, ISO8601Error): raise ParamError("Updated header was not a valid ISO8601 timestamp") r['CONTENT_TYPE'] = headers.get('CONTENT_TYPE', '') if r['CONTENT_TYPE'] == '' and 'Content-Type' in headers: r['CONTENT_TYPE'] = headers['Content-Type'] # FireFox automatically adds ;charset=foo to the end of headers. This will strip it out if ';' in r['CONTENT_TYPE']: r['CONTENT_TYPE'] = r['CONTENT_TYPE'].split(';')[0] r['ETAG'] = get_etag_info(headers, required=False) if 'HTTP_AUTHORIZATION' in headers: r['Authorization'] = headers.get('HTTP_AUTHORIZATION', None) elif 'Authorization' in headers: r['Authorization'] = headers.get('Authorization', None) if 'Accept_Language' in headers: r['language'] = headers.get('Accept_Language', None) elif 'Accept-Language' in headers: r['language'] = headers['Accept-Language'] if 'X-Experience-API-Version' in headers: r['X-Experience-API-Version'] = headers['X-Experience-API-Version'] return r
def get_headers(headers): r = {} if 'HTTP_UPDATED' in headers: r['updated'] = headers['HTTP_UPDATED'] elif 'updated' in headers: r['updated'] = headers['updated'] r['CONTENT_TYPE'] = headers.get('CONTENT_TYPE', '') if r['CONTENT_TYPE'] == '' and 'Content-Type' in headers: r['CONTENT_TYPE'] = headers['Content-Type'] # FireFox automatically adds ;charset=foo to the end of headers. This will strip it out if ';' in r['CONTENT_TYPE']: r['CONTENT_TYPE'] = r['CONTENT_TYPE'].split(';')[0] r['ETAG'] = get_etag_info(headers, required=False) if 'HTTP_AUTHORIZATION' in headers: r['Authorization'] = headers.get('HTTP_AUTHORIZATION', None) elif 'Authorization' in headers: r['Authorization'] = headers.get('Authorization', None) if 'Accept_Language' in headers: r['language'] = headers.get('Accept_Language', None) elif 'Accept-Language' in headers: r['language'] = headers['Accept-Language'] return r
def get_headers(headers): header_dict = {} # Get updated header if 'HTTP_UPDATED' in headers: try: header_dict['updated'] = parse_datetime( headers.pop('HTTP_UPDATED')) except (Exception, ISO8601Error): raise ParamError( "Updated header was not a valid ISO8601 timestamp") elif 'updated' in headers: try: header_dict['updated'] = parse_datetime(headers.pop('updated')) except (Exception, ISO8601Error): raise ParamError( "Updated header was not a valid ISO8601 timestamp") # Get content type header header_dict['CONTENT_TYPE'] = headers.pop('CONTENT_TYPE', None) if not header_dict['CONTENT_TYPE'] and 'Content-Type' in headers: header_dict['CONTENT_TYPE'] = headers.pop('Content-Type') # Could not exist with deletes if header_dict['CONTENT_TYPE']: # FireFox automatically adds ;charset=foo to the end of headers. This # will strip it out if ';' in header_dict['CONTENT_TYPE'] and 'boundary' not in header_dict[ 'CONTENT_TYPE']: header_dict['CONTENT_TYPE'] = header_dict['CONTENT_TYPE'].split( ';')[0] # Get etag header_dict['ETAG'] = get_etag_info(headers, required=False) # Get authorization - don't pop off - needed for setting authorization if 'HTTP_AUTHORIZATION' in headers: header_dict['Authorization'] = headers.get('HTTP_AUTHORIZATION') elif 'Authorization' in headers: header_dict['Authorization'] = headers.get('Authorization') # Get language if 'Accept_Language' in headers: header_dict['language'] = headers.pop('Accept_Language') elif 'Accept-Language' in headers: header_dict['language'] = headers.pop('Accept-Language') elif 'HTTP_ACCEPT_LANGUAGE' in headers: header_dict['language'] = headers.pop('HTTP_ACCEPT_LANGUAGE') # Get xapi version if 'X-Experience-API-Version' in headers: header_dict['X-Experience-API-Version'] = headers.pop( 'X-Experience-API-Version') return header_dict
def get_headers(headers): header_dict = {} # Get updated header if 'HTTP_UPDATED' in headers: try: header_dict['updated'] = parse_datetime( headers.pop('HTTP_UPDATED')) except (Exception, ISO8601Error): raise ParamError( "Updated header was not a valid ISO8601 timestamp") elif 'updated' in headers: try: header_dict['updated'] = parse_datetime(headers.pop('updated')) except (Exception, ISO8601Error): raise ParamError( "Updated header was not a valid ISO8601 timestamp") # Get content type header header_dict['CONTENT_TYPE'] = headers.pop('CONTENT_TYPE', None) if not header_dict['CONTENT_TYPE'] and 'Content-Type' in headers: header_dict['CONTENT_TYPE'] = headers.pop('Content-Type') # Could not exist with deletes if header_dict['CONTENT_TYPE']: # FireFox automatically adds ;charset=foo to the end of headers. This # will strip it out if ';' in header_dict['CONTENT_TYPE'] and 'boundary' not in header_dict['CONTENT_TYPE']: header_dict['CONTENT_TYPE'] = header_dict['CONTENT_TYPE'].split(';')[ 0] # Get etag header_dict['ETAG'] = get_etag_info(headers, required=False) # Get authorization - don't pop off - needed for setting authorization if 'HTTP_AUTHORIZATION' in headers: header_dict['Authorization'] = headers.get('HTTP_AUTHORIZATION') elif 'Authorization' in headers: header_dict['Authorization'] = headers.get('Authorization') # Get language if 'Accept_Language' in headers: header_dict['language'] = headers.pop('Accept_Language') elif 'Accept-Language' in headers: header_dict['language'] = headers.pop('Accept-Language') elif 'HTTP_ACCEPT_LANGUAGE' in headers: header_dict['language'] = headers.pop('HTTP_ACCEPT_LANGUAGE') # Get xapi version if 'X-Experience-API-Version' in headers: header_dict[ 'X-Experience-API-Version'] = headers.pop('X-Experience-API-Version') return header_dict
def get_headers(headers): r = {} if 'HTTP_UPDATED' in headers: try: r['updated'] = parse_datetime(headers['HTTP_UPDATED']) except (Exception, ISO8601Error): raise ParamError( "Updated header was not a valid ISO8601 timestamp") elif 'updated' in headers: try: r['updated'] = parse_datetime(headers['updated']) except (Exception, ISO8601Error): raise ParamError( "Updated header was not a valid ISO8601 timestamp") r['CONTENT_TYPE'] = headers.get('CONTENT_TYPE', '') if r['CONTENT_TYPE'] == '' and 'Content-Type' in headers: r['CONTENT_TYPE'] = headers['Content-Type'] # FireFox automatically adds ;charset=foo to the end of headers. This will strip it out if ';' in r['CONTENT_TYPE']: r['CONTENT_TYPE'] = r['CONTENT_TYPE'].split(';')[0] r['ETAG'] = get_etag_info(headers, required=False) if 'HTTP_AUTHORIZATION' in headers: r['Authorization'] = headers.get('HTTP_AUTHORIZATION', None) elif 'Authorization' in headers: r['Authorization'] = headers.get('Authorization', None) if 'Accept_Language' in headers: r['language'] = headers.get('Accept_Language', None) elif 'Accept-Language' in headers: r['language'] = headers['Accept-Language'] if 'X-Experience-API-Version' in headers: r['X-Experience-API-Version'] = headers['X-Experience-API-Version'] return r