1
- use std:: collections:: HashMap ;
2
-
3
1
use eframe:: egui:: { self } ;
4
2
use egui_extras:: TableRow ;
5
3
use proxyapi:: { * , hyper:: Method } ;
6
4
7
- struct Request {
8
- http_method : Method ,
9
- method : String ,
10
- uri : String ,
11
- version : String ,
12
- headers : HashMap < String , String > ,
13
- body : String ,
14
- time : i64 ,
15
- }
16
-
17
- impl Request {
18
- fn new (
19
- http_method : Method ,
20
- method : String ,
21
- uri : String ,
22
- version : String ,
23
- headers : HashMap < String , String > ,
24
- body : String ,
25
- time : i64 ,
26
- ) -> Self {
27
- Self {
28
- http_method,
29
- method,
30
- uri,
31
- version,
32
- headers,
33
- body,
34
- time,
35
- }
36
- }
37
- }
38
-
39
- pub struct Response {
40
- status : String ,
41
- version : String ,
42
- headers : HashMap < String , String > ,
43
- body : String ,
44
- time : i64 ,
45
- }
46
-
47
- impl Response {
48
- fn new (
49
- status : String ,
50
- version : String ,
51
- headers : HashMap < String , String > ,
52
- body : String ,
53
- time : i64 ,
54
- ) -> Self {
55
- Self {
56
- status,
57
- version,
58
- headers,
59
- body,
60
- time,
61
- }
62
- }
63
- }
64
-
65
5
pub struct Details ;
66
6
67
7
#[ derive( PartialEq ) ]
@@ -77,116 +17,73 @@ impl Default for InfoOptions {
77
17
}
78
18
}
79
19
pub struct RequestInfo {
80
- request : Option < Request > ,
81
- response : Option < Response > ,
20
+ request : Option < ProxiedRequest > ,
21
+ response : Option < ProxiedResponse > ,
82
22
details : Option < Details > ,
83
23
}
84
-
85
- impl Default for RequestInfo {
86
- fn default ( ) -> Self {
87
- RequestInfo {
88
- request : None ,
89
- response : None ,
90
- details : None ,
91
- }
92
- }
93
- }
94
-
95
- impl From < Output > for RequestInfo {
96
- fn from ( value : Output ) -> Self {
97
- let request = match value. req ( ) {
98
- Some ( r) => Some ( Request :: new (
99
- r. http_method ( ) . clone ( ) ,
100
- r. method ( ) . to_string ( ) ,
101
- r. uri ( ) . to_string ( ) ,
102
- r. version ( ) . to_string ( ) ,
103
- r. headers ( )
104
- . into_iter ( )
105
- . map ( |h| ( h. 0 . to_string ( ) , h. 1 . to_string ( ) ) )
106
- . collect ( ) ,
107
- r. body ( ) . to_string ( ) ,
108
- r. time ( ) ,
109
- ) ) ,
110
- None => None ,
111
- } ;
112
-
113
- let response = match value. res ( ) {
114
- Some ( r) => Some ( Response :: new (
115
- r. status ( ) . to_string ( ) ,
116
- r. version ( ) . to_string ( ) ,
117
- r. headers ( )
118
- . into_iter ( )
119
- . map ( |h| ( h. 0 . to_string ( ) , h. 1 . to_string ( ) ) )
120
- . collect ( ) ,
121
- r. body ( ) . to_string ( ) ,
122
- r. time ( ) ,
123
- ) ) ,
124
- None => None ,
125
- } ;
126
-
127
- let details = None ;
128
-
129
- RequestInfo {
24
+ impl RequestInfo {
25
+ pub fn new ( request : Option < ProxiedRequest > , response : Option < ProxiedResponse > ) ->Self {
26
+ Self {
130
27
request,
131
28
response,
132
- details,
29
+ details : None
133
30
}
134
31
}
135
32
}
136
-
137
33
impl RequestInfo {
138
- pub fn show_request ( & mut self , ui : & mut egui:: Ui ) {
34
+ pub fn show_request ( & self , ui : & mut egui:: Ui ) {
139
35
if let Some ( r) = & self . request {
140
36
ui. strong ( "Method" ) ;
141
- ui. label ( & r. method ) ;
37
+ ui. label ( r. method ( ) . to_string ( ) ) ;
142
38
143
39
ui. strong ( "Version" ) ;
144
- ui. label ( & r. version ) ;
40
+ ui. label ( format ! ( "{:?}" , r. version( ) ) ) ;
145
41
146
42
ui. strong ( "Headers" ) ;
147
- for ( k, v) in r. headers . iter ( ) {
148
- ui. label ( format ! ( "{}: {}" , & k, & v) ) ;
43
+ for ( k, v) in r. headers ( ) . iter ( ) {
44
+ if let Ok ( value_str) = v. to_str ( ) {
45
+ ui. label ( format ! ( "{}: {}" , & k, & value_str) ) ;
46
+ }
149
47
}
150
48
151
- ui. strong ( "body " ) ;
152
- ui. label ( & r. body ) ;
49
+ ui. strong ( "Body " ) ;
50
+ ui. label ( format ! ( "{:?}" , r. body( ) . as_ref ( ) ) ) ;
153
51
154
52
ui. strong ( "Time" ) ;
155
- ui. label ( & r. time . to_string ( ) ) ;
53
+ ui. label ( & r. time ( ) . to_string ( ) ) ;
156
54
} else {
157
55
ui. label ( "No requests" ) ;
158
56
}
159
57
}
160
58
161
- pub fn show_response ( & mut self , ui : & mut egui:: Ui ) {
59
+ pub fn show_response ( & self , ui : & mut egui:: Ui ) {
162
60
if let Some ( r) = & self . response {
163
61
ui. strong ( "Status" ) ;
164
- ui. label ( & r. status ) ;
62
+ ui. label ( & r. status ( ) . to_string ( ) ) ;
165
63
166
64
ui. strong ( "Version" ) ;
167
- ui. label ( & r. version ) ;
168
-
169
- ui. strong ( "Status" ) ;
170
- ui. label ( & r. status ) ;
65
+ ui. label ( format ! ( "{:?}" , r. version( ) ) ) ;
171
66
172
67
ui. strong ( "Headers" ) ;
173
- for ( k, v) in r. headers . iter ( ) {
174
- ui. label ( format ! ( "{}: {}" , & k, & v) ) ;
68
+ for ( k, v) in r. headers ( ) . iter ( ) {
69
+ if let Ok ( value_str) = v. to_str ( ) {
70
+ ui. label ( format ! ( "{}: {}" , & k, & value_str) ) ;
71
+ }
175
72
}
176
73
177
- ui. strong ( "body " ) ;
178
- ui. label ( & r. body ) ;
74
+ ui. strong ( "Body " ) ;
75
+ ui. label ( format ! ( "{:?}" , r. body( ) . as_ref ( ) ) ) ;
179
76
180
77
ui. strong ( "Time" ) ;
181
- ui. label ( & r. time . to_string ( ) ) ;
78
+ ui. label ( & r. time ( ) . to_string ( ) ) ;
182
79
} else {
183
80
ui. label ( "No Response" ) ;
184
81
}
185
82
}
186
83
187
84
pub fn should_show ( & self , method : & Method ) ->bool {
188
85
if let Some ( req) = & self . request {
189
- req. http_method == method
86
+ req. method ( ) == method
190
87
} else {
191
88
false
192
89
}
@@ -202,21 +99,21 @@ impl RequestInfo {
202
99
pub fn render_row ( & self , row : & mut TableRow ) {
203
100
let req = self . request . as_ref ( ) . unwrap ( ) ;
204
101
let res = self . response . as_ref ( ) . unwrap ( ) ;
205
- let time = ( res. time as f64 - req. time as f64 ) * 10_f64 . powf ( -9.0 ) as f64 ;
102
+ let time = ( res. time ( ) as f64 - req. time ( ) as f64 ) * 10_f64 . powf ( -9.0 ) as f64 ;
206
103
row. col ( |ui| {
207
- ui. label ( & req. uri ) ;
104
+ ui. label ( req. uri ( ) . to_string ( ) ) ;
208
105
} ) ;
209
106
210
107
row. col ( |ui| {
211
- ui. label ( & req. method ) ;
108
+ ui. label ( req. method ( ) . to_string ( ) ) ;
212
109
} ) ;
213
110
214
111
row. col ( |ui| {
215
- ui. label ( & res. status ) ;
112
+ ui. label ( res. status ( ) . to_string ( ) ) ;
216
113
} ) ;
217
114
218
115
row. col ( |ui| {
219
- ui. label ( format ! ( "{} bytes" , & res. body. len( ) ) ) ;
116
+ ui. label ( format ! ( "{} bytes" , res. body( ) . len( ) ) ) ;
220
117
} ) ;
221
118
222
119
row. col ( |ui| {
0 commit comments