Azure / Azure/azure-sdk-tools

500 returned from test proxy when content is an empty gzip payload

Open
#6,032 1 comment 1 reaction 1 assignee Claimed by @scbedd View on GitHub
Central-EngSys Test-Proxy
Dominant language
C#
Stars
135
Forks
260
Avg merge
3d 1h
Merged PRs (30d)
143

Description

A bug in a Java SDK where we were incorrectly sending a payload that was effectively a zero byte array which had been GZipped resulted in a 500 return from `record/stop`. This program reproduces it:

```csharp
using System.IO.Compression;
using System.Net.Http.Headers;

var ms = new MemoryStream();
var gz = new GZipStream(ms, CompressionMode.Compress);
byte[] zeroString = new byte[0];
gz.Write(zeroString, 0, zeroString.Length);
gz.Flush();
var client = new HttpClient();
client.Timeout = TimeSpan.FromMinutes(10);
var req = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5000/record/start");
req.Content = new StringContent("{\"x-recording-file\": \"record-file\"}");
var resp = client.Send(req);
resp.Headers.TryGetValues("x-recording-id", out var id);
var recordId = id.First();
req = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5000/Admin/AddSanitizer");
req.Content = new StringContent("{ \"value\":\"REDACTED\",\"jsonPath\":\"$..authHeader\"}", new MediaTypeHeaderValue("application/json"));
req.Headers.Add("x-abstraction-identifier", "BodyKeySanitizer");
req.Headers.Add("x-recording-id", recordId);
resp = client.Send(req);
req = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5000/");
req.Content = new ByteArrayContent(ms.ToArray());
req.Content.Headers.Add("Content-Encoding", "gzip");
req.Content.Headers.Add("Content-Type", "application/json");
req.Headers.Add("x-recording-upstream-base-uri", "http://example.com");
req.Headers.Add("x-recording-id", recordId);
req.Headers.Add("x-recording-mode", "record");

resp = client.Send(req);
req = new HttpRequestMessage(HttpMethod.Post, "http://localhost:5000/record/stop");
req.Headers.Add("x-recording-id", recordId);
req.Content = new StringContent("{}", new MediaTypeHeaderValue("application/json"));
resp = client.Send(req);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.