merge headers and echo headers operations
authorEirik Tsarpalis <eirik.tsarpalis@gmail.com>
Fri, 26 Jul 2019 14:49:09 +0000 (15:49 +0100)
committerEirik Tsarpalis <eirik.tsarpalis@gmail.com>
Fri, 26 Jul 2019 14:49:09 +0000 (15:49 +0100)
Commit migrated from https://github.com/dotnet/corefx/commit/e22fbde5ebe4000d682bcb679a3a372050c2bc16

src/libraries/System.Net.Http/tests/StressTests/HttpStress/ClientOperations.cs
src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressServer.cs

index 20d2d73..36d7650 100644 (file)
@@ -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<string> values) => $"{string.Join(", ", values.Select(x => $"\"{x}\""))}";
+                                    string FmtValues(IEnumerable<string> values) => string.Join(", ", values.Select(x => $"\"{x}\""));
                                     throw new Exception($"Unexpected values for header {reqHeader.Key}. Expected {FmtValues(reqHeader.Value)} but got {FmtValues(values)}");
                                 }
                             }
index 7bee0e6..ff11529 100644 (file)
@@ -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<string, StringValues> 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 =>