Repository navigation
fix(http): handle null request, keep span open over call, and isolate options in HeadersInspectionHandler - #821
Open
Hardik K (hardikkaurani) wants to merge 2 commits into
Conversation
… options in HeadersInspectionHandler
… and span failure tests
Contributor
Author
|
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! |
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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)