From 4ea407b3bb71042fb357a5bd61a73c2d0aa88530 Mon Sep 17 00:00:00 2001 From: vesp Date: Mon, 12 Jan 2026 11:02:21 +0100 Subject: [PATCH] Display response size in the status line --- src/http_client.py | 13 +++++++++++-- src/models.py | 1 + src/request_tab_widget.py | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/http_client.py b/src/http_client.py index 9795ef6..c570d37 100644 --- a/src/http_client.py +++ b/src/http_client.py @@ -153,15 +153,24 @@ class HttpClient: # Format headers in HTTPie-style output (HTTP/1.1 200 OK\nHeader: value\n...) headers_text = self._format_headers(msg, status_code, status_text) + # Get raw body data for size calculation + body_bytes = bytes_data.get_data() + + # Calculate total response size (headers + body) + headers_size = len(headers_text.encode('utf-8')) + body_size = len(body_bytes) + total_size = headers_size + body_size + # Decode body with error handling - body = bytes_data.get_data().decode('utf-8', errors='replace') + body = body_bytes.decode('utf-8', errors='replace') return HttpResponse( status_code=status_code, status_text=status_text, headers=headers_text, body=body.strip(), - response_time_ms=response_time + response_time_ms=response_time, + response_size_bytes=total_size ) def _format_headers(self, msg: Soup.Message, status_code: int, status_text: str) -> str: diff --git a/src/models.py b/src/models.py index d242ff2..d86cd1f 100644 --- a/src/models.py +++ b/src/models.py @@ -52,6 +52,7 @@ class HttpResponse: headers: str # Raw header text from libsoup3 body: str # Raw body text response_time_ms: float + response_size_bytes: int = 0 # Total response size in bytes def to_dict(self): """Convert to dictionary for JSON serialization.""" diff --git a/src/request_tab_widget.py b/src/request_tab_widget.py index b7c872d..ac54230 100644 --- a/src/request_tab_widget.py +++ b/src/request_tab_widget.py @@ -372,6 +372,9 @@ class RequestTabWidget(Gtk.Box): self.time_label = Gtk.Label(label="") status_box.append(self.time_label) + self.size_label = Gtk.Label(label="") + status_box.append(self.size_label) + # Spacer spacer = Gtk.Box() spacer.set_hexpand(True) @@ -901,6 +904,10 @@ class RequestTabWidget(Gtk.Box): time_text = f"{response.response_time_ms:.0f} ms" self.time_label.set_text(time_text) + # Update size + size_text = self._format_size(response.response_size_bytes) + self.size_label.set_text(size_text) + # Update response headers buffer = self.response_headers_textview.get_buffer() buffer.set_text(response.headers) @@ -921,6 +928,7 @@ class RequestTabWidget(Gtk.Box): """Display error in this tab's UI.""" self.status_label.set_text("Error") self.time_label.set_text("") + self.size_label.set_text("") # Clear response headers buffer = self.response_headers_textview.get_buffer() @@ -1179,6 +1187,20 @@ class RequestTabWidget(Gtk.Box): return body + def _format_size(self, size_bytes): + """Format size in bytes to human-readable format (B, KB, MB, GB).""" + if size_bytes < 1024: + return f"{size_bytes} B" + elif size_bytes < 1024 * 1024: + size_kb = size_bytes / 1024 + return f"{size_kb:.1f} KB" + elif size_bytes < 1024 * 1024 * 1024: + size_mb = size_bytes / (1024 * 1024) + return f"{size_mb:.1f} MB" + else: + size_gb = size_bytes / (1024 * 1024 * 1024) + return f"{size_gb:.1f} GB" + def _build_environment_selector_inline(self, container): """Build environment selector and add to container.""" if not self.project_id: