@@ -298,9 +298,9 @@ def _send_request(
298298 json = request .get_json ()
299299 if json :
300300 headers_dict [b"Content-Type" ] = [b"application/json" ]
301- self .sign_request (
301+ auth_headers = self .build_auth_headers (
302302 destination_bytes , method_bytes , url_to_sign_bytes ,
303- headers_dict , json ,
303+ json ,
304304 )
305305 data = encode_canonical_json (json )
306306 producer = FileBodyProducer (
@@ -309,11 +309,12 @@ def _send_request(
309309 )
310310 else :
311311 producer = None
312- self .sign_request (
312+ auth_headers = self .build_auth_headers (
313313 destination_bytes , method_bytes , url_to_sign_bytes ,
314- headers_dict ,
315314 )
316315
316+ headers_dict [b"Authorization" ] = auth_headers
317+
317318 logger .info (
318319 "{%s} [%s] Sending request: %s %s" ,
319320 request .txn_id , request .destination , request .method ,
@@ -440,24 +441,23 @@ def _send_request(
440441
441442 defer .returnValue (response )
442443
443- def sign_request (self , destination , method , url_bytes , headers_dict ,
444- content = None , destination_is = None ):
444+ def build_auth_headers (
445+ self , destination , method , url_bytes , content = None , destination_is = None ,
446+ ):
445447 """
446- Signs a request by adding an Authorization header to headers_dict
448+ Builds the Authorization headers for a federation request
447449 Args:
448450 destination (bytes|None): The desination home server of the request.
449451 May be None if the destination is an identity server, in which case
450452 destination_is must be non-None.
451453 method (bytes): The HTTP method of the request
452454 url_bytes (bytes): The URI path of the request
453- headers_dict (dict[bytes, list[bytes]]): Dictionary of request headers to
454- append to
455455 content (object): The body of the request
456456 destination_is (bytes): As 'destination', but if the destination is an
457457 identity server
458458
459459 Returns:
460- None
460+ list[bytes]: a list of headers to be added as "Authorization:" headers
461461 """
462462 request = {
463463 "method" : method ,
@@ -484,8 +484,7 @@ def sign_request(self, destination, method, url_bytes, headers_dict,
484484 self .server_name , key , sig ,
485485 )).encode ('ascii' )
486486 )
487-
488- headers_dict [b"Authorization" ] = auth_headers
487+ return auth_headers
489488
490489 @defer .inlineCallbacks
491490 def put_json (self , destination , path , args = {}, data = {},
0 commit comments