Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ public virtual void Sanitize(RecordEntry entry)

SanitizeHeaders(entry.Response.Headers);

SanitizeBody(entry.Response);
if (entry.RequestMethod != RequestMethod.Head)
{
SanitizeBody(entry.Response);
}
}

public virtual void Sanitize(RecordSession session)
Expand Down
33 changes: 33 additions & 0 deletions sdk/core/Azure.Core/tests/RecordSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,39 @@ public void RecordSessionLookupSkipsRequestBodyWhenFilterIsOn()
Assert.Throws<TestRecordingMismatchException>(() => playbackTransport.Process(message));
}

[Test]
[TestCase(true)]
[TestCase(false)]
public void ContentLengthUpdatedCorrectlyOnEmptyBody(bool isHeadRequest)
{
var sanitizer = new RecordedTestSanitizer();
var entry = new RecordEntry()
{
RequestUri = "http://localhost/",
RequestMethod = isHeadRequest ? RequestMethod.Head : RequestMethod.Get,
Response =
{
Headers =
{
{"Content-Length", new[] {"41"}},
{"Some-Header", new[] {"Random value"}},
{"Some-Other-Header", new[] {"V"}}
},
Body = new byte[0]
}
};
sanitizer.Sanitize(entry);

if (isHeadRequest)
{
Assert.AreEqual(new[] { "41" }, entry.Response.Headers["Content-Length"]);
}
else
{
Assert.AreEqual(new[] { "0" }, entry.Response.Headers["Content-Length"]);
}
}

private class TestSanitizer : RecordedTestSanitizer
{
public override string SanitizeVariable(string variableName, string environmentVariableValue)
Expand Down