Display response size in the status line
This commit is contained in:
parent
d2c7c09312
commit
8c842ee3f1
@ -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:
|
||||
|
||||
@ -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."""
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user