Commit a34fc29
committed
client: fix two real SDK bugs surfaced by integration harness
1. _scrape_request content-type KeyError on PUT without explicit header.
Line 213 did:
'content-type': scrape_config.headers['content-type']
if scrape_config.method in ['POST', 'PUT', 'PATCH']
else self.body_handler.content_type
This hard-reads the dict key for every PUT/PATCH/POST request. Callers who
send a PUT with just a body but no Content-Type header (e.g.
client.scrape(ScrapeConfig(url=..., method='PUT', body='test')))
got:
KeyError: 'content-type'
Fixed: use .get('content-type', self.body_handler.content_type) as the
fallback so absent header falls through to the SDK default.
2. _handle_api_response UnicodeDecodeError on non-msgpack/json compressed
responses.
Line 830 did:
body = response.content.decode('utf-8')
...when body_handler.support(headers) returned False, which happens when
the server returns a content-type that isn't application/msgpack or
application/json. For responses that are still compressed (zstd, brotli)
because the requests library didn't transparently decompress them, this
raises UnicodeDecodeError: invalid start byte.
Fixed: if response has content-encoding in the known set, call
body_handler.read() to decompress first, then decode as utf-8 with
errors='replace' as a last resort so the error never bubbles as a
cryptic Unicode failure.
Both surfaced by sdk/integration tests test_scrape_http_method_put and
test_scrape_http_method_delete after the harness was set up to run every
SDK feature against the dev stack.1 parent b4f17dd commit a34fc29
1 file changed
Lines changed: 34 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
214 | 222 | | |
215 | 223 | | |
216 | 224 | | |
217 | 225 | | |
218 | 226 | | |
219 | 227 | | |
220 | | - | |
| 228 | + | |
221 | 229 | | |
222 | 230 | | |
223 | 231 | | |
| |||
819 | 827 | | |
820 | 828 | | |
821 | 829 | | |
822 | | - | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
823 | 854 | | |
824 | 855 | | |
825 | 856 | | |
| |||
0 commit comments