@@ -21,7 +21,9 @@ public class ProxyTransport : HttpPipelineTransport
2121 private static readonly RemoteCertificateValidationCallback ServerCertificateCustomValidationCallback =
2222 ( _ , certificate , _ , _ ) => certificate . Issuer == TestProxy . DevCertIssuer ;
2323
24- public ProxyTransport ( TestProxy proxy , HttpPipelineTransport transport , TestRecording recording )
24+ private readonly Func < EntryRecordModel > _filter ;
25+
26+ public ProxyTransport ( TestProxy proxy , HttpPipelineTransport transport , TestRecording recording , Func < EntryRecordModel > filter )
2527 {
2628 if ( transport is HttpClientTransport )
2729 {
@@ -39,6 +41,7 @@ public ProxyTransport(TestProxy proxy, HttpPipelineTransport transport, TestReco
3941 }
4042 _recording = recording ;
4143 _proxy = proxy ;
44+ _filter = filter ;
4245 }
4346
4447 public override void Process ( HttpMessage message )
@@ -59,15 +62,15 @@ private async Task ProcessResponseAsync(HttpMessage message, bool async)
5962 {
6063 if ( message . Response . Headers . Contains ( "x-request-mismatch" ) )
6164 {
62- var streamreader = new StreamReader ( message . Response . ContentStream ) ;
65+ var streamReader = new StreamReader ( message . Response . ContentStream ) ;
6366 string response ;
6467 if ( async)
6568 {
66- response = await streamreader . ReadToEndAsync ( ) ;
69+ response = await streamReader . ReadToEndAsync ( ) ;
6770 }
6871 else
6972 {
70- response = streamreader . ReadToEnd ( ) ;
73+ response = streamReader . ReadToEnd ( ) ;
7174 }
7275 throw new TestRecordingMismatchException ( response ) ;
7376 }
@@ -106,6 +109,27 @@ public override Request CreateRequest()
106109 // copied from https://github.com/Azure/azure-sdk-for-net/blob/main/common/Perf/Azure.Test.Perf/TestProxyPolicy.cs
107110 private void RedirectToTestProxy ( HttpMessage message )
108111 {
112+ if ( _recording . Mode == RecordedTestMode . Record )
113+ {
114+ switch ( _filter ( ) )
115+ {
116+ case EntryRecordModel . Record :
117+ break ;
118+ case EntryRecordModel . RecordWithoutRequestBody :
119+ message . Request . Content = null ;
120+ break ;
121+ case EntryRecordModel . DoNotRecord :
122+ return ;
123+ }
124+ }
125+ else if ( _recording . Mode == RecordedTestMode . Playback )
126+ {
127+ if ( _filter ( ) == EntryRecordModel . RecordWithoutRequestBody )
128+ {
129+ message . Request . Content = null ;
130+ }
131+ }
132+
109133 var request = message . Request ;
110134 request . Headers . SetValue ( "x-recording-id" , _recording . RecordingId ) ;
111135 request . Headers . SetValue ( "x-recording-mode" , _recording . Mode . ToString ( ) . ToLower ( ) ) ;
0 commit comments