Display response size in the status line
This commit is contained in:
parent
2000f98d35
commit
4ea407b3bb
@ -153,15 +153,24 @@ class HttpClient:
|
|||||||
# Format headers in HTTPie-style output (HTTP/1.1 200 OK\nHeader: value\n...)
|
# Format headers in HTTPie-style output (HTTP/1.1 200 OK\nHeader: value\n...)
|
||||||
headers_text = self._format_headers(msg, status_code, status_text)
|
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
|
# 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(
|
return HttpResponse(
|
||||||
status_code=status_code,
|
status_code=status_code,
|
||||||
status_text=status_text,
|
status_text=status_text,
|
||||||
headers=headers_text,
|
headers=headers_text,
|
||||||
body=body.strip(),
|
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:
|
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
|
headers: str # Raw header text from libsoup3
|
||||||
body: str # Raw body text
|
body: str # Raw body text
|
||||||
response_time_ms: float
|
response_time_ms: float
|
||||||
|
response_size_bytes: int = 0 # Total response size in bytes
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
"""Convert to dictionary for JSON serialization."""
|
"""Convert to dictionary for JSON serialization."""
|
||||||
|
|||||||
@ -372,6 +372,9 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
self.time_label = Gtk.Label(label="")
|
self.time_label = Gtk.Label(label="")
|
||||||
status_box.append(self.time_label)
|
status_box.append(self.time_label)
|
||||||
|
|
||||||
|
self.size_label = Gtk.Label(label="")
|
||||||
|
status_box.append(self.size_label)
|
||||||
|
|
||||||
# Spacer
|
# Spacer
|
||||||
spacer = Gtk.Box()
|
spacer = Gtk.Box()
|
||||||
spacer.set_hexpand(True)
|
spacer.set_hexpand(True)
|
||||||
@ -901,6 +904,10 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
time_text = f"{response.response_time_ms:.0f} ms"
|
time_text = f"{response.response_time_ms:.0f} ms"
|
||||||
self.time_label.set_text(time_text)
|
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
|
# Update response headers
|
||||||
buffer = self.response_headers_textview.get_buffer()
|
buffer = self.response_headers_textview.get_buffer()
|
||||||
buffer.set_text(response.headers)
|
buffer.set_text(response.headers)
|
||||||
@ -921,6 +928,7 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
"""Display error in this tab's UI."""
|
"""Display error in this tab's UI."""
|
||||||
self.status_label.set_text("Error")
|
self.status_label.set_text("Error")
|
||||||
self.time_label.set_text("")
|
self.time_label.set_text("")
|
||||||
|
self.size_label.set_text("")
|
||||||
|
|
||||||
# Clear response headers
|
# Clear response headers
|
||||||
buffer = self.response_headers_textview.get_buffer()
|
buffer = self.response_headers_textview.get_buffer()
|
||||||
@ -1179,6 +1187,20 @@ class RequestTabWidget(Gtk.Box):
|
|||||||
|
|
||||||
return body
|
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):
|
def _build_environment_selector_inline(self, container):
|
||||||
"""Build environment selector and add to container."""
|
"""Build environment selector and add to container."""
|
||||||
if not self.project_id:
|
if not self.project_id:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user