@@ -41,89 +41,88 @@ def __init__(self, request):
4141 self .request = request
4242
4343 def extract_into_event (self , event , client_options ):
44+ content_length = self .content_length ()
4445 request_info = event .setdefault ("request" , {})
45- request_info ["url" ] = self .url
46+ request_info ["url" ] = self .url ()
4647
4748 if _should_send_default_pii ():
48- request_info ["cookies" ] = dict (self .cookies )
49+ request_info ["cookies" ] = dict (self .cookies () )
4950
5051 bodies = client_options .get ("request_bodies" )
5152 if (
5253 bodies == "never"
53- or (bodies == "small" and self . content_length > 10 ** 3 )
54- or (bodies == "medium" and self . content_length > 10 ** 4 )
54+ or (bodies == "small" and content_length > 10 ** 3 )
55+ or (bodies == "medium" and content_length > 10 ** 4 )
5556 ):
5657 data = AnnotatedValue (
5758 "" ,
58- {
59- "rem" : [["!config" , "x" , 0 , self .content_length ]],
60- "len" : self .content_length ,
61- },
62- )
63- elif self .form or self .files :
64- data = dict (self .form .items ())
65- for k , v in self .files .items ():
66- size = self .size_of_file (v )
67- data [k ] = AnnotatedValue (
68- "" , {"len" : size , "rem" : [["!filecontent" , "x" , 0 , size ]]}
69- )
70-
71- elif self .json is not None :
72- data = self .json
73- elif self .raw_data :
74- data = AnnotatedValue (
75- "" ,
76- {
77- "rem" : [["!rawbody" , "x" , 0 , self .content_length ]],
78- "len" : self .content_length ,
79- },
59+ {"rem" : [["!config" , "x" , 0 , content_length ]], "len" : content_length },
8060 )
8161 else :
82- return
62+ parsed_body = self .parsed_body ()
63+ if parsed_body :
64+ data = parsed_body
65+ elif self .raw_data ():
66+ data = AnnotatedValue (
67+ "" ,
68+ {
69+ "rem" : [["!rawbody" , "x" , 0 , content_length ]],
70+ "len" : content_length ,
71+ },
72+ )
73+ else :
74+ return
8375
8476 request_info ["data" ] = data
8577
86- @property
8778 def content_length (self ):
8879 try :
89- return int (self .env .get ("CONTENT_LENGTH" , 0 ))
80+ return int (self .env () .get ("CONTENT_LENGTH" , 0 ))
9081 except ValueError :
9182 return 0
9283
93- @property
9484 def url (self ):
9585 raise NotImplementedError ()
9686
97- @property
9887 def cookies (self ):
9988 raise NotImplementedError ()
10089
101- @property
10290 def raw_data (self ):
10391 raise NotImplementedError ()
10492
105- @property
10693 def form (self ):
10794 raise NotImplementedError ()
10895
109- @property
96+ def parsed_body (self ):
97+ form = self .form ()
98+ files = self .files ()
99+ if form or files :
100+ data = dict (form .items ())
101+ for k , v in files .items ():
102+ size = self .size_of_file (v )
103+ data [k ] = AnnotatedValue (
104+ "" , {"len" : size , "rem" : [["!filecontent" , "x" , 0 , size ]]}
105+ )
106+
107+ return data
108+
109+ return self .json ()
110+
110111 def is_json (self ):
111- mt = (self .env .get ("CONTENT_TYPE" ) or "" ).split (";" , 1 )[0 ]
112+ mt = (self .env () .get ("CONTENT_TYPE" ) or "" ).split (";" , 1 )[0 ]
112113 return (
113114 mt == "application/json"
114115 or (mt .startswith ("application/" ))
115116 and mt .endswith ("+json" )
116117 )
117118
118- @property
119119 def json (self ):
120120 try :
121- if self .is_json :
122- return json .loads (self .raw_data .decode ("utf-8" ))
121+ if self .is_json () :
122+ return json .loads (self .raw_data () .decode ("utf-8" ))
123123 except ValueError :
124124 pass
125125
126- @property
127126 def files (self ):
128127 raise NotImplementedError ()
129128
0 commit comments