19
19
import xmlrpclib
20
20
import magic
21
21
22
- from webob import Request , Response
23
22
from swift .common .swob import HTTPBadRequest , HTTPAccepted , HTTPOk , HTTPCreated , HTTPInternalServerError ,\
24
23
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
27
26
from linecache import updatecache
28
27
from gzip import GzipFile
29
28
from hashlib import sha1
29
+ from swift .common .wsgi import make_pre_authed_request
30
30
31
31
CHUNK_SIZE = 524288
32
32
@@ -39,14 +39,20 @@ def getFileName(self):
39
39
return "chk-" + self .checksum
40
40
41
41
42
+ # TODO: This is not useful
42
43
class Controller (object ):
43
44
def __init__ (self , app ):
44
45
self .app = app
45
46
self .response_args = []
46
47
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
50
56
51
57
class GzipWrap (object ):
52
58
# input is a filelike object that feeds the input
@@ -254,32 +260,33 @@ def LIST(self):
254
260
255
261
def __getFile (self , env ):
256
262
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
270
276
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 ()
274
280
else :
275
- responseFile = HTTPBadRequest ()
281
+ response = HTTPBadRequest ()
276
282
277
- return responseFile
283
+ return response
278
284
279
285
280
286
def __getChunks (self , env , urlBase , scriptName , chunks ):
281
287
fileCompressContent = []
282
288
statusFile = 200
289
+
283
290
for chunk in chunks :
284
291
fileChunk = "chk-" + str (chunk )
285
292
@@ -363,13 +370,10 @@ def __uploadFileChunks(self, env, urlBase, scriptName, separateFile):
363
370
364
371
env ['PATH_INFO' ] = urlBase + "/" + chunkName
365
372
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
373
377
374
378
if 200 > status >= 300 :
375
379
break
0 commit comments