1
- use std:: sync:: mpsc:: Receiver ;
1
+ use std:: { sync:: mpsc:: Receiver , fmt :: { Display , format } , default } ;
2
2
3
3
use crate :: {
4
4
requests:: { InfoOptions , RequestInfo } ,
@@ -8,13 +8,13 @@ use crate::{
8
8
use eframe:: {
9
9
egui:: {
10
10
self , FontData , FontDefinitions , FontFamily , Grid , Layout , ScrollArea , Style , TextStyle :: * ,
11
- TopBottomPanel , Visuals ,
11
+ TopBottomPanel , Visuals , RichText , ComboBox ,
12
12
} ,
13
13
epaint:: FontId ,
14
14
Frame ,
15
15
} ;
16
16
use egui_extras:: { Column , TableBuilder } ;
17
- use proxyapi:: * ;
17
+ use proxyapi:: { * , hyper :: Method } ;
18
18
use serde:: { Deserialize , Serialize } ;
19
19
20
20
#[ derive( Serialize , Deserialize ) ]
@@ -40,15 +40,49 @@ impl Default for MitmProxyConfig {
40
40
}
41
41
}
42
42
43
+
44
+ #[ derive( Debug , Default , PartialEq , Eq ) ]
45
+ pub enum MethodFilter {
46
+ #[ default]
47
+ All ,
48
+ Only ( Method ) ,
49
+ }
50
+ impl MethodFilter {
51
+ const METHODS : [ ( & ' static str , Self ) ; 10 ] =[
52
+ ( "All" , MethodFilter :: All ) ,
53
+ ( "GET" , MethodFilter :: Only ( Method :: GET ) ) ,
54
+ ( "POST" , MethodFilter :: Only ( Method :: POST ) ) ,
55
+ ( "PUT" , MethodFilter :: Only ( Method :: PUT ) ) ,
56
+ ( "DELETE" , MethodFilter :: Only ( Method :: DELETE ) ) ,
57
+ ( "PATCH" , MethodFilter :: Only ( Method :: PATCH ) ) ,
58
+ ( "HEAD" , MethodFilter :: Only ( Method :: HEAD ) ) ,
59
+ ( "OPTIONS" , MethodFilter :: Only ( Method :: OPTIONS ) ) ,
60
+ ( "CONNECT" , MethodFilter :: Only ( Method :: CONNECT ) ) ,
61
+ ( "TRACE" , MethodFilter :: Only ( Method :: TRACE ) ) ,
62
+ ] ;
63
+ }
64
+ impl Display for MethodFilter {
65
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
66
+ if let Self :: Only ( method) = self {
67
+ Display :: fmt ( method, f)
68
+ } else {
69
+ f. write_str ( "All" )
70
+ }
71
+ }
72
+ }
73
+
74
+
43
75
struct MitmProxyState {
44
76
selected_request : Option < usize > ,
77
+ selected_request_method : MethodFilter ,
45
78
detail_option : InfoOptions ,
46
79
}
47
80
48
81
impl MitmProxyState {
49
82
fn new ( ) -> Self {
50
83
Self {
51
84
selected_request : None ,
85
+ selected_request_method : MethodFilter :: All ,
52
86
detail_option : InfoOptions :: Request ,
53
87
}
54
88
}
@@ -155,18 +189,31 @@ impl MitmProxy {
155
189
156
190
header. col ( |_ui| ( ) ) ;
157
191
} )
158
- . body ( |body| {
159
- body. rows ( text_height, self . requests . len ( ) , |row_index, mut row| {
160
- self . requests
161
- . get_mut ( row_index)
162
- . expect ( "Problem with index" )
163
- . render_row ( & mut row) ;
164
- row. col ( |ui| {
165
- if ui. button ( "🔎" ) . clicked ( ) {
166
- self . state . selected_request = Some ( row_index) ;
167
- }
168
- } ) ;
169
- } )
192
+ . body ( |mut body| {
193
+ if let MethodFilter :: Only ( filter_method) = & self . state . selected_request_method {
194
+ for ( row_index, request) in self . requests . iter ( ) . enumerate ( ) . filter ( |r|r. 1 . should_show ( & filter_method) ) {
195
+ body. row ( text_height, |mut row|{
196
+ request. render_row ( & mut row) ;
197
+ row. col ( |ui| {
198
+ if ui. button ( "🔎" ) . clicked ( ) {
199
+ self . state . selected_request = Some ( row_index) ;
200
+ }
201
+ } ) ;
202
+ } ) ;
203
+ }
204
+ } else {
205
+ body. rows ( text_height, self . requests . len ( ) , |row_index, mut row| {
206
+ self . requests
207
+ . get_mut ( row_index)
208
+ . expect ( "Problem with index" )
209
+ . render_row ( & mut row) ;
210
+ row. col ( |ui| {
211
+ if ui. button ( "🔎" ) . clicked ( ) {
212
+ self . state . selected_request = Some ( row_index) ;
213
+ }
214
+ } ) ;
215
+ } )
216
+ }
170
217
} ) ;
171
218
}
172
219
@@ -247,6 +294,23 @@ impl MitmProxy {
247
294
} )
248
295
. on_hover_text ( "Toggle theme" ) ;
249
296
297
+
298
+
299
+ const COMBOBOX_TEXT_SIZE : f32 =15. ;
300
+ ComboBox :: from_label ( "" )
301
+ . selected_text ( RichText :: new ( format ! ( "{} Requests" , & self . state. selected_request_method) ) . size ( COMBOBOX_TEXT_SIZE ) )
302
+ . wrap ( false )
303
+ . show_ui ( ui, |ui| {
304
+ ui. style_mut ( ) . wrap = Some ( false ) ;
305
+ for ( method_str, method) in MethodFilter :: METHODS {
306
+ ui. selectable_value (
307
+ & mut self . state . selected_request_method ,
308
+ method,
309
+ RichText :: new ( method_str) . size ( COMBOBOX_TEXT_SIZE )
310
+ ) ;
311
+ }
312
+ } ) ;
313
+
250
314
if close_btn. clicked ( ) {
251
315
frame. close ( ) ;
252
316
}
0 commit comments