1919import xmlrpclib
2020import magic
2121
22- from webob import Request , Response
2322from swift .common .swob import HTTPBadRequest , HTTPAccepted , HTTPOk , HTTPCreated , HTTPInternalServerError ,\
2423 HTTPNotFound , HTTPServerError , HTTPUnauthorized , HTTPForbidden ,\
25- HTTPMethodNotAllowed , wsgify
26- from swift .common .utils import get_param
24+ HTTPMethodNotAllowed , wsgify , Request , Response
25+ from swift .common .request_helpers import get_param
2726from linecache import updatecache
2827from gzip import GzipFile
2928from hashlib import sha1
29+ from swift .common .wsgi import make_pre_authed_request
3030
3131CHUNK_SIZE = 524288
3232
@@ -39,14 +39,20 @@ def getFileName(self):
3939 return "chk-" + self .checksum
4040
4141
42+ # TODO: This is not useful
4243class Controller (object ):
4344 def __init__ (self , app ):
4445 self .app = app
4546 self .response_args = []
4647
47- def do_start_response (self , * args ):
48- self .response_args .extend (args )
49-
48+ def do_start_response (self , status , headers , exc_info = None ):
49+ """
50+ Saves response info without sending it to the remote client.
51+ Uses the same semantics as the usual WSGI start_response.
52+ """
53+ self ._response_status = status
54+ self ._response_headers = headers
55+ self ._response_exc_info = exc_info
5056
5157class GzipWrap (object ):
5258 # input is a filelike object that feeds the input
@@ -254,32 +260,33 @@ def LIST(self):
254260
255261 def __getFile (self , env ):
256262 self .response_args = []
257-
258- app_iterFile = self . app (env , self . do_start_response )
259- statusFile = int (self .response_args [ 0 ]. split ()[ 0 ] )
260- headersFile = dict ( self . response_args [ 1 ])
261- if 200 <= statusFile < 300 :
262-
263- new_hdrsFile = {}
264- for key , val in headersFile .iteritems ():
265- _key = key .lower ()
266- if _key .startswith ('x-object-meta-' ):
267- new_hdrsFile ['x-amz-meta-' + key [14 :]] = val
268- elif _key in ('content-length' , 'content-type' , 'content-encoding' , 'etag' , 'last-modified' ):
269- new_hdrsFile [key ] = val
263+
264+ subrequest = make_pre_authed_request (env , agent = ( '%(orig)s ' ))
265+ response = subrequest . get_response (self .app )
266+
267+ if 200 <= response . status_int < 300 :
268+ pass
269+ # new_hdrsFile = {}
270+ # for key, val in headersFile.iteritems():
271+ # _key = key.lower()
272+ # if _key.startswith('x-object-meta-'):
273+ # new_hdrsFile['x-amz-meta-' + key[14:]] = val
274+ # elif _key in ('content-length', 'content-type', 'content-encoding', 'etag', 'last-modified'):
275+ # new_hdrsFile[key] = val
270276
271- responseFile = Response (status = statusFile , headers = new_hdrsFile , app_iter = app_iterFile )
272- elif statusFile == 401 :
273- responseFile = HTTPUnauthorized ()
277+ # responseFile = Response(status=statusFile, headers=new_hdrsFile, app_iter=app_iterFile)
278+ elif response . status_int == 401 :
279+ response = HTTPUnauthorized ()
274280 else :
275- responseFile = HTTPBadRequest ()
281+ response = HTTPBadRequest ()
276282
277- return responseFile
283+ return response
278284
279285
280286 def __getChunks (self , env , urlBase , scriptName , chunks ):
281287 fileCompressContent = []
282288 statusFile = 200
289+
283290 for chunk in chunks :
284291 fileChunk = "chk-" + str (chunk )
285292
@@ -363,13 +370,10 @@ def __uploadFileChunks(self, env, urlBase, scriptName, separateFile):
363370
364371 env ['PATH_INFO' ] = urlBase + "/" + chunkName
365372 env ['SCRIPT_NAME' ] = scriptName
366-
367- req = Request (env )
368- req .body = chunkContent
369- req .content_length = len (chunkContent )
370-
371- self .app (req .environ , self .do_start_response )
372- status = int (self .response_args [0 ].split ()[0 ])
373+
374+ subrequest = make_pre_authed_request (env , body = chunkContent , agent = ('%(orig)s ' ))
375+ response = subrequest .get_response (self .app )
376+ status = response .status_int
373377
374378 if 200 > status >= 300 :
375379 break
0 commit comments