{testsdk} Add ContentLengthProcessor to fix Content-Length header#20668
Merged
{testsdk} Add ContentLengthProcessor to fix Content-Length header#20668
ContentLengthProcessor to fix Content-Length header#20668Conversation
ContentLengthProcessor to fix Content-Length headerContentLengthProcessor to fix Content-Length header
14102cd to
b359a19
Compare
jiasli
commented
Dec 9, 2021
|
|
||
| if self.in_recording: | ||
| for processor in self.recording_processors: | ||
| for processor in self.recording_processors + self.recording_post_processors: |
Member
Author
There was a problem hiding this comment.
We can't add ContentLengthProcessor here
azure-cli/src/azure-cli-testsdk/azure/cli/testsdk/base.py
Lines 89 to 97 in 30216d0
because AbstractPreparer will add preparers when executing the test method
causing these newly added preparers to be called after ContentLengthProcessor
kairu-ms
approved these changes
Dec 10, 2021
wangzelin007
approved these changes
Dec 10, 2021
| # fails with azure.core.exceptions.IncompleteReadError: | ||
| # https://github.com/Azure/azure-sdk-for-python/pull/20888 | ||
| if is_text_payload(response) and response['body']['string'] and 'content-length' in response['headers']: | ||
| response['headers']['content-length'][0] = str(len(response['body']['string'])) |
Member
There was a problem hiding this comment.
Why response['headers']['content-length'] is list while request.headers['Content-Length'] is str ?
Member
Author
There was a problem hiding this comment.
Very good question. Because request is a vcr.request.Request object while response is a dict. vcrpy defines different data structures for them, though I don't know why.
evelyn-ys
approved these changes
Dec 10, 2021
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
When the test framework replaces a random name, its length is not preserved:
This make
Content-Lengthheader in the response not match the actual body, causing failure due to the newazure-corecheck Azure/azure-sdk-for-python#20888.There are several processors that changes the
Content-Lengthof the body:AbstractPreparerorSingleValueReplacer, likeResourceGroupPreparerAADGraphUserReplacerGraphClientPasswordReplacerThis makes it difficult to enforce all processors to rectify the
Content-Lengthheader. The best place is to rectifyContent-Lengthheader when all processors are finished.See
Content-Lengthheader's value in recordings #20541Content-Lengthmatch the body #20533