#NEWLINE# @ route ( '/download' ) #NEWLINE# def download( ) : #NEWLINE# #INDENT# ( browser_type , archive , url ) = get_params ( ) #NEWLINE# response_key = get_cache_key ( archive , browser_type , url ) #NEWLINE# result = rc . get ( response_key ) #NEWLINE# if ( not result ) : #NEWLINE# #INDENT# raise HTTPError ( status = 404 , body = 'Url Not Archived' ) #NEWLINE# #UNINDENT# result = json . loads ( result ) #NEWLINE# if ( not ( 'download_url' in result ) ) : #NEWLINE# #INDENT# raise HTTPError ( status = 404 , body = 'Download Not Available' ) #NEWLINE# #UNINDENT# headers = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# session = result . get ( 'download_session' ) #NEWLINE# if session : #NEWLINE# #INDENT# headers [ 'Cookie' ] = session #NEWLINE# #UNINDENT# r = requests . get ( result [ 'download_url' ] , headers = headers , stream = True ) #NEWLINE# if ( r . status_code != 200 ) : #NEWLINE# #INDENT# raise HTTPError ( status = 400 , body = 'Invalid Download Result: {0} {1}' . format ( r . status_code , h . reason ) ) #NEWLINE# #UNINDENT# pass_headers = ( 'Content-Disposition' , 'Content-Length' , 'Content-Type' ) #NEWLINE# for h in pass_headers : #NEWLINE# #INDENT# response . set_header ( h , r . headers . get ( h ) ) #NEWLINE# #UNINDENT# response . body = r . iter_content ( ) #NEWLINE# return response