Skip to content

Commit f734f38

Browse files
committed
🐍 Make proxy/mock streams behave similarly
Now when streaming proxy responses the following happens in order; 0. Send status code 1. Iterate and send headers, if any 2. Close headers, if any 3. Iterate and send body lines, if any This is different in that instead of attempting to re-send headers for every line of response body, so _should_ be a little faster for Vim as the channel callback will now not need to re-parse repeated headers. Oh and this commit will be tracked by the next patch tagged version!
1 parent 0782274 commit f734f38

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ The format is based on [Keep a Changelog][] and this project adheres to
3333
______
3434

3535

36+
## [0.0.4] - 2024-10-08
37+
38+
39+
- [X] Fix JSON parser!!!
40+
- [X] Optimize and normalize proxy streaming behavior for real and mock classes
41+
42+
43+
______
44+
45+
3646
## [0.0.3] - 2024-10-07
3747

3848

scripts/proompter-channel-proxy.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,18 @@ def _POST_Response_StreamLines(self, post_data):
135135
if self.server.verbose:
136136
print("Streaming response ->", response)
137137

138+
self.send_response(response.status_code)
139+
for (keyword, value) in response.headers.items():
140+
if self.server.verbose:
141+
print("Header -- keyword | value ->", keyword, '|', value)
142+
self.send_header(keyword, value)
143+
144+
if len(response.headers):
145+
self.end_headers()
146+
138147
for line in response.iter_lines():
139148
if self.server.verbose:
140149
print(" line ->", line)
141-
self.send_response(response.status_code)
142-
self.send_header('Content-Type', 'application/json')
143-
self.end_headers()
144150
self.wfile.write(line)
145151
else:
146152
if self.server.verbose:
@@ -294,20 +300,21 @@ def _POST_Response_StreamLines(self, post_data):
294300

295301
## Attempt to pare-out headers before reading lines of response body
296302
mock_response.begin()
303+
self.send_response(mock_response.code)
304+
print(' mock_response.code ->', mock_response.code)
305+
306+
for header in mock_response.getheaders():
307+
print(' header ->', header)
308+
self.send_header(*header)
309+
310+
if len(mock_response.headers):
311+
self.end_headers()
312+
297313
while True:
298314
line = mock_response.readline()
299315
if len(line) <= 0:
300316
break
301317

302-
self.send_response(mock_response.code)
303-
print(' mock_response.code ->', mock_response.code)
304-
for header in mock_response.getheaders():
305-
print(' header ->', header)
306-
self.send_header(*header)
307-
308-
if len(mock_response.headers):
309-
self.end_headers()
310-
311318
print(' line ->', line)
312319
self.wfile.write(line)
313320

0 commit comments

Comments
 (0)