Repository navigation
fix(http): handle null request, keep span open over call, and isolate options in HeadersInspectionHandler - #821
Conversation
|
Hi Vincent Biret (@baywet), I've created this PR to resolve the span lifecycle, per-request option isolation, multi-valued header preservation, and null checks for HeadersInspectionHandler, complete with comprehensive regression unit tests. Ready for your review whenever convenient! |
|
The review comments have been addressed in the latest commit:
All linters and test suites pass cleanly. Ready for review! |
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
… options in HeadersInspectionHandler
… and span failure tests
…n during transport
095d388 to
7f2763c
Compare
|
Thanks for the review Vincent Biret (@baywet) |
|





Description
This PR brings
HeadersInspectionHandlerinto full alignment with the middleware patterns and error handling across Kiota HTTP:Validates
if request is None: raise TypeError("request cannot be null")matchingBodyInspectionHandler, preventing an unexpectedAttributeErroron invalid requests.Keeps the observability span open over the downstream
super().send(request, transport)call and ensuresspan.end()is invoked within atry ... finallyblock (mirroring the fix inUrlReplaceHandlerandBodyInspectionHandler), ensuring correct timing and preventing dropped spans on transport failures.Clears captured request and response headers on each call on whichever option object is active (
current_options), preventing headers from previous requests or retry attempts from accumulating when passing customHeadersInspectionHandlerOptionper request.Uses
request.headers.get_list(header)andresponse.headers.get_list(header)when feeding intoHeadersCollection.add, accurately preserving discrete multi-valued headers (e.g. multiple cookies or accepts) without comma concatenation.Testing
Added comprehensive unit tests in
packages/http/httpx/tests/middleware_tests/test_headers_inspection_handler.py:test_send_request_none_raises_type_errortest_headers_inspection_handler_request_options_isolation_and_clearingtest_headers_inspection_handler_multi_valued_headerstest_span_ends_on_transport_failurecc Vincent Biret (@baywet)