@@ -41,89 +41,88 @@ def __init__(self, request):
41
41
self .request = request
42
42
43
43
def extract_into_event (self , event , client_options ):
44
+ content_length = self .content_length ()
44
45
request_info = event .setdefault ("request" , {})
45
- request_info ["url" ] = self .url
46
+ request_info ["url" ] = self .url ()
46
47
47
48
if _should_send_default_pii ():
48
- request_info ["cookies" ] = dict (self .cookies )
49
+ request_info ["cookies" ] = dict (self .cookies () )
49
50
50
51
bodies = client_options .get ("request_bodies" )
51
52
if (
52
53
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 )
55
56
):
56
57
data = AnnotatedValue (
57
58
"" ,
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 },
80
60
)
81
61
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
83
75
84
76
request_info ["data" ] = data
85
77
86
- @property
87
78
def content_length (self ):
88
79
try :
89
- return int (self .env .get ("CONTENT_LENGTH" , 0 ))
80
+ return int (self .env () .get ("CONTENT_LENGTH" , 0 ))
90
81
except ValueError :
91
82
return 0
92
83
93
- @property
94
84
def url (self ):
95
85
raise NotImplementedError ()
96
86
97
- @property
98
87
def cookies (self ):
99
88
raise NotImplementedError ()
100
89
101
- @property
102
90
def raw_data (self ):
103
91
raise NotImplementedError ()
104
92
105
- @property
106
93
def form (self ):
107
94
raise NotImplementedError ()
108
95
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
+
110
111
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 ]
112
113
return (
113
114
mt == "application/json"
114
115
or (mt .startswith ("application/" ))
115
116
and mt .endswith ("+json" )
116
117
)
117
118
118
- @property
119
119
def json (self ):
120
120
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" ))
123
123
except ValueError :
124
124
pass
125
125
126
- @property
127
126
def files (self ):
128
127
raise NotImplementedError ()
129
128
0 commit comments