Skip to content

Commit

Permalink
Show the number of bytes send/received
Browse files Browse the repository at this point in the history
+ clippy and cleanup
  • Loading branch information
heeckhau committed Mar 4, 2024
1 parent 34b1355 commit fb7934c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/components/content_iframe.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gloo::console::log;
use std::fmt;
// use gloo::console::log;
// use std::fmt;

use spansy::http::parse_response;
use wasm_bindgen::prelude::*;
Expand All @@ -26,11 +26,11 @@ enum ContentType {
Other,
}
fn get_content_type(bytes: &[u8]) -> (ContentType, String) {
match parse_response(&bytes) {
match parse_response(bytes) {
Ok(x) => {
// log!(format!("Test {:?}", x.headers));

let content_type = (&x)
let content_type = x
.headers
.iter()
.find(|h| h.name.as_str().to_lowercase() == "content-type")
Expand Down Expand Up @@ -58,7 +58,7 @@ fn get_content_type(bytes: &[u8]) -> (ContentType, String) {
#[function_component]
pub fn ContentIFrame(props: &Props) -> Html {
// JavaScript function to trigger Prism highlighting
use_effect(move || highlight_code());
use_effect(highlight_code);

match get_content_type(&props.bytes) {
(ContentType::Html, content_html) => html! {
Expand Down
2 changes: 1 addition & 1 deletion src/components/pem_input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use elliptic_curve::{pkcs8::DecodePublicKey, PublicKey};
use elliptic_curve::pkcs8::DecodePublicKey;

#[allow(unused_imports)]
use gloo::console::log;
Expand Down
19 changes: 11 additions & 8 deletions src/components/redacted_bytes_component.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt, ops::Range};

use gloo::console::log;
// use gloo::console::log;
use yew::prelude::*;

#[derive(Clone, PartialEq)]
Expand All @@ -27,18 +27,16 @@ pub struct Props {
}

fn get_redacted_string(redacted_char: &char, size: usize) -> String {
if true || size < 10 {
if true
/*|| size < 10*/
{
redacted_char.to_string().repeat(size)
} else {
format! {"{}...{}", redacted_char.to_string().repeat(3), redacted_char.to_string().repeat(3)}
}
}

fn redactions_in_red(
bytes: &Vec<u8>,
redacted_ranges: &Vec<Range<usize>>,
redacted_char: &char,
) -> Html {
fn redactions_in_red(bytes: &[u8], redacted_ranges: &[Range<usize>], redacted_char: &char) -> Html {
if redacted_ranges.is_empty() {
return Html::from(String::from_utf8(bytes.to_vec()).unwrap());
}
Expand Down Expand Up @@ -100,9 +98,14 @@ pub fn RedactedBytesComponent(props: &Props) -> Html {
redacted_ranges,
} = props;

let size = bytes.len();
let redacted_size = redacted_ranges
.iter()
.fold(0, |acc, r| acc + r.end - r.start);

html! {
<details class="p-4 w-5/6" open={true}>
<summary><b>{"Bytes "}{direction}{": " }</b></summary>
<summary><b>{"Bytes "}{direction}{": " }</b>{"("}{size}{"B, redacted:"}{redacted_size}{"B)"}</summary>
<div class="bg-black text-white p-4 rounded-md overflow-x-auto">
<pre>{redactions_in_red(bytes, redacted_ranges, redacted_char)}</pre>
</div>
Expand Down

0 comments on commit fb7934c

Please sign in to comment.