3535 - _parse_args
3636 - post_construct (*)
3737 - update_http_args
38+
39+ do_response returns a dictionary that can look like this:
40+ {
41+ 'response':
42+ _response as a string or as a Message instance_
43+ 'http_headers': [
44+ ('Content-type', 'application/json'),
45+ ('Pragma', 'no-cache'),
46+ ('Cache-Control', 'no-store')
47+ ],
48+ 'cookie': _list of cookies_
49+ }
50+
51+ "response" MUST be present
52+ "http_headers" MAY be present
53+ "cookie": MAY be present
3854"""
3955
4056
@@ -319,6 +335,9 @@ def response_info(self, response_args, request, **kwargs):
319335 return self .construct (response_args , request , ** kwargs )
320336
321337 def do_response (self , response_args = None , request = None , error = "" , ** kwargs ):
338+ """
339+
340+ """
322341 do_placement = True
323342 content_type = "text/html"
324343 _resp = {}
@@ -336,43 +355,47 @@ def do_response(self, response_args=None, request=None, error="", **kwargs):
336355 elif "response_msg" in kwargs :
337356 resp = kwargs ["response_msg" ]
338357 do_placement = False
339- _response = "" # This is just for my IDE
340- if self .response_format == "json" :
341- content_type = "application/json"
342- elif self .request_format in ["jws" , "jwe" , "jose" ]:
343- content_type = "application/jose"
344- else :
345- content_type = "application/x-www-form-urlencoded"
346- else :
347- _response = self .response_info (response_args , request , ** kwargs )
348-
349- if do_placement :
350- if self .response_placement == "body" :
358+ _response = ""
359+ content_type = kwargs .get ('content_type' )
360+ if content_type is None :
351361 if self .response_format == "json" :
352362 content_type = "application/json"
353- resp = _response .to_json ()
354363 elif self .request_format in ["jws" , "jwe" , "jose" ]:
355364 content_type = "application/jose"
356- resp = _response
357365 else :
358366 content_type = "application/x-www-form-urlencoded"
359- resp = _response .to_urlencoded ()
360- elif self .response_placement == "url" :
361- # content_type = 'application/x-www-form-urlencoded'
362- content_type = ""
363- try :
364- fragment_enc = kwargs ["fragment_enc" ]
365- except KeyError :
366- fragment_enc = fragment_encoding (kwargs ["return_type" ])
367+ else :
368+ _response = self .response_info (response_args , request , ** kwargs )
367369
368- if fragment_enc :
369- resp = _response .request (kwargs ["return_uri" ], True )
370+ if do_placement :
371+ content_type = kwargs .get ('content_type' )
372+ if content_type is None :
373+ if self .response_placement == "body" :
374+ if self .response_format == "json" :
375+ content_type = "application/json"
376+ resp = _response .to_json ()
377+ elif self .request_format in ["jws" , "jwe" , "jose" ]:
378+ content_type = "application/jose"
379+ resp = _response
380+ else :
381+ content_type = "application/x-www-form-urlencoded"
382+ resp = _response .to_urlencoded ()
383+ elif self .response_placement == "url" :
384+ # content_type = 'application/x-www-form-urlencoded'
385+ content_type = ""
386+ try :
387+ fragment_enc = kwargs ["fragment_enc" ]
388+ except KeyError :
389+ fragment_enc = fragment_encoding (kwargs ["return_type" ])
390+
391+ if fragment_enc :
392+ resp = _response .request (kwargs ["return_uri" ], True )
393+ else :
394+ resp = _response .request (kwargs ["return_uri" ])
370395 else :
371- resp = _response .request (kwargs ["return_uri" ])
372- else :
373- raise ValueError (
374- "Don't know where that is: '{}" .format (self .response_placement )
375- )
396+ raise ValueError (
397+ "Don't know where that is: '{}" .format (self .response_placement )
398+ )
376399
377400 if content_type :
378401 try :
0 commit comments