From: Eirik Tsarpalis Date: Fri, 26 Jul 2019 14:49:09 +0000 (+0100) Subject: merge headers and echo headers operations X-Git-Tag: submit/tizen/20210909.063632~11031^2~830^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36410dbf1ad370af728d4d8be140898648f83cff;p=platform%2Fupstream%2Fdotnet%2Fruntime.git merge headers and echo headers operations Commit migrated from https://github.com/dotnet/corefx/commit/e22fbde5ebe4000d682bcb679a3a372050c2bc16 --- diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/ClientOperations.cs b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/ClientOperations.cs index 20d2d73..36d7650 100644 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/ClientOperations.cs +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/ClientOperations.cs @@ -176,21 +176,8 @@ namespace HttpStress async ctx => { Version httpVersion = ctx.GetRandomHttpVersion(); - using (var req = new HttpRequestMessage(HttpMethod.Get, "/headers") { Version = httpVersion }) - using (HttpResponseMessage m = await ctx.SendAsync(req)) - { - ValidateHttpVersion(m, httpVersion); - ValidateStatusCode(m); - ValidateContent(ctx.ContentSource, await m.Content.ReadAsStringAsync()); - } - }), - - ("GET Echo Headers", - async ctx => - { - Version httpVersion = ctx.GetRandomHttpVersion(); - using (var req = new HttpRequestMessage(HttpMethod.Get, "/echoHeaders") { Version = httpVersion }) + using (var req = new HttpRequestMessage(HttpMethod.Get, "/headers") { Version = httpVersion }) { ctx.PopulateWithRandomHeaders(req.Headers); @@ -208,7 +195,7 @@ namespace HttpStress } else if (!reqHeader.Value.SequenceEqual(values)) { - string FmtValues(IEnumerable values) => $"{string.Join(", ", values.Select(x => $"\"{x}\""))}"; + string FmtValues(IEnumerable values) => string.Join(", ", values.Select(x => $"\"{x}\"")); throw new Exception($"Unexpected values for header {reqHeader.Key}. Expected {FmtValues(reqHeader.Value)} but got {FmtValues(values)}"); } } diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs index 7bee0e6..ff11529 100644 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs @@ -127,37 +127,29 @@ namespace HttpStress }); endpoints.MapGet("/headers", async context => { - // Get request but with a bunch of extra headers - for (int i = 0; i < 20; i++) + (string name, StringValues values)[] headersToEcho = + context.Request.Headers + // filter the pseudo-headers surfaced by Kestrel + .Where(h => !h.Key.StartsWith(':')) + // kestrel does not seem to be splitting comma separated header values, handle here + .Select(h => (h.Key, new StringValues(h.Value.SelectMany(v => v.Split(',')).Select(x => x.Trim()).ToArray()))) + .ToArray(); + + foreach((string name, StringValues values) in headersToEcho) { - context.Response.Headers.Add( - "CustomHeader" + i, - new StringValues(Enumerable.Range(0, i).Select(id => "value" + id).ToArray())); + context.Response.Headers.Add(name, values); } - await context.Response.WriteAsync(contentSource); + + await context.Response.WriteAsync("ok"); + if (context.Response.SupportsTrailers()) { - for (int i = 0; i < 10; i++) + // just add variations of already echoed headers as trailers + foreach ((string name, StringValues values) in headersToEcho) { - context.Response.AppendTrailer( - "CustomTrailer" + i, - new StringValues(Enumerable.Range(0, i).Select(id => "value" + id).ToArray())); + context.Response.AppendTrailer(name + "-Trailer", values); } } - }); - endpoints.MapGet("/echoHeaders", async context => - { - foreach(KeyValuePair header in context.Request.Headers) - { - // skip pseudo-headers surfaced by kestrel - if (header.Key.StartsWith(':')) continue; - - // kestrel seems to not be splitting comma separated header values, handle here - string[] values = header.Value.SelectMany(v => v.Split(',')).Select(x => x.Trim()).ToArray(); - context.Response.Headers.Add(header.Key, new StringValues(values)); - } - - await context.Response.WriteAsync("ok"); }); endpoints.MapGet("/variables", async context =>