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);
}
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)}");
}
}
});
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 =>