1 override of Response
Microsoft.AspNetCore.Http (1)
DefaultHttpContext.cs (1)
145public override HttpResponse Response => _response;
4008 references to Response
Aspire.Dashboard (15)
DashboardWebApplication.cs (4)
347context.Response.Redirect(TargetLocationInterceptor.StructuredLogsPath); 391if (context.Context.Response.Headers.CacheControl.Count == 0) 393context.Context.Response.Headers.CacheControl = "no-cache"; 427httpContext.Response.Redirect("/");
Model\BrowserSecurityHeadersMiddleware.cs (3)
69context.Response.Headers.ContentSecurityPolicy = context.Request.IsHttps 74context.Response.Headers["Referrer-Policy"] = "strict-origin-when-cross-origin"; 76context.Response.Headers.XContentTypeOptions = "nosniff";
Model\ValidateTokenMiddleware.cs (3)
59context.Response.Redirect($"{context.Request.Path}{newQuerystring}"); 73context.Response.Redirect(returnUrl.ToString()); 77context.Response.Redirect(DashboardUrls.ResourcesUrl());
Otlp\Http\OtlpHttpEndpointsBuilder.cs (5)
129context.Response.StatusCode = ex.StatusCode; 134context.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; 157httpContext.Response.ContentType = ProtobufContentType; 158await ms.CopyToAsync(httpContext.Response.Body).ConfigureAwait(false); 162httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType;
AutobahnTestApp (1)
Startup.cs (1)
33await context.Response.WriteAsync($"Ready to accept a WebSocket request at: {wsUrl}");
AzureAppServicesHostingStartupSample (25)
Startup.cs (25)
16context.Response.ContentType = "text/plain"; 17await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine); 18await context.Response.WriteAsync(Environment.NewLine); 20await context.Response.WriteAsync("Address:" + Environment.NewLine); 21await context.Response.WriteAsync("Scheme: " + context.Request.Scheme + Environment.NewLine); 22await context.Response.WriteAsync("Host: " + context.Request.Headers.Host + Environment.NewLine); 23await context.Response.WriteAsync("PathBase: " + context.Request.PathBase.Value + Environment.NewLine); 24await context.Response.WriteAsync("Path: " + context.Request.Path.Value + Environment.NewLine); 25await context.Response.WriteAsync("Query: " + context.Request.QueryString.Value + Environment.NewLine); 26await context.Response.WriteAsync(Environment.NewLine); 28await context.Response.WriteAsync("Connection:" + Environment.NewLine); 29await context.Response.WriteAsync("RemoteIp: " + context.Connection.RemoteIpAddress + Environment.NewLine); 30await context.Response.WriteAsync("RemotePort: " + context.Connection.RemotePort + Environment.NewLine); 31await context.Response.WriteAsync("LocalIp: " + context.Connection.LocalIpAddress + Environment.NewLine); 32await context.Response.WriteAsync("LocalPort: " + context.Connection.LocalPort + Environment.NewLine); 33await context.Response.WriteAsync("ClientCert: " + context.Connection.ClientCertificate + Environment.NewLine); 34await context.Response.WriteAsync(Environment.NewLine); 36await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine); 37await context.Response.WriteAsync(Environment.NewLine); 39await context.Response.WriteAsync("Headers:" + Environment.NewLine); 42await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine); 44await context.Response.WriteAsync(Environment.NewLine); 46await context.Response.WriteAsync("Environment Variables:" + Environment.NewLine); 51await context.Response.WriteAsync(key + ": " + value + Environment.NewLine); 53await context.Response.WriteAsync(Environment.NewLine);
AzureAppServicesSample (25)
Startup.cs (25)
27context.Response.ContentType = "text/plain"; 28await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine); 29await context.Response.WriteAsync(Environment.NewLine); 31await context.Response.WriteAsync("Address:" + Environment.NewLine); 32await context.Response.WriteAsync("Scheme: " + context.Request.Scheme + Environment.NewLine); 33await context.Response.WriteAsync("Host: " + context.Request.Headers.Host + Environment.NewLine); 34await context.Response.WriteAsync("PathBase: " + context.Request.PathBase.Value + Environment.NewLine); 35await context.Response.WriteAsync("Path: " + context.Request.Path.Value + Environment.NewLine); 36await context.Response.WriteAsync("Query: " + context.Request.QueryString.Value + Environment.NewLine); 37await context.Response.WriteAsync(Environment.NewLine); 39await context.Response.WriteAsync("Connection:" + Environment.NewLine); 40await context.Response.WriteAsync("RemoteIp: " + context.Connection.RemoteIpAddress + Environment.NewLine); 41await context.Response.WriteAsync("RemotePort: " + context.Connection.RemotePort + Environment.NewLine); 42await context.Response.WriteAsync("LocalIp: " + context.Connection.LocalIpAddress + Environment.NewLine); 43await context.Response.WriteAsync("LocalPort: " + context.Connection.LocalPort + Environment.NewLine); 44await context.Response.WriteAsync("ClientCert: " + context.Connection.ClientCertificate + Environment.NewLine); 45await context.Response.WriteAsync(Environment.NewLine); 47await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine); 48await context.Response.WriteAsync(Environment.NewLine); 50await context.Response.WriteAsync("Headers:" + Environment.NewLine); 53await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine); 55await context.Response.WriteAsync(Environment.NewLine); 57await context.Response.WriteAsync("Environment Variables:" + Environment.NewLine); 62await context.Response.WriteAsync(key + ": " + value + Environment.NewLine); 64await context.Response.WriteAsync(Environment.NewLine);
BasicLinkedApp (1)
Startup.cs (1)
28return context.Response.WriteAsync("Hello World");
BasicWebSite (9)
Controllers\ContentNegotiation\InvalidContentTypeController.cs (1)
13HttpContext.Response.ContentType = "json";
Controllers\TestingController.cs (2)
108context.HttpContext.Response.Redirect(_url); 109context.HttpContext.Response.StatusCode = (int)_statusCode;
Filters\ServiceActionFilter.cs (1)
24context.HttpContext.Response.Headers["X-ServiceActionFilter"] = "True";
Formatters\CustomFormatter.cs (1)
36var response = context.HttpContext.Response;
Formatters\PlainTextFormatter.cs (1)
34var response = context.HttpContext.Response;
Formatters\VCardFormatter_V3.cs (1)
39await context.HttpContext.Response.WriteAsync(
Formatters\VCardFormatter_V4.cs (1)
42await context.HttpContext.Response.WriteAsync(
StoreIntoTempDataActionResult.cs (1)
19return httpContext.Response.WriteAsync($"Hello from {nameof(StoreIntoTempDataActionResult)}");
Benchmarks (2)
StartupUsingEndpointRouting.cs (1)
29var response = httpContext.Response;
StartupUsingRouter.cs (1)
23var response = httpContext.Response;
Binding.Http.IntegrationTests (2)
MtomBindingTestHelper.cs (2)
58context.Response.Headers.ContentType = "multipart/related; type=\"application/xop+xml\";start=\"<http://tempuri.org/0>\";boundary=\"uuid:fca834ef-6b4a-43c0-a7d0-09064d2827e8+id=1\";start-info=\"text/xml\""; 59await context.Response.WriteAsync("--uuid:fca834ef-6b4a-43c0-a7d0-09064d2827e8+id=1\r\nContent-ID: <http://tempuri.org/0>\r\nContent-Transfer-Encoding: 8bit\r\nContent-Type: application/xop+xml;charset=utf-8;type=\"text/xml\"\r\n\r\n<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><UploadStreamResponse xmlns=\"http://tempuri.org/\"></UploadStreamResponse></s:Body></s:Envelope>");
blazor-devserver (5)
Server\Startup.cs (5)
40ctx.Response.Headers.Append("Blazor-Environment", webHostEnvironment.EnvironmentName); 99context.Response.StatusCode = 404; 100return context.Response.WriteAsync($"The server is configured only to " + 109httpContext.Response.Headers["Cross-Origin-Embedder-Policy"] = "require-corp"; 110httpContext.Response.Headers["Cross-Origin-Opener-Policy"] = "same-origin";
Certificate.Optional.Sample (2)
Startup.cs (2)
49return context.Response.WriteAsync($"Hello {context.User.Identity.Name} at {context.Request.Host}"); 54return context.Response.WriteAsync($"Hello {context.User.Identity.Name} at {context.Request.Host}. Try /auth");
Certificate.Sample (1)
Startup.cs (1)
54return context.Response.WriteAsync($"Hello {context.User.Identity.Name}");
ConcurrencyLimiterSample (1)
Startup.cs (1)
26await context.Response.WriteAsync("Hello World!");
CookiePolicySample (5)
Startup.cs (5)
51context.Response.Cookies.Append("Temp", "1"); 54context.Response.Cookies.Delete("Temp"); 57context.Response.Cookies.Append("EssentialCookie", "2", 61context.Response.Cookies.Delete("EssentialCookie"); 79var response = context.Response;
CookieSample (6)
Program.cs (6)
46context.Response.ContentType = "text/plain"; 47await context.Response.WriteAsync("Hello First timer"); 51context.Response.ContentType = "text/plain"; 52await context.Response.WriteAsync("Hello old timer"); 60await context.Response.WriteAsync($"Signed Out"); 66await context.Response.WriteAsync($"{key}: {value}\r\n");
CookieSessionSample (4)
Startup.cs (4)
45context.Response.ContentType = "text/plain"; 46await context.Response.WriteAsync("Hello First timer"); 50context.Response.ContentType = "text/plain"; 51await context.Response.WriteAsync("Hello old timer");
CorsMiddlewareWebSite (2)
EchoMiddleware.cs (2)
27context.Response.ContentType = "text/plain; charset=utf-8"; 29return context.Response.WriteAsync(path, Encoding.UTF8);
CreateDefaultBuilderApp (1)
Program.cs (1)
34return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName);
CreateDefaultBuilderOfTApp (1)
Program.cs (1)
45return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName);
CustomAuthorizationFailureResponse (5)
Authorization\SampleAuthorizationMiddlewareResultHandler.cs (5)
36await httpContext.Response.WriteAsync(policyAuthorizationResult.AuthorizationFailure.FailureReasons.First().Message); 45httpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; 46await httpContext.Response.WriteAsync(Startup.CustomForbiddenMessage); 58httpContext.Response.OnStarting(() => httpContext.Response.BodyWriter.WriteAsync(Encoding.UTF8.GetBytes(message)).AsTask());
DefaultBuilder.SampleApp (21)
Program.cs (3)
22using (WebHost.Start(context => context.Response.WriteAsync("Hello, World!"))) 33using (WebHost.Start("http://localhost:8080", context => context.Response.WriteAsync("Hello, World!"))) 65await context.Response.WriteAsync("Hello, World!");
Startup.cs (18)
19await context.Response.WriteAsync($"Hello from {context.Request.GetDisplayUrl()}\r\n"); 20await context.Response.WriteAsync("\r\n"); 22await context.Response.WriteAsync("Headers:\r\n"); 25await context.Response.WriteAsync($"{header.Key}: {header.Value}\r\n"); 27await context.Response.WriteAsync("\r\n"); 29await context.Response.WriteAsync("Connection:\r\n"); 30await context.Response.WriteAsync("RemoteIp: " + context.Connection.RemoteIpAddress + "\r\n"); 31await context.Response.WriteAsync("RemotePort: " + context.Connection.RemotePort + "\r\n"); 32await context.Response.WriteAsync("LocalIp: " + context.Connection.LocalIpAddress + "\r\n"); 33await context.Response.WriteAsync("LocalPort: " + context.Connection.LocalPort + "\r\n"); 34await context.Response.WriteAsync("ClientCert: " + context.Connection.ClientCertificate + "\r\n"); 35await context.Response.WriteAsync("\r\n"); 37await context.Response.WriteAsync("Environment Variables:\r\n"); 42await context.Response.WriteAsync($"{key}: {value}\r\n"); 44await context.Response.WriteAsync("\r\n"); 46await context.Response.WriteAsync("Config:\r\n"); 47await ShowConfig(context.Response, config); 48await context.Response.WriteAsync("\r\n");
DelegationSite (1)
Program.cs (1)
21return context.Response.WriteAsync("Hello from delegatee");
DependencyInjectionApp (2)
Program.cs (2)
31return context.Response.WriteAsync("Success"); 35return context.Response.WriteAsync(ex.ToString());
Diagnostics.EFCore.FunctionalTests (5)
DatabaseErrorPageMiddlewareTest.cs (3)
56context.Response.StatusCode = (int)HttpStatusCode.OK; 57await context.Response.WriteAsync("Request Handled"); 322await context.Response.WriteAsync("Saved a Blog");
MigrationsEndPointMiddlewareTest.cs (2)
53context.Response.StatusCode = (int)HttpStatusCode.OK; 54await context.Response.WriteAsync("Request Handled");
ExceptionHandlerSample (18)
Startup.cs (12)
19context.Response.StatusCode = 500; 20context.Response.ContentType = "text/html"; 21await context.Response.WriteAsync("<html><body>\r\n"); 22await context.Response.WriteAsync("We're sorry, we encountered an un-expected issue with your application.<br>\r\n"); 28await context.Response.WriteAsync("<br>Error: " + HtmlEncoder.Default.Encode(error.Error.Message) + "<br>\r\n"); 30await context.Response.WriteAsync("<br><a href=\"/\">Home</a><br>\r\n"); 31await context.Response.WriteAsync("</body></html>\r\n"); 32await context.Response.WriteAsync(new string(' ', 512)); // Padding for IE 50context.Response.ContentType = "text/html"; 51await context.Response.WriteAsync("<html><body>Welcome to the sample<br><br>\r\n"); 52await context.Response.WriteAsync("Click here to throw an exception: <a href=\"/throw\">throw</a>\r\n"); 53await context.Response.WriteAsync("</body></html>\r\n");
StartupWithProblemDetails.cs (5)
48context.Response.ContentType = "text/html"; 49await context.Response.WriteAsync("<html><body>Welcome to the sample<br><br>\r\n"); 50await context.Response.WriteAsync("Click here to throw an exception: <a href=\"/throw\">throw</a><br>\r\n"); 51await context.Response.WriteAsync("Click here to throw a conflict exception: <a href=\"/throw2/conflict\">throw conflict</a>\r\n"); 52await context.Response.WriteAsync("</body></html>\r\n");
StartupWithWebSocket.cs (1)
38await context.Response.WriteAsync($"Not a web socket request. PID: {Process.GetCurrentProcess().Id}");
FormatterWebSite (1)
Controllers\SystemTextJsonOutputFormatterController.cs (1)
26HttpContext.Response.Headers["Test"] = "t";
GenericHostWebSite (2)
Controllers\TestingController.cs (2)
94context.HttpContext.Response.Redirect(_url); 95context.HttpContext.Response.StatusCode = (int)_statusCode;
GenericWebHost (1)
Program.cs (1)
23await context.Response.WriteAsync("Hello World!");
HeaderPropagationSample (6)
Startup.cs (6)
67await context.Response.WriteAsync($"'/' Got Header '{header.Key}': {string.Join(", ", (string[])header.Value)}\r\n"); 73await context.Response.WriteAsync("Sending request to /forwarded\r\n"); 81await context.Response.WriteAsync($"Sent Header '{header.Key}': {string.Join(", ", header.Value)}\r\n"); 84await context.Response.WriteAsync("Got response\r\n"); 85await context.Response.WriteAsync(await response.Content.ReadAsStringAsync()); 93await context.Response.WriteAsync($"'/forwarded' Got Header '{header.Key}': {string.Join(", ", (string[])header.Value)}\r\n");
HealthChecksSample (20)
BasicStartup.cs (1)
29await context.Response.WriteAsync("Go to /health to see the health status");
CustomWriterStartup.cs (3)
37await context.Response.WriteAsync("Go to /health to see the health status"); 43httpContext.Response.ContentType = "application/json"; 52return httpContext.Response.WriteAsync(json.ToString(Formatting.Indented));
DbContextHealthStartup.cs (11)
50await context.Response.WriteAsync("Creating the database...\n"); 51await context.Response.Body.FlushAsync(); 56await context.Response.WriteAsync("Done\n"); 57await context.Response.WriteAsync("Go to /health to see the health status\n"); 62await context.Response.WriteAsync("Deleting the database...\n"); 63await context.Response.Body.FlushAsync(); 68await context.Response.WriteAsync("Done\n"); 69await context.Response.WriteAsync("Go to /health to see the health status\n"); 74await context.Response.WriteAsync("Go to /health to see the health status\n"); 75await context.Response.WriteAsync("Go to /createdatabase to create the database\n"); 76await context.Response.WriteAsync("Go to /deletedatabase to delete the database\n");
DBHealthStartup.cs (1)
38await context.Response.WriteAsync("Go to /health to see the health status");
LivenessProbeStartup.cs (3)
59await context.Response.WriteAsync("Go to /health/ready to see the readiness status"); 60await context.Response.WriteAsync(Environment.NewLine); 61await context.Response.WriteAsync("Go to /health/live to see the liveness status");
ManagementPortStartup.cs (1)
40await context.Response.WriteAsync($"Go to http://localhost:{Configuration["ManagementPort"]}/health to see the health status");
HostFilteringSample (1)
Startup.cs (1)
46return context.Response.WriteAsync("Hello World! " + context.Request.Host);
HotAddSample (22)
Startup.cs (22)
42context.Response.ContentType = "text/html"; 43await context.Response.WriteAsync("<html><body>"); 47await context.Response.WriteAsync("Added: <a href=\"" + toAdd + "\">" + toAdd + "</a>"); 51await context.Response.WriteAsync("Error adding: " + toAdd + "<br>"); 52await context.Response.WriteAsync(ex.ToString().Replace(Environment.NewLine, "<br>")); 54await context.Response.WriteAsync("<br><a href=\"" + context.Request.PathBase.ToUriComponent() + "\">back</a>"); 55await context.Response.WriteAsync("</body></html>"); 68context.Response.ContentType = "text/html"; 69await context.Response.WriteAsync("<html><body>"); 72await context.Response.WriteAsync("Removed: " + toRemove); 76await context.Response.WriteAsync("Not found: " + toRemove); 78await context.Response.WriteAsync("<br><a href=\"" + context.Request.PathBase.ToUriComponent() + "\">back</a>"); 79await context.Response.WriteAsync("</body></html>"); 87context.Response.ContentType = "text/html"; 88await context.Response.WriteAsync("<html><body>"); 89await context.Response.WriteAsync("Listening on these prefixes: <br>"); 92await context.Response.WriteAsync("<a href=\"" + prefix + "\">" + prefix + "</a> <a href=\"?remove=" + prefix + "\">(remove)</a><br>"); 95await context.Response.WriteAsync("<form action=\"" + context.Request.PathBase.ToUriComponent() + "\" method=\"GET\">"); 96await context.Response.WriteAsync("<input type=\"text\" name=\"add\" value=\"http://localhost:12348\" >"); 97await context.Response.WriteAsync("<input type=\"submit\" value=\"Add\">"); 98await context.Response.WriteAsync("</form>"); 100await context.Response.WriteAsync("</body></html>");
Http2SampleApp (4)
Startup.cs (1)
23return context.Response.WriteAsync("Hello World! " + context.Request.Protocol);
TimingMiddleware.cs (3)
23if (httpContext.Response.SupportsTrailers()) 25httpContext.Response.DeclareTrailer("Server-Timing"); 34httpContext.Response.AppendTrailer("Server-Timing", $"app;dur={stopWatch.ElapsedMilliseconds}.0");
Http3SampleApp (2)
Startup.cs (2)
24context.Response.Headers["test"] = "foo"; 26await context.Response.WriteAsync($"Hello World! {context.Request.Protocol} {context.Connection.ClientCertificate?.Subject}");
HttpLogging.Sample (3)
SampleHttpLoggingInterceptor.cs (1)
49foreach (var header in logContext.HttpContext.Response.Headers)
Startup.cs (2)
30context.Response.ContentType = "text/plain"; 31await context.Response.WriteAsync("Hello World!");
HttpOverridesSample (5)
Startup.cs (5)
23await context.Response.WriteAsync($"{header.Key}: {header.Value}\r\n"); 25await context.Response.WriteAsync($"Method: {context.Request.Method}\r\n"); 26await context.Response.WriteAsync($"Scheme: {context.Request.Scheme}\r\n"); 27await context.Response.WriteAsync($"RemoteIP: {context.Connection.RemoteIpAddress}\r\n"); 28await context.Response.WriteAsync($"RemotePort: {context.Connection.RemotePort}\r\n");
HttpsPolicySample (1)
Startup.cs (1)
38await context.Response.WriteAsync("Hello world!");
HttpStress (13)
Program.cs (13)
425await context.Response.WriteAsync(contentSource); 432await context.Response.WriteAsync(contentSource[i].ToString()); 433await context.Response.Body.FlushAsync(); 441context.Response.Headers.Add( 445await context.Response.WriteAsync(contentSource); 446if (context.Response.SupportsTrailers()) 450context.Response.AppendTrailer( 459await context.Response.WriteAsync(contentSource.Substring(0, contentSource.Length / 2)); 465var writeTask = context.Response.WriteAsync(contentSource.Substring(0, contentSource.Length)); 476await s.CopyToAsync(context.Response.Body); 481await context.Request.Body.CopyToAsync(context.Response.Body); 489await context.Response.Body.WriteAsync(buffer); 495context.Response.Headers.ContentLength = maxContentLength;
IIS.Microbenchmarks (1)
PlaintextBenchmark.cs (1)
58return WriteResponse(httpContext.Response);
IIS.Tests (10)
ClientDisconnectTests.cs (3)
38await ctx.Response.Body.WriteAsync(data); 74await ctx.Response.Body.WriteAsync(data, ctx.RequestAborted); 157await ctx.Response.Body.WriteAsync(data, cancellationTokenSource.Token);
HttpBodyControlFeatureTests.cs (1)
30ctx.Response.Body.Write(new byte[10]);
ResponseAbortTests.cs (3)
44await ctx.Response.WriteAsync("Abort"); 45await ctx.Response.Body.FlushAsync(); 107await ctx.Response.Body.WriteAsync(new byte[10]);
ResponseBodySizeTests.cs (1)
23await ctx.Response.Body.WriteAsync(buffer, 0, buffer.Length);
TestServerTest.cs (1)
27return ctx.Response.WriteAsync(helloWorld);
Utilities\TestServer.cs (1)
154app.Map("/start", builder => builder.Run(context => context.Response.WriteAsync("Done")));
IISSample (28)
Startup.cs (28)
41context.Response.ContentType = "text/plain"; 42await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine); 43await context.Response.WriteAsync(Environment.NewLine); 45await context.Response.WriteAsync("Address:" + Environment.NewLine); 46await context.Response.WriteAsync("Scheme: " + context.Request.Scheme + Environment.NewLine); 47await context.Response.WriteAsync("Host: " + context.Request.Headers["Host"] + Environment.NewLine); 48await context.Response.WriteAsync("PathBase: " + context.Request.PathBase.Value + Environment.NewLine); 49await context.Response.WriteAsync("Path: " + context.Request.Path.Value + Environment.NewLine); 50await context.Response.WriteAsync("Query: " + context.Request.QueryString.Value + Environment.NewLine); 51await context.Response.WriteAsync(Environment.NewLine); 53await context.Response.WriteAsync("Connection:" + Environment.NewLine); 54await context.Response.WriteAsync("RemoteIp: " + context.Connection.RemoteIpAddress + Environment.NewLine); 55await context.Response.WriteAsync("RemotePort: " + context.Connection.RemotePort + Environment.NewLine); 56await context.Response.WriteAsync("LocalIp: " + context.Connection.LocalIpAddress + Environment.NewLine); 57await context.Response.WriteAsync("LocalPort: " + context.Connection.LocalPort + Environment.NewLine); 58await context.Response.WriteAsync("ClientCert: " + context.Connection.ClientCertificate + Environment.NewLine); 59await context.Response.WriteAsync(Environment.NewLine); 61await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine); 63await context.Response.WriteAsync("DisplayName: " + scheme?.DisplayName + Environment.NewLine); 64await context.Response.WriteAsync(Environment.NewLine); 66await context.Response.WriteAsync("Headers:" + Environment.NewLine); 69await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine); 71await context.Response.WriteAsync(Environment.NewLine); 73await context.Response.WriteAsync("Environment Variables:" + Environment.NewLine); 78await context.Response.WriteAsync(key + ": " + value + Environment.NewLine); 81await context.Response.WriteAsync(Environment.NewLine); 84await context.Response.WriteAsync("Websocket feature is enabled."); 88await context.Response.WriteAsync("Websocket feature is disabled.");
InMemory.FunctionalTests (861)
ChunkedRequestTests.cs (12)
24var response = httpContext.Response; 41var response = httpContext.Response; 60var response = httpContext.Response; 176var response = httpContext.Response; 232var response = httpContext.Response; 360var response = httpContext.Response; 582var response = httpContext.Response; 663var response = httpContext.Response; 707var response = httpContext.Response; 913var response = httpContext.Response; 969var response = httpContext.Response; 1082var response = httpContext.Response;
ChunkedResponseTests.cs (39)
26var response = httpContext.Response; 61await httpContext.Response.WriteAsync("Hello "); 62await httpContext.Response.WriteAsync("World!"); 90var response = httpContext.Response; 125await httpContext.Response.WriteAsync("Hello "); 126await httpContext.Response.WriteAsync("World!"); 161await httpContext.Response.WriteAsync(expectedString); 201await httpContext.Response.StartAsync(); 202var memory = httpContext.Response.BodyWriter.GetMemory(length); 205httpContext.Response.BodyWriter.Advance(length); 206await httpContext.Response.BodyWriter.FlushAsync(); 243await httpContext.Response.StartAsync(); 244var memory = httpContext.Response.BodyWriter.GetMemory(100000); 246httpContext.Response.BodyWriter.Advance(partialLength); 247await httpContext.Response.BodyWriter.FlushAsync(); 280httpContext.Response.Headers["Connection"] = "close"; 281await httpContext.Response.WriteAsync("Hello "); 282await httpContext.Response.WriteAsync("World!"); 316var response = httpContext.Response; 354var response = httpContext.Response; 396var response = httpContext.Response; 426var response = httpContext.Response; 459var response = httpContext.Response; 493var response = httpContext.Response; 537var response = httpContext.Response; 575var response = httpContext.Response; 619var response = httpContext.Response; 664var response = httpContext.Response; 718var response = httpContext.Response; 774var response = httpContext.Response; 829var response = httpContext.Response; 871var response = httpContext.Response; 918var response = httpContext.Response; 959var response = httpContext.Response; 999var response = httpContext.Response; 1038var response = httpContext.Response; 1075var response = httpContext.Response; 1113var response = httpContext.Response; 1148var response = httpContext.Response;
ConnectionLimitTests.cs (2)
38await context.Response.WriteAsync("Hello"); 114await context.Response.WriteAsync("Hello");
ConnectionMiddlewareTests.cs (6)
278await context.Response.WriteAsync("Hello "); 279await context.Response.Body.FlushAsync(); 280await context.Response.WriteAsync("World!"); 309await context.Response.BodyWriter.WriteAsync(Encoding.ASCII.GetBytes("Hello ")); 310await context.Response.BodyWriter.FlushAsync(); 311await context.Response.BodyWriter.WriteAsync(Encoding.ASCII.GetBytes("World!"));
Http2\Http2ConnectionTests.cs (47)
61return c.Response.Body.WriteAsync(new byte[1]).AsTask(); 93await c.Response.Body.FlushAsync(); 96await c.Response.Body.WriteAsync(new byte[65540]); 572await context.Response.WriteAsync("Content"); 1181await context.Response.Body.WriteAsync(data, 0, read); 1386await context.Response.BodyWriter.FlushAsync(); 1399await context.Response.BodyWriter.WriteAsync(readResult.Buffer.ToArray()); 1913await context.Response.Body.WriteAsync(_maxData, 0, _maxData.Length); 1986await context.Response.WriteAsync(new string('!', 65536)); 2069await context.Response.Body.WriteAsync(data); 2369c.Response.ContentLength = 0; 2370c.Response.Headers.SetCookie = "SetCookie!"; 2371c.Response.Headers.ContentDisposition = "ContentDisposition!"; 3213await context.Response.Body.FlushAsync(); 3217await context.Response.Body.WriteAsync(_maxData, 0, _maxData.Length); 3220await context.Response.Body.WriteAsync(_maxData, 0, remainingBytesBeforeBackpressure + 1); 3331await context.Response.Body.WriteAsync(_helloWorldBytes, 0, _helloWorldBytes.Length); 3890context.Response.Headers["A"] = new string('a', headerValueLength); 3891context.Response.Headers["B"] = new string('b', headerValueLength); 3892return context.Response.Body.WriteAsync(new byte[payloadLength], 0, payloadLength); 3943return context.Response.Body.WriteAsync(new byte[clientMaxFrame], 0, clientMaxFrame); 4236await context.Response.Body.FlushAsync(); 4240await context.Response.Body.WriteAsync(_maxData, 0, _maxData.Length); 4243await context.Response.Body.WriteAsync(_maxData, 0, remainingBytesBeforeBackpressure + 1); 4338await context.Response.Body.WriteAsync(_helloWorldBytes, 0, _helloWorldBytes.Length); 4584await context.Response.Body.FlushAsync(); 4589await context.Response.Body.WriteAsync(_maxData, 0, _maxData.Length); 4593var lastWriteTask = context.Response.Body.WriteAsync(_maxData, 0, _maxData.Length); 4764await context.Response.Body.WriteAsync(new byte[windowSize - 1], 0, windowSize - 1); 4766await context.Response.Body.WriteAsync(new byte[windowSize], 0, windowSize); 5902var memory = c.Response.BodyWriter.GetMemory(); 5903c.Response.BodyWriter.Advance(memory.Length); 5905Assert.Equal(length, c.Response.BodyWriter.UnflushedBytes); 5907memory = c.Response.BodyWriter.GetMemory(); 5908c.Response.BodyWriter.Advance(memory.Length); 5911Assert.Equal(length, c.Response.BodyWriter.UnflushedBytes); 5913await c.Response.BodyWriter.FlushAsync(); 5915Assert.Equal(0, c.Response.BodyWriter.UnflushedBytes); 5955await c.Response.StartAsync(); 5958var memory = c.Response.BodyWriter.GetMemory(); 5959c.Response.BodyWriter.Advance(memory.Length); 5961Assert.Equal(length, c.Response.BodyWriter.UnflushedBytes); 5963memory = c.Response.BodyWriter.GetMemory(); 5964c.Response.BodyWriter.Advance(memory.Length); 5967Assert.Equal(length, c.Response.BodyWriter.UnflushedBytes); 5969await c.Response.BodyWriter.FlushAsync(); 5971Assert.Equal(0, c.Response.BodyWriter.UnflushedBytes);
Http2\Http2EndToEndTests.cs (1)
38await context.Response.WriteAsync("hello, world");
Http2\Http2StreamTests.cs (222)
189return context.Request.BodyReader.CopyToAsync(context.Response.BodyWriter); 240return context.Request.BodyReader.CopyToAsync(context.Response.BodyWriter); 360context.Response.Headers["path"] = context.Request.Path.Value; 361context.Response.Headers["query"] = context.Request.QueryString.Value; 362context.Response.Headers["rawtarget"] = context.Features.Get<IHttpRequestFeature>().RawTarget; 1335context.Response.ContentLength = 11; 1336await context.Response.WriteAsync("hello, world"); // 12 1373context.Response.ContentLength = 11; 1374await context.Response.WriteAsync("hello,"); 1375await context.Response.WriteAsync(" world"); 1412context.Response.ContentLength = 11; 1446await context.Response.StartAsync(); 1480context.Response.ContentLength = 0; 1481await context.Response.StartAsync(); 1518await context.Response.StartAsync(); 1519ex = Assert.Throws<InvalidOperationException>(() => context.Response.OnStarting(_ => Task.CompletedTask, null)); 1555await context.Response.StartAsync(); 1556Assert.True(context.Response.HasStarted); 1592await context.Response.StartAsync(); 1596await context.Response.WriteAsync("hello, world"); 1640await context.Response.StartAsync(); 1643await context.Response.Body.FlushAsync(); 1678context.Response.ContentLength = 0; 1679await context.Response.StartAsync(); 1680await context.Response.WriteAsync(""); 1715await context.Response.StartAsync(); 1716await context.Response.WriteAsync("hello, world"); 1758context.Response.ContentLength = 11; 1759await context.Response.StartAsync(); 1793await context.Response.StartAsync(); 1826context.Response.ContentLength = 11; 1827return context.Response.WriteAsync("hello,"); 2144Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("Custom你好Name", "Custom Value")); 2145Assert.Throws<InvalidOperationException>(() => context.Response.ContentType = "Custom 你好 Type"); 2146Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom 你好 Value")); 2147Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom \r Value")); 2148await context.Response.WriteAsync("Hello World"); 2185Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("Custom你好Name", "Custom Value")); 2186Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom \r Value")); 2187context.Response.ContentType = "Custom 你好 Type"; 2188context.Response.Headers.Append("CustomName", "Custom 你好 Value"); 2189await context.Response.WriteAsync("Hello World"); 2229context.Response.Headers.Append("CustomName", "Custom 你好 Value"); 2230await context.Response.WriteAsync("Hello World"); 2244context.Response.AppendTrailer("CustomName", "Custom Value"); 2282context.Response.AppendTrailer("CustomName", "Custom Value"); 2308Assert.True(context.Response.SupportsTrailers(), "SupportsTrailers"); 2313context.Response.AppendTrailer("CustomName", "Custom Value"); 2360await context.Response.WriteAsync("Hello World"); 2361context.Response.AppendTrailer("CustomName", "Custom Value"); 2403await context.Response.WriteAsync("Hello World"); 2405context.Response.AppendTrailer("CustomName0", largeHeader); 2406context.Response.AppendTrailer("CustomName1", largeHeader); 2407context.Response.AppendTrailer("CustomName2", largeHeader); 2408context.Response.AppendTrailer("CustomName3", largeHeader); 2409context.Response.AppendTrailer("CustomName4", largeHeader); 2411context.Response.AppendTrailer("CustomName5", largeHeader); 2468await context.Response.WriteAsync("Hello World"); 2469Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("Custom你好Name", "Custom Value")); 2470Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("CustomName", "Custom 你好 Value")); 2471Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("CustomName", "Custom \r Value")); 2511await context.Response.WriteAsync("Hello World"); 2512Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("Custom你好Name", "Custom Value")); 2513Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("CustomName", "Custom \r Value")); 2514context.Response.AppendTrailer("CustomName", "Custom 你好 Value"); 2564await context.Response.WriteAsync("Hello World"); 2565context.Response.AppendTrailer("CustomName", "Custom 你好 Value"); 2596await context.Response.WriteAsync("Hello World"); 2597context.Response.AppendTrailer("too_long", trailerValue); 2638await context.Response.WriteAsync("Hello World"); 2639context.Response.AppendTrailer("a-key", "a-value"); 2640context.Response.AppendTrailer("b-key", "b-value"); 2641context.Response.AppendTrailer("too_long", trailerValue); 2731await context.Response.WriteAsync("Hello World"); 2732context.Response.AppendTrailer("too_long", trailerValue); 2733context.Response.AppendTrailer("too_long2", trailerValue); 2791await context.Response.WriteAsync("Hello World"); 2792context.Response.AppendTrailer("short", shortValue); 2793context.Response.AppendTrailer("long", trailerValue); 2794context.Response.AppendTrailer("short2", shortValue); 2845context.Response.Headers["too_long_header"] = value; 2846await context.Response.WriteAsync("Hello World"); 2847context.Response.AppendTrailer("too_long_trailer", value); 2983await context.Response.StartAsync(); 2987context.Response.BodyWriter.GetMemory(windowSize + 1); 2988context.Response.BodyWriter.Advance(windowSize + 1); 2990context.Response.AppendTrailer("CustomName", "Custom Value"); 3049await context.Response.StartAsync(); 3051var s = context.Response.BodyWriter.GetMemory(1); 3053context.Response.BodyWriter.Advance(1); 3055context.Response.AppendTrailer("CustomName", "Custom Value"); 3134await context.Response.WriteAsync("hello,"); 3193await context.Response.Body.WriteAsync(new byte[10], 0, 10); 3226context.Response.BodyWriter.GetMemory(); 3227context.Response.BodyWriter.Advance(10); 3228await context.Response.BodyWriter.FlushAsync(); 3259await context.Response.Body.WriteAsync(new byte[10], 0, 10); 3302await context.Response.Body.WriteAsync(new byte[10], 0, 10); 3349await context.Response.Body.WriteAsync(new byte[10], 0, 10); 3386await context.Response.Body.WriteAsync(new byte[10], 0, 10); 3391await context.Response.Body.WriteAsync(new byte[11], 0, 11); 3488await context.Response.Body.WriteAsync(new byte[windowSize + 1], 0, windowSize + 1); 3489context.Response.Body.Write(new byte[1], 0, 1); 3529context.Response.Headers.ETag = new string('a', (int)Http2PeerSettings.DefaultMaxFrameSize); 3530await context.Response.WriteAsync("Hello World"); 3565context.Response.Headers.ETag = new string('a', (int)Http2PeerSettings.DefaultMaxFrameSize); 3566context.Response.Headers.TE = new string('a', 30); 3567await context.Response.WriteAsync("Hello World"); 3603context.Response.Headers.ETag = new string('a', (int)Http2PeerSettings.DefaultMaxFrameSize); 3604context.Response.Headers.TE = new string('b', (int)Http2PeerSettings.DefaultMaxFrameSize); 3605await context.Response.WriteAsync("Hello World"); 3654context.Response.Headers.ETag = new string('a', 17002); 3655await context.Response.WriteAsync("Hello World"); 3683context.Response.Headers.ETag = new string('a', (int)Http2PeerSettings.DefaultMaxFrameSize - 20); 3684await context.Response.WriteAsync("Hello World"); 3716context.Response.Headers[longHeaderName] = headerValue; 3717await context.Response.WriteAsync("Hello World"); 3755context.Response.Headers["my"] = headerValue; 3756await context.Response.WriteAsync("Hello World"); 3796await Assert.ThrowsAsync<OperationCanceledException>(() => context.Response.WriteAsync("hello,", new CancellationToken(true))); 3797Assert.False(context.Response.HasStarted); 3830await context.Response.Body.FlushAsync(); // https://github.com/aspnet/KestrelHttpServer/issues/3031 3831var writeTask = context.Response.WriteAsync("hello,", cts.Token); 3876var response = httpContext.Response; 3922var response = httpContext.Response; 3968var response = httpContext.Response; 4020var response = httpContext.Response; 4073var response = httpContext.Response; 4119var response = httpContext.Response; 4169var response = httpContext.Response; 4214var response = httpContext.Response; 4256var response = httpContext.Response; 4300var result = await httpContext.Response.BodyWriter.WriteAsync(payload); 4331httpContext.Response.BodyWriter.CancelPendingFlush(); 4333var cancelledResult = await httpContext.Response.BodyWriter.WriteAsync(payload); 4337var goodResult = await httpContext.Response.BodyWriter.WriteAsync(secondPayload); 4373var response = httpContext.Response; 4437var response = httpContext.Response; 4488var response = httpContext.Response; 4534httpContext.Response.ContentLength = 12; 4535await httpContext.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("hello, world")); 4574var response = httpContext.Response; 4638context.Response.BodyWriter.Complete(); 4670context.Response.BodyWriter.Complete(); 4671writeEx = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.WriteAsync("")); 4704context.Response.BodyWriter.Complete(expectedException); 4743context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 4744await context.Response.CompleteAsync().DefaultTimeout(); 4747Assert.True(context.Response.Headers.IsReadOnly); 4796context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 4797context.Response.AppendTrailer("CustomName", "Custom Value"); 4799await context.Response.CompleteAsync().DefaultTimeout(); 4800await context.Response.CompleteAsync().DefaultTimeout(); // Can be called twice, no-ops 4803Assert.True(context.Response.Headers.IsReadOnly); 4862context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 4864context.Response.ContentLength = 25; 4865context.Response.AppendTrailer("CustomName", "Custom Value"); 4867var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.CompleteAsync().DefaultTimeout()); 4871Assert.False(context.Response.Headers.IsReadOnly); 4917context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 4919await context.Response.WriteAsync("Hello World"); 4921Assert.True(context.Response.Headers.IsReadOnly); 4923await context.Response.CompleteAsync().DefaultTimeout(); 4924await context.Response.CompleteAsync().DefaultTimeout(); // Can be called twice, no-ops 4983context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 4984await context.Response.CompleteAsync().DefaultTimeout(); 4987Assert.True(context.Response.Headers.IsReadOnly); 4990var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.WriteAsync("2 Hello World").DefaultTimeout()); 5039context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5041await context.Response.WriteAsync("Hello World").DefaultTimeout(); 5043Assert.True(context.Response.Headers.IsReadOnly); 5045await context.Response.CompleteAsync().DefaultTimeout(); 5049var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.WriteAsync("2 Hello World").DefaultTimeout()); 5103var memory = context.Response.BodyWriter.GetMemory(12); 5104await context.Response.CompleteAsync(); 5107context.Response.BodyWriter.Advance(memory.Length); 5153context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5155var buffer = context.Response.BodyWriter.GetMemory(); 5157context.Response.BodyWriter.Advance(length); 5160Assert.False(context.Response.Headers.IsReadOnly); 5162context.Response.AppendTrailer("CustomName", "Custom Value"); 5164await context.Response.CompleteAsync().DefaultTimeout(); 5166Assert.True(context.Response.Headers.IsReadOnly); 5232context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5234await context.Response.WriteAsync("Hello World"); 5236Assert.True(context.Response.Headers.IsReadOnly); 5238context.Response.AppendTrailer("CustomName", "Custom Value"); 5240await context.Response.CompleteAsync().DefaultTimeout(); 5306context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5308context.Response.ContentLength = 25; 5309await context.Response.WriteAsync("Hello World"); 5311Assert.True(context.Response.Headers.IsReadOnly); 5313context.Response.AppendTrailer("CustomName", "Custom Value"); 5315var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.CompleteAsync().DefaultTimeout()); 5377context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5379context.Response.ContentLength = 25; 5380await context.Response.WriteAsync("Hello World"); 5382Assert.True(context.Response.Headers.IsReadOnly); 5384context.Response.AppendTrailer("CustomName", "Custom Value"); 5386var ex = Assert.Throws<InvalidOperationException>(() => context.Response.BodyWriter.Complete()); 5447context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5449await context.Response.WriteAsync("Hello World"); 5451Assert.True(context.Response.Headers.IsReadOnly); 5453context.Response.AppendTrailer("CustomName", "Custom Value"); 5455await context.Response.CompleteAsync().DefaultTimeout(); 5529context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5531await context.Response.WriteAsync("Hello World"); 5533Assert.True(context.Response.Headers.IsReadOnly); 5535context.Response.AppendTrailer("CustomName", "Custom Value"); 5537await context.Response.CompleteAsync().DefaultTimeout(); 5611context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5613await context.Response.WriteAsync("Hello World"); 5615Assert.True(context.Response.Headers.IsReadOnly); 5617context.Response.AppendTrailer("CustomName", "Custom Value"); 5619await context.Response.CompleteAsync().DefaultTimeout(); 5695context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 5697await context.Response.WriteAsync("Hello World"); 5699Assert.True(context.Response.Headers.IsReadOnly); 5701context.Response.AppendTrailer("CustomName", "Custom Value"); 5703await context.Response.CompleteAsync().DefaultTimeout(); 5843var response = context.Response; 5895var response = httpContext.Response;
Http2\Http2TestBase.cs (10)
246await context.Response.Body.WriteAsync(data.ToArray(), 0, data.Count); 256await context.Response.Body.WriteAsync(buffer, 0, received); 267await context.Response.Body.WriteAsync(buffer, 0, received); 284context.Response.Headers[name] = _4kHeaderValue; 327await context.Response.Body.FlushAsync(); 347await context.Response.Body.WriteAsync(new byte[1], 0, 1); 356context.Response.Headers["Method"] = context.Request.Method; 364context.Response.Headers.Host = context.Request.Headers.Host; 372context.Response.Headers["path"] = context.Request.Path.ToString(); 373context.Response.Headers["rawtarget"] = context.Features.Get<IHttpRequestFeature>().RawTarget;
Http2\Http2TimeoutTests.cs (1)
339var writeTask = context.Response.Body.WriteAsync(buffer, 0, received);
Http2\Http2WebSocketTests.cs (10)
175context.Response.StatusCode = StatusCodes.Status201Created; // Any 2XX should work 456var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.Body.WriteAsync(new byte[1] { 0x00 }).AsTask()); 458ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.BodyWriter.WriteAsync(new byte[1] { 0x00 }).AsTask()); 465ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.Body.WriteAsync(new byte[1] { 0x00 }).AsTask()); 467ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.BodyWriter.WriteAsync(new byte[1] { 0x00 }).AsTask()); 531context.Response.StatusCode = Http.StatusCodes.Status418ImATeapot; 532context.Response.ContentLength = 2; 533await context.Response.Body.WriteAsync(new byte[1] { 0x01 }); 534await context.Response.BodyWriter.WriteAsync(new byte[1] { 0x02 }); 603context.Response.StatusCode = StatusCodes.Status201Created; // Any 2XX should work
Http2\TlsTests.cs (1)
47return context.Response.WriteAsync("hello world " + context.Request.Protocol);
Http3\Http3ConnectionTests.cs (20)
46await context.Response.Body.WriteAsync(buffer, 0, received); 86await context.Response.Body.WriteAsync(buffer, 0, received); 149await context.Response.Body.WriteAsync(buffer, 0, received); 607var memory = c.Response.BodyWriter.GetMemory(); 608c.Response.BodyWriter.Advance(memory.Length); 610Assert.Equal(length, c.Response.BodyWriter.UnflushedBytes); 612memory = c.Response.BodyWriter.GetMemory(); 613c.Response.BodyWriter.Advance(memory.Length); 616Assert.Equal(length, c.Response.BodyWriter.UnflushedBytes); 618await c.Response.BodyWriter.FlushAsync(); 620Assert.Equal(0, c.Response.BodyWriter.UnflushedBytes); 658await c.Response.StartAsync(); 661var memory = c.Response.BodyWriter.GetMemory(); 662c.Response.BodyWriter.Advance(memory.Length); 664Assert.Equal(length, c.Response.BodyWriter.UnflushedBytes); 666memory = c.Response.BodyWriter.GetMemory(); 667c.Response.BodyWriter.Advance(memory.Length); 670Assert.Equal(length, c.Response.BodyWriter.UnflushedBytes); 672await c.Response.BodyWriter.FlushAsync(); 674Assert.Equal(0, c.Response.BodyWriter.UnflushedBytes);
Http3\Http3StreamTests.cs (116)
56context.Response.StatusCode = 401; 208context.Response.Headers["path"] = context.Request.Path.Value; 209context.Response.Headers["query"] = context.Request.QueryString.Value; 210context.Response.Headers["rawtarget"] = context.Features.Get<IHttpRequestFeature>().RawTarget; 658var response = context.Response; 722await context.Response.BodyWriter.FlushAsync(); 729await context.Response.BodyWriter.WriteAsync(new byte[] { data[i] }); 768var result = await context.Response.BodyWriter.WriteAsync(payload); 797context.Response.BodyWriter.CancelPendingFlush(); 799var cancelledResult = await context.Response.BodyWriter.WriteAsync(payload); 803var goodResult = await context.Response.BodyWriter.WriteAsync(secondPayload); 862Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("Custom你好Name", "Custom Value")); 863Assert.Throws<InvalidOperationException>(() => context.Response.ContentType = "Custom 你好 Type"); 864Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom 你好 Value")); 865Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom \r Value")); 866await context.Response.WriteAsync("Hello World"); 896Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("Custom你好Name", "Custom Value")); 897Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom \r Value")); 898context.Response.ContentType = "Custom 你好 Type"; 899context.Response.Headers.Append("CustomName", "Custom 你好 Value"); 900await context.Response.WriteAsync("Hello World"); 931context.Response.Headers.Append("CustomName", "Custom 你好 Value"); 932await context.Response.WriteAsync("Hello World"); 959await context.Response.WriteAsync("Hello world"); 1012await context.Response.WriteAsync("Hello World"); 1013Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("Custom你好Name", "Custom Value")); 1014Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("CustomName", "Custom 你好 Value")); 1015Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("CustomName", "Custom \r Value")); 1043await context.Response.WriteAsync("Hello World"); 1044Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("Custom你好Name", "Custom Value")); 1045Assert.Throws<InvalidOperationException>(() => context.Response.AppendTrailer("CustomName", "Custom \r Value")); 1046context.Response.AppendTrailer("CustomName", "Custom 你好 Value"); 1082await context.Response.WriteAsync("Hello World"); 1083context.Response.AppendTrailer("CustomName", "Custom 你好 Value"); 1139context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1140await context.Response.CompleteAsync().DefaultTimeout(); 1143Assert.True(context.Response.Headers.IsReadOnly); 1185context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1186context.Response.AppendTrailer("CustomName", "Custom Value"); 1188await context.Response.CompleteAsync().DefaultTimeout(); 1189await context.Response.CompleteAsync().DefaultTimeout(); // Can be called twice, no-ops 1192Assert.True(context.Response.Headers.IsReadOnly); 1237context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1239context.Response.ContentLength = 25; 1240context.Response.AppendTrailer("CustomName", "Custom Value"); 1242var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.CompleteAsync().DefaultTimeout()); 1246Assert.False(context.Response.Headers.IsReadOnly); 1285context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1287await context.Response.WriteAsync("Hello World"); 1289Assert.True(context.Response.Headers.IsReadOnly); 1291await context.Response.CompleteAsync().DefaultTimeout(); 1292await context.Response.CompleteAsync().DefaultTimeout(); // Can be called twice, no-ops 1338context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1339await context.Response.CompleteAsync().DefaultTimeout(); 1342Assert.True(context.Response.Headers.IsReadOnly); 1345var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.WriteAsync("2 Hello World").DefaultTimeout()); 1387context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1389await context.Response.WriteAsync("Hello World").DefaultTimeout(); 1391Assert.True(context.Response.Headers.IsReadOnly); 1393await context.Response.CompleteAsync().DefaultTimeout(); 1397var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.WriteAsync("2 Hello World").DefaultTimeout()); 1437var memory = context.Response.BodyWriter.GetMemory(12); 1438await context.Response.CompleteAsync(); 1441context.Response.BodyWriter.Advance(memory.Length); 1480context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1482var buffer = context.Response.BodyWriter.GetMemory(); 1484context.Response.BodyWriter.Advance(length); 1487Assert.False(context.Response.Headers.IsReadOnly); 1489context.Response.AppendTrailer("CustomName", "Custom Value"); 1491await context.Response.CompleteAsync().DefaultTimeout(); 1493Assert.True(context.Response.Headers.IsReadOnly); 1540context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1542await context.Response.WriteAsync("Hello World"); 1544Assert.True(context.Response.Headers.IsReadOnly); 1546context.Response.AppendTrailer("CustomName", "Custom Value"); 1548await context.Response.CompleteAsync().DefaultTimeout(); 1595context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1597context.Response.ContentLength = 25; 1598await context.Response.WriteAsync("Hello World"); 1600Assert.True(context.Response.Headers.IsReadOnly); 1602context.Response.AppendTrailer("CustomName", "Custom Value"); 1604var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.CompleteAsync().DefaultTimeout()); 1653context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1655context.Response.ContentLength = 25; 1656await context.Response.WriteAsync("Hello World"); 1658Assert.True(context.Response.Headers.IsReadOnly); 1660context.Response.AppendTrailer("CustomName", "Custom Value"); 1662var ex = Assert.Throws<InvalidOperationException>(() => context.Response.BodyWriter.Complete()); 1710context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1712await context.Response.WriteAsync("Hello World"); 1714Assert.True(context.Response.Headers.IsReadOnly); 1716context.Response.AppendTrailer("CustomName", "Custom Value"); 1718await context.Response.CompleteAsync().DefaultTimeout(); 1771context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1773await context.Response.WriteAsync("Hello World"); 1775Assert.True(context.Response.Headers.IsReadOnly); 1777context.Response.AppendTrailer("CustomName", "Custom Value"); 1779await context.Response.CompleteAsync().DefaultTimeout(); 1833context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1835await context.Response.WriteAsync("Hello World"); 1837Assert.True(context.Response.Headers.IsReadOnly); 1839context.Response.AppendTrailer("CustomName", "Custom Value"); 1841await context.Response.CompleteAsync().DefaultTimeout(); 1898context.Response.OnStarting(() => { startingTcs.SetResult(); return Task.CompletedTask; }); 1900await context.Response.WriteAsync("Hello World"); 1902Assert.True(context.Response.Headers.IsReadOnly); 1904context.Response.AppendTrailer("CustomName", "Custom Value"); 1906await context.Response.CompleteAsync().DefaultTimeout(); 2014await c.Response.Body.FlushAsync(); 2789context.Response.Headers["BigHeader"] = new string('!', 100); 2837await context.Response.Body.WriteAsync(buffer.AsMemory(0, 100)); 2901c.Response.Headers["Header" + i] = i + "-" + headerText; 2941c.Response.AppendTrailer("Header" + i, i + "-" + headerText); 2996var memory = context.Response.BodyWriter.GetMemory(sizeHint); 2999await context.Response.CompleteAsync(); 3000context.Response.BodyWriter.Advance(memory.Length);
Http3\Http3TestBase.cs (6)
70await context.Response.Body.WriteAsync(buffer, 0, received); 89await context.Response.Body.WriteAsync(new byte[1], 0, 1); 96context.Response.Headers["Method"] = context.Request.Method; 103context.Response.Headers["path"] = context.Request.Path.ToString(); 104context.Response.Headers["rawtarget"] = context.Features.Get<IHttpRequestFeature>().RawTarget; 111context.Response.Headers.Host = context.Request.Headers.Host;
Http3\Http3TimeoutTests.cs (2)
429await context.Response.Body.FlushAsync(); 436var writeTask = context.Response.Body.WriteAsync(buffer, 0, received);
HttpsConnectionMiddlewareTests.cs (20)
118return context.Response.WriteAsync("hello world"); 157return context.Response.WriteAsync("hello world"); 193return context.Response.WriteAsync("hello world"); 235return context.Response.WriteAsync("hello world"); 263return context.Response.WriteAsync("hello world"); 516return context.Response.WriteAsync("hello world"); 558await context.Response.WriteAsync("hello world"); 602await context.Response.WriteAsync("hello world"); 645await context.Response.WriteAsync("hello world"); 686await context.Response.WriteAsync("hello world"); 734await context.Response.WriteAsync("hello world"); 776await context.Response.WriteAsync("hello world"); 843context => context.Response.WriteAsync("hello world"), 1042await context.Response.WriteAsync("hello world"); 1085context.Response.ContentLength = 11; 1086await context.Response.WriteAsync("hello world"); 1118await using (var server = new TestServer(context => context.Response.WriteAsync(context.Request.Scheme), new TestServiceContext(LoggerFactory), ConfigureListenOptions)) 1141await using (var server = new TestServer(context => context.Response.WriteAsync("hello world"), new TestServiceContext(LoggerFactory), ConfigureListenOptions)) 1287return context.Response.WriteAsync("hello world"); 1487var response = httpContext.Response;
HttpsTests.cs (2)
239await httpContext.Response.WriteAsync("hello, world", ct); 284await httpContext.Response.WriteAsync("hello, world");
KeepAliveTimeoutTests.cs (1)
261var responseStream = httpContext.Response.Body;
KestrelMetricsTests.cs (7)
180await context.Response.WriteAsync("Hello World?"); 287await c.Response.BodyWriter.WriteAsync(Encoding.UTF8.GetBytes("Hello world")); 288await c.Response.BodyWriter.FlushAsync(); 542await context.Response.BodyWriter.FlushAsync(); 623await context.Response.BodyWriter.FlushAsync(); 776context.Response.WriteAsync("Hello world"); 922var response = httpContext.Response;
LoggingConnectionMiddlewareTests.cs (2)
22context.Response.ContentLength = 12; 23return context.Response.WriteAsync("Hello World!");
MaxRequestBodySizeTests.cs (6)
84context.Response.StatusCode = requestRejectedEx.StatusCode; 85await context.Response.WriteAsync(customApplicationResponse); 131context.Response.StatusCode = requestRejectedEx.StatusCode; 132await context.Response.WriteAsync(customApplicationResponse); 225context.Response.ContentLength = 1; 226await context.Response.Body.WriteAsync(buffer, 0, 1);
MaxRequestLineSizeTests.cs (1)
85return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext(LoggerFactory, metrics: new KestrelMetrics(meterFactory))
RequestBodyTimeoutTests.cs (2)
185context.Response.ContentLength = response.Length; 186await context.Response.WriteAsync("hello, world");
RequestHeaderLimitsTests.cs (1)
176return new TestServer(async httpContext => await httpContext.Response.WriteAsync("hello, world"), new TestServiceContext(LoggerFactory, metrics: kestrelMetrics)
RequestHeadersTimeoutTests.cs (1)
161await httpContext.Response.WriteAsync("hello, world");
RequestTargetProcessingTests.cs (5)
26context.Response.Headers.ContentLength = 11; 27await context.Response.WriteAsync("Hello World"); 71context.Response.Headers["Content-Length"] = new[] { "11" }; 72await context.Response.WriteAsync("Hello World"); 106await context.Response.CompleteAsync();
RequestTests.cs (50)
37if (context.Response.Body is MemoryStream) 43context.Response.Body = new MemoryStream(); 45await context.Response.WriteAsync("hello, world"); 63if (context.Response.BodyWriter == bodyPipe) 67bodyPipe = context.Response.BodyWriter; 69await context.Response.WriteAsync("hello, world"); 102await context.Response.WriteAsync("hello, world"); 139context.Response.ContentLength = 12; 140await context.Response.WriteAsync("Read success"); 144context.Response.ContentLength = 14; 145await context.Response.WriteAsync("Read cancelled"); 240await context.Response.WriteAsync("Done"); 324context.Response.OnStarting(() => 330context.Response.OnCompleted(() => 337context.Response.ContentLength = 1; 338return context.Response.WriteAsync($"{value}"); 361context.Response.OnStarting(() => 367context.Response.OnCompleted(() => 374context.Response.ContentLength = 1; 375return context.Response.WriteAsync($"{value}"); 396context.Response.OnStarting(async () => 402context.Response.OnCompleted(async () => 408context.Response.ContentLength = 1; 409return context.Response.WriteAsync($"{value}"); 428context.Response.OnStarting(async () => 434context.Response.OnCompleted(async () => 443context.Response.ContentLength = 1; 444await context.Response.WriteAsync($"{value}"); 469context.Response.OnStarting(async () => 475context.Response.OnCompleted(async () => 484context.Response.ContentLength = 1; 485await context.Response.WriteAsync($"{value}"); 508context.Response.OnStarting(() => 516context.Response.OnCompleted(() => 527context.Response.ContentLength = 1; 528await context.Response.WriteAsync($"{value}"); 578await context.Response.WriteAsync(context.TraceIdentifier); 595context.Response.ContentLength = identifierLength; 596await context.Response.WriteAsync(context.TraceIdentifier); 1408if (context.Response.Headers != lastResponseHeaders) 1410lastResponseHeaders = context.Response.Headers; 1418context.Response.ContentLength = request.Length; 1420await context.Response.Body.WriteAsync(request, 0, request.Length); 1712context.Response.ContentLength = 6; 1713await context.Response.Body.WriteAsync(buffer, 0, 6); 1755context.Response.ContentLength = 5; 1756await context.Response.Body.WriteAsync(buffer, 0, 5); 1905var response = httpContext.Response; 1955var response = httpContext.Response; 2040var response = httpContext.Response;
ResponseHeaderTests.cs (23)
23Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("Custom你好Name", "Custom Value")); 24Assert.Throws<InvalidOperationException>(() => context.Response.ContentType = "Custom 你好 Type"); // Special cased 25Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Accept = "Custom 你好 Accept"); // Not special cased 26Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom 你好 Value")); 27Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom \r Value")); 28context.Response.ContentLength = 11; 29return context.Response.WriteAsync("Hello World"); 54Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("Custom你好Name", "Custom Value")); 55Assert.Throws<InvalidOperationException>(() => context.Response.Headers.Append("CustomName", "Custom \r Value")); 56context.Response.ContentType = "Custom 你好 Type"; 57context.Response.Headers.Accept = "Custom 你好 Accept"; 58context.Response.Headers.Append("CustomName", "Custom 你好 Value"); 59context.Response.ContentLength = 11; 60return context.Response.WriteAsync("Hello World"); 91context.Response.Headers.Append("CustomName", "Custom 你好 Value"); 92context.Response.ContentLength = 11; 93return context.Response.WriteAsync("Hello World"); 112Assert.Equal(0, context.Response.Headers[tag].Count); 114context.Response.Headers.Add(tag, new StringValues((string)null)); 116Assert.Equal(0, context.Response.Headers[tag].Count); 119context.Response.Headers.Add(tag, new StringValues("Hello")); 121context.Response.ContentLength = 11; 122return context.Response.WriteAsync("Hello World");
ResponseTests.cs (239)
43context.Response.OnStarting(() => Task.Run(() => onStartingCalled = true)); 44context.Response.OnCompleted(() => Task.Run(() => 81await context.Response.WriteAsync("hello, world"); 82await context.Response.BodyWriter.FlushAsync(); 83ex = Assert.Throws<InvalidOperationException>(() => context.Response.OnStarting(_ => Task.CompletedTask, null)); 116await context.Response.StartAsync(); 117ex = Assert.Throws<InvalidOperationException>(() => context.Response.OnStarting(_ => Task.CompletedTask, null)); 156await context.Response.WriteAsync("hello", cts.Token).DefaultTimeout(); 161var writeTask = context.Response.BodyWriter.WriteAsync(new Memory<byte>(data, 0, data.Length), cts.Token).AsTask().DefaultTimeout(); 168writeTask = context.Response.BodyWriter.WriteAsync(new Memory<byte>(data, 0, data.Length), cts.Token).AsTask().DefaultTimeout(); 223var result = await context.Response.BodyWriter.WriteAsync(payload); 248context.Response.BodyWriter.CancelPendingFlush(); 250var cancelledResult = await context.Response.BodyWriter.WriteAsync(payload); 254var goodResult = await context.Response.BodyWriter.WriteAsync(secondPayload); 377context.Response.OnCompleted(_ => throw new Exception(), null); 378await context.Response.WriteAsync("hello, world"); 409context.Response.OnCompleted(async () => 413await context.Response.WriteAsync("hello, world"); 446httpContext.Response.OnCompleted(() => Task.Run(() => 520await httpContext.Response.WriteAsync("hello, "); 521await httpContext.Response.WriteAsync("world"); 554httpContext.Response.StatusCode = statusCode; 579httpContext.Response.StatusCode = 205; 679httpContext.Response.StatusCode = statusCode; 680httpContext.Response.Headers.ContentLength = 1; 684await httpContext.Response.StartAsync(); 717httpContext.Response.StatusCode = statusCode; 718httpContext.Response.Headers.ContentLength = 0; 722await httpContext.Response.StartAsync(); 757httpContext.Response.StatusCode = 205; 758httpContext.Response.Headers.ContentLength = 1; 762await httpContext.Response.StartAsync(); 796httpContext.Response.StatusCode = statusCode; 800await httpContext.Response.WriteAsync("hello, world"); 838httpContext.Response.StatusCode = 205; 842await httpContext.Response.WriteAsync("hello, world"); 915await httpContext.Response.WriteAsync(response); 916await httpContext.Response.BodyWriter.FlushAsync(); 959httpContext.Response.ContentLength = 11; 960await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("hello,"), 0, 6)); 961await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes(" world"), 0, 6)); 1000httpContext.Response.ContentLength = 11; 1001await httpContext.Response.WriteAsync("hello,"); 1002await httpContext.Response.WriteAsync(" world"); 1040httpContext.Response.ContentLength = 5; 1041await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(response, 0, response.Length)); 1075httpContext.Response.ContentLength = 5; 1076await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(response, 0, response.Length)); 1117httpContext.Response.ContentLength = 13; 1118await httpContext.Response.WriteAsync("hello, world"); 1171httpContext.Response.ContentLength = 13; 1172await httpContext.Response.WriteAsync("hello, world"); 1174completeEx = Assert.Throws<InvalidOperationException>(() => httpContext.Response.BodyWriter.Complete()); 1225httpContext.Response.ContentLength = 12; 1226await httpContext.Response.WriteAsync("hello,"); 1267httpContext.Response.ContentLength = 5; 1308httpContext.Response.ContentLength = 0; 1312await httpContext.Response.BodyWriter.FlushAsync(); 1346httpContext.Response.Headers["Transfer-Encoding"] = "chunked"; 1347httpContext.Response.ContentLength = 13; 1348await httpContext.Response.WriteAsync("hello, world"); 1382httpContext.Response.Headers["Transfer-Encoding"] = "chunked"; 1383httpContext.Response.ContentLength = 11; 1384await httpContext.Response.WriteAsync("hello, world"); 1412httpContext.Response.ContentLength = 42; 1440httpContext.Response.ContentLength = 12; 1441await httpContext.Response.WriteAsync("hello, world"); 1473httpContext.Response.ContentLength = 12; 1474await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("hello, world"), 0, 12)); 1504httpContext.Response.ContentLength = 12; 1505await httpContext.Response.WriteAsync(""); 1507await httpContext.Response.WriteAsync("hello, world"); 1546httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; 1547httpContext.Response.ContentLength = ex.Message.Length; 1548await httpContext.Response.WriteAsync(ex.Message); 1579httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; 1580await httpContext.Response.WriteAsync("hello, world"); 1624httpContext.Response.Headers["Connection"] = "keep-alive"; 1625httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; 1626await httpContext.Response.WriteAsync("hello, world"); 1670httpContext.Response.Headers["Transfer-Encoding"] = responseTransferEncoding; 1673await httpContext.Response.WriteAsync("hello, world"); 1713httpContext.Response.OnStarting(() => 1716httpContext.Response.ContentLength = null; 1721httpContext.Response.ContentLength = response.Length - 1; 1724await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(response, 0, response.Length)); 1755httpContext.Response.OnStarting(() => 1758httpContext.Response.ContentLength = null; 1763httpContext.Response.ContentLength = response.Length - 1; 1766await httpContext.Response.Body.WriteAsync(new Memory<byte>(response, 0, response.Length)); 1797httpContext.Response.OnStarting(() => 1800httpContext.Response.ContentLength = null; 1805httpContext.Response.ContentLength = response.Length - 1; 1808await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(response, 0, response.Length / 2)); 1809await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(response, response.Length / 2, response.Length - response.Length / 2)); 1842httpContext.Response.OnStarting(() => 1845httpContext.Response.ContentLength = null; 1850httpContext.Response.ContentLength = response.Length - 1; 1853await httpContext.Response.Body.WriteAsync(new Memory<byte>(response, 0, response.Length / 2)); 1854await httpContext.Response.Body.WriteAsync(new Memory<byte>(response, response.Length / 2, response.Length - response.Length / 2)); 1885httpContext.Response.OnStarting(() => 1888httpContext.Response.ContentLength = null; 1893httpContext.Response.ContentLength = response.Length - 1; 1896return httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(response, 0, response.Length)).AsTask(); 1925httpContext.Response.OnStarting(() => 1928httpContext.Response.ContentLength = null; 1933httpContext.Response.ContentLength = response.Length - 1; 1936await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(response, 0, response.Length / 2)); 1937await httpContext.Response.BodyWriter.WriteAsync(new Memory<byte>(response, response.Length / 2, response.Length - response.Length / 2)); 1968await httpContext.Response.WriteAsync("hello, world"); 2156await httpContext.Response.WriteAsync("hello, world"); 2328var response = httpContext.Response; 2426var response = httpContext.Response; 2481var response = httpContext.Response; 2535var response = httpContext.Response; 2580var response = httpContext.Response; 2630var response = httpContext.Response; 2682var response = httpContext.Response; 2727var response = httpContext.Response; 2768var response = httpContext.Response; 2934await httpContext.Response.StartAsync(); 2963httpContext.Response.ContentLength = 0; 2964await httpContext.Response.StartAsync(); 2965await httpContext.Response.WriteAsync(""); 2991await httpContext.Response.StartAsync(); 2992await httpContext.Response.WriteAsync(""); 3021await httpContext.Response.StartAsync(); 3022await httpContext.Response.WriteAsync("Hello World!"); 3053await httpContext.Response.StartAsync(); 3054Assert.True(httpContext.Response.HasStarted); 3083await httpContext.Response.StartAsync(); 3111httpContext.Response.ContentLength = 11; 3112await httpContext.Response.StartAsync(); 3142await httpContext.Response.StartAsync(); 3143Assert.True(httpContext.Response.HasStarted); 3178httpContext.Response.Headers["Content-Length"] = new[] { "11" }; 3179await httpContext.Response.StartAsync(); 3180await httpContext.Response.WriteAsync("Hello World"); 3181Assert.True(httpContext.Response.HasStarted); 3209httpContext.Response.ContentLength = expectedLength; 3210await httpContext.Response.WriteAsync(expectedString); 3211Assert.True(httpContext.Response.HasStarted); 3255httpContext.Response.ContentLength = expectedLength; 3257WriteStringWithoutFlushing(httpContext.Response.BodyWriter, expectedString); 3259Assert.False(httpContext.Response.HasStarted); 3287await httpContext.Response.StartAsync(); 3288await httpContext.Response.BodyWriter.FlushAsync(); 3289Assert.True(httpContext.Response.HasStarted); 3323context.Response.OnStarting(_ => 3329context.Response.OnStarting(_ => 3335context.Response.ContentLength = response.Length; 3336await context.Response.WriteAsync(response); 3374context.Response.OnCompleted(_ => 3380context.Response.OnCompleted(_ => 3386context.Response.ContentLength = response.Length; 3387await context.Response.WriteAsync(response); 3421context.Response.ContentLength = 6; 3424var ioEx = Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(Encoding.ASCII.GetBytes("What!?"), 0, 6)); 3426await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Hello1"), 0, 6); 3451context.Response.ContentLength = 6; 3452context.Response.Body.Write(Encoding.ASCII.GetBytes("Hello1"), 0, 6); 3482context.Response.ContentLength = 6; 3483context.Response.Body.Write(Encoding.ASCII.GetBytes("Hello!"), 0, 6); 3517context.Response.ContentLength = 6; 3520var ioEx = Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(Encoding.ASCII.GetBytes("What!?"), 0, 6)); 3523return context.Response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello!"), 0, 6)).AsTask(); 3548var response = httpContext.Response; 3579var response = httpContext.Response; 3612var response = httpContext.Response; 3642var response = httpContext.Response; 3674var response = httpContext.Response; 3712var response = httpContext.Response; 3749httpContext.Response.ContentLength = 12; 3750await httpContext.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("hello, world")); 3775var response = httpContext.Response; 3817httpContext.Response.BodyWriter.Complete(); 3845httpContext.Response.BodyWriter.Complete(); 3846writeEx = await Assert.ThrowsAsync<InvalidOperationException>(() => httpContext.Response.WriteAsync("test")); 3876await httpContext.Response.WriteAsync("hello, world"); 3877await httpContext.Response.BodyWriter.CompleteAsync(); 3914var memory = httpContext.Response.BodyWriter.GetMemory(); 3916httpContext.Response.BodyWriter.Advance(1); 3917await httpContext.Response.BodyWriter.FlushAsync(); 3960var memory = httpContext.Response.BodyWriter.GetMemory(); 3962httpContext.Response.BodyWriter.Advance(1); 3963await httpContext.Response.BodyWriter.FlushAsync(); 4012httpContext.Response.ContentLength = 1; 4013var memory = httpContext.Response.BodyWriter.GetMemory(); 4015httpContext.Response.BodyWriter.Advance(1); 4016await httpContext.Response.BodyWriter.FlushAsync(); 4020var memory = httpContext.Response.BodyWriter.GetMemory(); 4022httpContext.Response.BodyWriter.Advance(1); 4023await httpContext.Response.BodyWriter.FlushAsync(); 4073Assert.Throws<InvalidOperationException>(() => httpContext.Response.BodyWriter.Advance(1)); 4077var memory = httpContext.Response.BodyWriter.GetMemory(); 4116httpContext.Response.BodyWriter.Complete(expectedException); 4144await httpContext.Response.StartAsync(); 4145httpContext.Response.BodyWriter.Complete(); 4146var memory = httpContext.Response.BodyWriter.GetMemory(); // Shouldn't throw 4176httpContext.Response.BodyWriter.Complete(); 4177var memory = httpContext.Response.BodyWriter.GetMemory(); // Shouldn't throw 4205var memory = httpContext.Response.BodyWriter.GetMemory(); 4208await httpContext.Response.StartAsync(); 4211memory = httpContext.Response.BodyWriter.GetMemory(); 4240var memory = httpContext.Response.BodyWriter.GetMemory(); 4242await httpContext.Response.StartAsync(); 4244Assert.Throws<InvalidOperationException>(() => httpContext.Response.BodyWriter.Advance(1)); 4274httpContext.Response.BodyWriter.Complete(); 4276writeEx = Assert.Throws<InvalidOperationException>(() => httpContext.Response.BodyWriter.GetMemory()); 4305httpContext.Response.Body = new MemoryStream(); 4306var BodyWriter1 = httpContext.Response.BodyWriter; 4308httpContext.Response.Body = new MemoryStream(); 4309var BodyWriter2 = httpContext.Response.BodyWriter; 4337var oldBody = httpContext.Response.Body; 4338httpContext.Response.Body = new MemoryStream(); 4340await httpContext.Response.BodyWriter.WriteAsync(new byte[1]); 4341await httpContext.Response.Body.WriteAsync(new byte[1]); 4343Assert.Equal(2, httpContext.Response.Body.Length); 4345httpContext.Response.Body = oldBody; 4371httpContext.Response.Headers.AltSvc = "Custom"; 4579var memory = context.Response.BodyWriter.GetMemory(); 4580context.Response.BodyWriter.Advance(memory.Length); 4582Assert.Equal(length, context.Response.BodyWriter.UnflushedBytes); 4584memory = context.Response.BodyWriter.GetMemory(); 4585context.Response.BodyWriter.Advance(memory.Length); 4588Assert.Equal(length, context.Response.BodyWriter.UnflushedBytes); 4590await context.Response.BodyWriter.FlushAsync(); 4592Assert.Equal(0, context.Response.BodyWriter.UnflushedBytes); 4628await context.Response.StartAsync(); 4631await context.Response.BodyWriter.FlushAsync(); 4634var memory = context.Response.BodyWriter.GetMemory(); 4635context.Response.BodyWriter.Advance(memory.Length); 4637Assert.Equal(length, context.Response.BodyWriter.UnflushedBytes); 4639memory = context.Response.BodyWriter.GetMemory(); 4640context.Response.BodyWriter.Advance(memory.Length); 4644Assert.Equal(length + 7, context.Response.BodyWriter.UnflushedBytes); 4646await context.Response.BodyWriter.FlushAsync(); 4648Assert.Equal(0, context.Response.BodyWriter.UnflushedBytes); 4692disposedTcs.TrySetResult(c.Response.StatusCode);
src\Servers\Kestrel\shared\test\TestApp.cs (4)
17var response = httpContext.Response; 30var response = httpContext.Response; 47var response = httpContext.Response; 64var response = httpContext.Response;
UpgradeTests.cs (2)
31var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.Body.WriteAsync(new byte[1], 0, 1)); 34await Assert.ThrowsAsync<InvalidOperationException>(() => context.Response.BodyWriter.WriteAsync(new byte[1]).AsTask());
InProcessWebSite (149)
src\Servers\IIS\IIS\test\testassets\InProcessWebSite\Program.cs (1)
100.Configure(builder => builder.Run(async context => { await context.Response.WriteAsync("I shouldn't work"); }))
src\Servers\IIS\IIS\test\testassets\InProcessWebSite\Startup.cs (145)
57private async Task ContentRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().ContentRootPath); 59private async Task WebRootPath(HttpContext ctx) => await ctx.Response.WriteAsync(ctx.RequestServices.GetService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().WebRootPath); 66private async Task CurrentDirectory(HttpContext ctx) => await ctx.Response.WriteAsync(Environment.CurrentDirectory); 68private async Task BaseDirectory(HttpContext ctx) => await ctx.Response.WriteAsync(AppContext.BaseDirectory); 74await ctx.Response.WriteAsync("IIS Version: " + config["IIS_VERSION"] + Environment.NewLine); 75await ctx.Response.WriteAsync("ApplicationId: " + config["IIS_APPLICATION_ID"] + Environment.NewLine); 76await ctx.Response.WriteAsync("Application Path: " + config["IIS_PHYSICAL_PATH"] + Environment.NewLine); 77await ctx.Response.WriteAsync("Application Virtual Path: " + config["IIS_APPLICATION_VIRTUAL_PATH"] + Environment.NewLine); 78await ctx.Response.WriteAsync("Application Config Path: " + config["IIS_APP_CONFIG_PATH"] + Environment.NewLine); 79await ctx.Response.WriteAsync("AppPool ID: " + config["IIS_APP_POOL_ID"] + Environment.NewLine); 80await ctx.Response.WriteAsync("AppPool Config File: " + config["IIS_APP_POOL_CONFIG_FILE"] + Environment.NewLine); 81await ctx.Response.WriteAsync("Site ID: " + config["IIS_SITE_ID"] + Environment.NewLine); 82await ctx.Response.WriteAsync("Site Name: " + config["IIS_SITE_NAME"]); 102private async Task ASPNETCORE_IIS_PHYSICAL_PATH(HttpContext ctx) => await ctx.Response.WriteAsync(Environment.GetEnvironmentVariable("ASPNETCORE_IIS_PHYSICAL_PATH")); 107await ctx.Response.WriteAsync(string.Join(",", serverAddresses.Addresses)); 112await ctx.Response.WriteAsync(ctx.Request.Protocol); 119await ctx.Response.WriteAsync("Hello World"); 126await ctx.Response.WriteAsync("Hello World"); 134await ctx.Response.WriteAsync(authScheme?.Name ?? "null"); 137await ctx.Response.WriteAsync(":" + ctx.User.Identity.Name); 144await context.Response.WriteAsync(clientCert != null ? $"Enabled;{clientCert.GetCertHashString()}" : "Disabled"); 171await context.Response.WriteAsync(_waitingRequestCount.ToString(CultureInfo.InvariantCulture)); 193context.Response.Headers["connection"] = "close"; 199context.Response.Headers["Server"] = "MyServer/7.8"; 210context.Response.ContentType = "text/html"; 211await context.Response.Body.WriteAsync(new byte[100], 0, 100); 217await ctx.Response.WriteAsync(Environment.GetEnvironmentVariable(ctx.Request.Query["name"].ToString())); 229await ctx.Response.WriteAsync($"{varName}: {feature[varName] ?? "(null)"}"); 234await ctx.Response.WriteAsync("Anonymous?" + !ctx.User.Identity.IsAuthenticated); 241await ctx.Response.WriteAsync(ctx.User.Identity.AuthenticationType); 258await ctx.Response.WriteAsync("NTLM"); 268return ctx.Response.WriteAsync($"PathBase: {ctx.Request.PathBase.Value}; Path: {ctx.Request.Path.Value}"); 315await ctx.Response.WriteAsync("Success"); 320ctx.Response.StatusCode = 500; 321await ctx.Response.WriteAsync(exception.ToString()); 323await ctx.Response.WriteAsync("_Failure"); 330Assert.Equal(200, ctx.Response.StatusCode); 331ctx.Response.StatusCode = 404; 332Assert.Equal(404, ctx.Response.StatusCode); 333ctx.Response.StatusCode = 200; 339Assert.NotNull(ctx.Response.Headers); 344var originalBody = ctx.Response.Body; 347ctx.Response.Body = body; 348Assert.Same(body, ctx.Response.Body); 349ctx.Response.Body = originalBody; 351await ctx.Response.WriteAsync("Success"); 356ctx.Response.StatusCode = 500; 357await ctx.Response.WriteAsync(exception.ToString()); 359await ctx.Response.WriteAsync("_Failure"); 373await ctx.Response.WriteAsync("Success"); 378ctx.Response.StatusCode = 500; 379await ctx.Response.WriteAsync(exception.ToString()); 381await ctx.Response.WriteAsync("_Failure"); 396await ctx.Response.WriteAsync(ctx.Request.Query["body"]); 404await ctx.Response.WriteAsync(ctx.Request.Path.Value); 409await ctx.Response.WriteAsync(ctx.Request.QueryString.Value); 413await ctx.Response.WriteAsync("Hello World"); 420await ctx.Response.WriteAsync(new string('a', length)); 448ctx.Response.Headers["UnknownHeader"] = "test123=foo"; 449ctx.Response.ContentType = "text/plain"; 450ctx.Response.Headers["MultiHeader"] = new StringValues(new string[] { "1", "2" }); 451await ctx.Response.WriteAsync("Request Complete"); 456ctx.Response.Headers["EmptyHeader"] = ""; 457await ctx.Response.WriteAsync("EmptyHeaderShouldBeSkipped"); 469return ctx.Response.WriteAsync($"Failure: '{headerName}' indexer"); 473return ctx.Response.WriteAsync($"Failure: '{headerName}' TryGetValue"); 497return ctx.Response.WriteAsync($"Failure: Repeated '{headerName}' Add did not throw"); 514return ctx.Response.WriteAsync("Success"); 521await ctx.Response.WriteAsync("Started_"); 524ctx.Response.StatusCode = 200; 528await ctx.Response.WriteAsync("SetStatusCodeAfterWriteThrew_"); 530await ctx.Response.WriteAsync("Finished"); 535await ctx.Response.WriteAsync("Started_"); 538ctx.Response.Headers["This will fail"] = "some value"; 542await ctx.Response.WriteAsync("SetHeaderAfterWriteThrew_"); 544await ctx.Response.WriteAsync("Finished"); 586await ctx.Response.WriteAsync(_requestsInFlight.ToString(CultureInfo.InvariantCulture)); 591await ctx.Response.WriteAsync("done"); 597await ctx.Response.WriteAsync("test1"); 604await ctx.Response.WriteAsync("test2"); 613ctx.Response.ContentLength = 9; 614await ctx.Response.WriteAsync("Completed"); 621await ctx.Response.WriteAsync("hello world"); 634await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result)); 647await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result)); 648await ctx.Response.Body.FlushAsync(); 660ctx.Response.ContentType = contentType; 664await ctx.Response.Body.FlushAsync(); 674await ctx.Response.WriteAsync(line + Environment.NewLine); 675await ctx.Response.Body.FlushAsync(); 692ctx.Response.ContentType = contentType; 696await ctx.Response.Body.FlushAsync(); 706await ctx.Response.WriteAsync(line + Environment.NewLine); 721await ctx.Response.Body.WriteAsync(data, 0, data.Length); 729ctx.Response.Headers["BodyAsString"] = value; 730await ctx.Response.WriteAsync(value); 740await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result)); 741await ctx.Response.Body.FlushAsync(); 742await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result)); 743await ctx.Response.Body.FlushAsync(); 759await ctx.Response.WriteAsync("hello world"); 768await ctx.Request.Body.CopyToAsync(ctx.Response.Body); 777await ctx.Response.WriteAsync(Encoding.UTF8.GetString(buffer)); 850await ctx.Response.WriteAsync(success ? "Success" : "Failure"); 874await ctx.Response.WriteAsync(count == 0 ? "Success" : "Failure"); 885await ctx.Response.Body.WriteAsync(new byte[1], -1, 0); 896await ctx.Response.Body.WriteAsync(new byte[1], 2, 0); 907await ctx.Response.Body.WriteAsync(new byte[1], 0, -1); 918await ctx.Response.Body.WriteAsync(new byte[1], 0, -1); 929await ctx.Response.Body.WriteAsync(new byte[3], 1, 3); 937await ctx.Response.WriteAsync(success ? "Success" : "Failure"); 944await ctx.Response.Body.WriteAsync(null, 0, 0); 948await ctx.Response.Body.WriteAsync(null, 0, 0); 951await ctx.Response.WriteAsync("Success"); 966await ctx.Response.SendFileAsync(tempFile, 0, null); 982await ctx.Response.WriteAsync(AppDomain.CurrentDomain.BaseDirectory); 988return ctx.Response.WriteAsync(ctx.Request.Path.Value); 993await ctx.Response.WriteAsync("Shutting down"); 1003await ctx.Response.WriteAsync("Shutting down"); 1010await ctx.Response.WriteAsync("Shutting down"); 1021await ctx.Response.WriteAsync("Hello World"); 1028await ctx.Response.WriteAsync("Hello World"); 1042await ctx.Response.WriteAsync(StartupHookCalled.ToString()); 1052await ctx.Response.WriteAsync("Response Begin"); 1055await ctx.Response.WriteAsync(serverVariableFeature["REMOTE_PORT"]); 1056await ctx.Response.Body.FlushAsync(); 1058await ctx.Response.WriteAsync("Response End"); 1063await ctx.Response.WriteAsync(string.Join("|", Environment.GetCommandLineArgs().Skip(1))); 1067ctx.Response.WriteAsync("Scheme:" + ctx.Request.Scheme + "; Original:" + ctx.Request.Headers["x-original-proto"]); 1069public Task Path(HttpContext ctx) => ctx.Response.WriteAsync(ctx.Request.Path.Value); 1071public Task Query(HttpContext ctx) => ctx.Response.WriteAsync(ctx.Request.QueryString.Value); 1073public Task BodyLimit(HttpContext ctx) => ctx.Response.WriteAsync(ctx.Features.Get<IHttpMaxRequestBodySizeFeature>()?.MaxRequestBodySize?.ToString(CultureInfo.InvariantCulture) ?? "null"); 1075public Task Anonymous(HttpContext context) => context.Response.WriteAsync("Anonymous?" + !context.User.Identity.IsAuthenticated); 1082return context.Response.WriteAsync(context.User.Identity.AuthenticationType); 1096return context.Response.WriteAsync("NTLM"); 1105context.Response.WriteAsync(context.Features.Get<IHttpUpgradeFeature>() != null ? "Enabled" : "Disabled"); 1119return context.Response.WriteAsync("Hello World"); 1122return context.Response.WriteAsync(context.Request.Headers["ANCMRHPath"]); 1127await context.Response.WriteAsync(Environment.ProcessId.ToString(CultureInfo.InvariantCulture)); 1134await context.Response.WriteAsync(httpsPort.HasValue ? httpsPort.Value.ToString(CultureInfo.InvariantCulture) : "NOVALUE"); 1141await context.Response.WriteAsync(httpsPort.HasValue ? httpsPort.Value.ToString(CultureInfo.InvariantCulture) : "NOVALUE"); 1171ctx.Response.StatusCode = 500; 1172await ctx.Response.WriteAsync(exception.ToString()); 1192ctx.Response.StatusCode = 500; 1193await ctx.Response.WriteAsync(exception.ToString());
src\Servers\IIS\IIS\test\testassets\InProcessWebSite\Startup.WebSockets.cs (3)
77context.Response.OnStarting(() => 79context.Response.Headers["custom-header"] = "value"; 118context.Response.Headers[headerPair.Key] = headerPair.Value;
Interop.FunctionalTests (83)
H2SpecTests.cs (1)
153await context.Response.WriteAsync("Hello World");
Http2\Http2RequestTests.cs (5)
170c.Response.Headers["test"] = "abc"; 171c.Response.Headers[longKey] = longValue; 244var memory = c.Response.BodyWriter.GetMemory(randomBytes.Length); 252c.Response.BodyWriter.Advance(randomBytes.Length); 256c.Response.AppendTrailer("test-trailer", "value!");
Http3\Http3RequestTests.cs (23)
140await context.Response.WriteAsync("hello, world"); 238await context.Response.Body.WriteAsync(TestData); 242await context.Response.Body.WriteAsync(TestData); 332await context.Response.Body.WriteAsync(data); 407await context.Response.Body.WriteAsync(data); 602await context.Response.Body.WriteAsync(new byte[16]); 667writeAsyncTask.SetResult(context.Response.Body.WriteAsync(TestData).AsTask()); 714await context.Response.Body.WriteAsync(data); 983var responseBody = context.Response.Body; 1077await context.Response.BodyWriter.FlushAsync(); 1092context.Response.BodyWriter.GetSpan(data.Length); 1093context.Response.BodyWriter.Advance(data.Length); 1095await context.Response.BodyWriter.FlushAsync(); 1175await context.Response.BodyWriter.FlushAsync(); 1187var memory = context.Response.BodyWriter.GetMemory(); 1197context.Response.BodyWriter.Advance(memory.Length); 1198var flushResult = await context.Response.BodyWriter.FlushAsync(); 1300var responseBody = context.Response.Body; 1357await context.Response.BodyWriter.WriteAsync(TestData); 1529await context.Response.CompleteAsync(); 2002await context.Response.Body.FlushAsync(); 2113await context.Response.Body.FlushAsync(); 2119await context.Response.Body.WriteAsync(data);
Http3\Http3TlsTests.cs (8)
32await context.Response.WriteAsync("Hello World"); 83await context.Response.WriteAsync(hasCert.ToString()); 125await context.Response.WriteAsync(hasCert.ToString()); 170await context.Response.WriteAsync(hasCert.ToString()); 224await context.Response.WriteAsync(hasCert.ToString()); 265await context.Response.WriteAsync("Hello World"); 295await context.Response.WriteAsync("Hello World"); 448await context.Response.WriteAsync("Hello World");
HttpClientHttp2InteropTests.cs (46)
58.Configure(app => app.Run(context => context.Response.WriteAsync("Hello World"))); 81await context.Request.BodyReader.CopyToAsync(context.Response.BodyWriter).DefaultTimeout(); 120await content.CopyToAsync(context.Response.Body).DefaultTimeout(); 167await context.Request.BodyReader.CopyToAsync(context.Response.BodyWriter).DefaultTimeout(); 282await context.Response.BodyWriter.WriteAsync(sequence.First).DefaultTimeout(); 339await context.Response.BodyWriter.WriteAsync(sequence.First).DefaultTimeout(); 341await context.Response.CompleteAsync().DefaultTimeout(); 410context.Response.ContentType = "text/plain"; 411await context.Response.WriteAsync("Hello World"); 412await context.Response.CompleteAsync().DefaultTimeout(); 526context.Response.DeclareTrailer("TestTrailer"); 527context.Response.AppendTrailer("TestTrailer", "TestValue"); 556context.Response.DeclareTrailer("TestTrailer"); 557await context.Response.WriteAsync("Hello "); 559await context.Response.WriteAsync("World"); 560context.Response.AppendTrailer("TestTrailer", "TestValue"); 616await context.Response.BodyWriter.FlushAsync(); 644await context.Response.WriteAsync("Hello World"); 645await context.Response.CompleteAsync(); 671context.Response.DeclareTrailer("TestTrailer"); 672await context.Response.WriteAsync("Hello World"); 673context.Response.AppendTrailer("TestTrailer", "TestValue"); 674await context.Response.CompleteAsync(); 707context.Response.ContentType = "text/plain"; 708await context.Response.BodyWriter.FlushAsync(); 766context.Response.ContentType = "text/plain"; 767await context.Response.BodyWriter.FlushAsync(); 917await context.Response.WriteAsync("Hello World").DefaultTimeout(); 956await context.Response.WriteAsync("Hello World").DefaultTimeout(); 958await context.Response.WriteAsync("Hello World").DefaultTimeout(); 996await context.Response.WriteAsync("Hello World").DefaultTimeout(); 998context.Response.AppendTrailer("foo", "bar"); 999await context.Response.CompleteAsync(); 1092context.Response.Headers.Append("header" + i, oneKbString + i); 1320.Configure(app => app.Run(context => context.Response.WriteAsync("Hello World"))); 1353.Configure(app => app.Run(context => context.Response.WriteAsync("Hello World"))); 1391context.Response.Headers.Append("header" + i, oneKbString + i); 1424await context.Response.WriteAsync("Hello World"); 1469await context.Response.WriteAsync(oneKbString).DefaultTimeout(); 1471await context.Response.WriteAsync(new string('a', 1023)).DefaultTimeout(); 1472await context.Response.CompleteAsync().DefaultTimeout(); 1508await context.Response.WriteAsync("Hello World"); 1559return context.Response.WriteAsync(context.Request.Host.Host); 1583.Configure(app => app.Run(context => context.Response.WriteAsync(context.Request.Path.Value))); 1622await context.Response.WriteAsync("Hello World"); 1667await context.Response.WriteAsync("Hello World");
JwtBearerSample (1)
Startup.cs (1)
72var response = context.Response;
JwtSample (1)
Startup.cs (1)
72return context.Response.WriteAsync(GenerateToken(context));
Kestrel.SampleApp (3)
Startup.cs (3)
61context.Response.ContentLength = response.Length; 62context.Response.ContentType = "text/plain"; 63await context.Response.WriteAsync(response);
LargeResponseApp (3)
Startup.cs (3)
31context.Response.ContentLength = _chunkSize * numChunks; 32context.Response.ContentType = "text/plain"; 36await context.Response.Body.WriteAsync(_chunk, 0, _chunkSize).ConfigureAwait(false);
LocalizationSample (51)
Startup.cs (51)
37context.Response.StatusCode = 404; 41context.Response.StatusCode = 200; 42context.Response.ContentType = "text/html; charset=utf-8"; 47await context.Response.WriteAsync( 72await context.Response.WriteAsync($"<h1>{SR["Request Localization Sample"]}</h1>"); 73await context.Response.WriteAsync($"<h1>{SR["Hello"]}</h1>"); 74await context.Response.WriteAsync("<form id=\"theForm\" method=\"get\">"); 75await context.Response.WriteAsync($"<label for=\"culture\">{SR["Culture"]}: </label>"); 76await context.Response.WriteAsync("<select id=\"culture\" name=\"culture\">"); 78await context.Response.WriteAsync("</select><br />"); 79await context.Response.WriteAsync($"<label for=\"uiCulture\">{SR["UI Culture"]}: </label>"); 80await context.Response.WriteAsync("<select id=\"uiCulture\" name=\"ui-culture\">"); 82await context.Response.WriteAsync("</select><br />"); 83await context.Response.WriteAsync("<input type=\"submit\" value=\"go QS\" /> "); 84await context.Response.WriteAsync($"<input type=\"button\" value=\"go cookie\" onclick='useCookie();' /> "); 85await context.Response.WriteAsync($"<a href=\"/\" onclick='clearCookie();'>{SR["reset"]}</a>"); 86await context.Response.WriteAsync("</form>"); 87await context.Response.WriteAsync("<br />"); 88await context.Response.WriteAsync("<table><tbody>"); 89await context.Response.WriteAsync($"<tr><th>Winning provider:</th><td>{requestCultureFeature.Provider.GetType().Name}</td></tr>"); 90await context.Response.WriteAsync($"<tr><th>{SR["Current request culture:"]}</th><td>{requestCulture.Culture.DisplayName} ({requestCulture.Culture})</td></tr>"); 91await context.Response.WriteAsync($"<tr><th>{SR["Current request UI culture:"]}</th><td>{requestCulture.UICulture.DisplayName} ({requestCulture.UICulture})</td></tr>"); 92await context.Response.WriteAsync($"<tr><th>{SR["Current thread culture:"]}</th><td>{CultureInfo.CurrentCulture.DisplayName} ({CultureInfo.CurrentCulture})</td></tr>"); 93await context.Response.WriteAsync($"<tr><th>{SR["Current thread UI culture:"]}</th><td>{CultureInfo.CurrentUICulture.DisplayName} ({CultureInfo.CurrentUICulture})</td></tr>"); 94await context.Response.WriteAsync($"<tr><th>{SR["Current date (invariant full):"]}</th><td>{DateTime.Now.ToString("F", CultureInfo.InvariantCulture)}</td></tr>"); 95await context.Response.WriteAsync($"<tr><th>{SR["Current date (invariant):"]}</th><td>{DateTime.Now.ToString(CultureInfo.InvariantCulture)}</td></tr>"); 96await context.Response.WriteAsync($"<tr><th>{SR["Current date (request full):"]}</th><td>{DateTime.Now.ToString("F", CultureInfo.CurrentCulture)}</td></tr>"); 97await context.Response.WriteAsync($"<tr><th>{SR["Current date (request):"]}</th><td>{DateTime.Now.ToString(CultureInfo.CurrentCulture)}</td></tr>"); 98await context.Response.WriteAsync($"<tr><th>{SR["Current time (invariant):"]}</th><td>{DateTime.Now.ToString("T", CultureInfo.InvariantCulture)}</td></tr>"); 99await context.Response.WriteAsync($"<tr><th>{SR["Current time (request):"]}</th><td>{DateTime.Now.ToString("T", CultureInfo.CurrentCulture)}</td></tr>"); 100await context.Response.WriteAsync($"<tr><th>{SR["Big number (invariant):"]}</th><td>{(Math.Pow(2, 42) + 0.42).ToString("N", CultureInfo.InvariantCulture)}</td></tr>"); 101await context.Response.WriteAsync($"<tr><th>{SR["Big number (request):"]}</th><td>{(Math.Pow(2, 42) + 0.42).ToString("N", CultureInfo.CurrentCulture)}</td></tr>"); 102await context.Response.WriteAsync($"<tr><th>{SR["Big number negative (invariant):"]}</th><td>{(-Math.Pow(2, 42) + 0.42).ToString("N", CultureInfo.InvariantCulture)}</td></tr>"); 103await context.Response.WriteAsync($"<tr><th>{SR["Big number negative (request):"]}</th><td>{(-Math.Pow(2, 42) + 0.42).ToString("N", CultureInfo.CurrentCulture)}</td></tr>"); 104await context.Response.WriteAsync($"<tr><th>{SR["Money (invariant):"]}</th><td>{2199.50.ToString("C", CultureInfo.InvariantCulture)}</td></tr>"); 105await context.Response.WriteAsync($"<tr><th>{SR["Money (request):"]}</th><td>{2199.50.ToString("C", CultureInfo.CurrentCulture)}</td></tr>"); 106await context.Response.WriteAsync($"<tr><th>{SR["Money negative (invariant):"]}</th><td>{(-2199.50).ToString("C", CultureInfo.InvariantCulture)}</td></tr>"); 107await context.Response.WriteAsync($"<tr><th>{SR["Money negative (request):"]}</th><td>{(-2199.50).ToString("C", CultureInfo.CurrentCulture)}</td></tr>"); 108await context.Response.WriteAsync("</tbody></table>"); 109await context.Response.WriteAsync( 117await context.Response.WriteAsync($" <option value=\"\">-- select --</option>"); 118await context.Response.WriteAsync($" <option value=\"{new CultureInfo("en-US").Name}\">{new CultureInfo("en-US").DisplayName}</option>"); 119await context.Response.WriteAsync($" <option value=\"{new CultureInfo("en-AU").Name}\">{new CultureInfo("en-AU").DisplayName}</option>"); 120await context.Response.WriteAsync($" <option value=\"{new CultureInfo("en-GB").Name}\">{new CultureInfo("en-GB").DisplayName}</option>"); 121await context.Response.WriteAsync($" <option value=\"{new CultureInfo("fr-FR").Name}\">{new CultureInfo("fr-FR").DisplayName}</option>"); 122await context.Response.WriteAsync($" <option value=\"{new CultureInfo("es-ES").Name}\">{new CultureInfo("es-ES").DisplayName}</option>"); 123await context.Response.WriteAsync($" <option value=\"{new CultureInfo("ja-JP").Name}\">{new CultureInfo("ja-JP").DisplayName}</option>"); 124await context.Response.WriteAsync($" <option value=\"{new CultureInfo("zh").Name}\">{new CultureInfo("zh").DisplayName}</option>"); 125await context.Response.WriteAsync($" <option value=\"{new CultureInfo("zh-CN").Name}\">{new CultureInfo("zh-CN").DisplayName}</option>"); 126await context.Response.WriteAsync($" <option value=\"en-NOTREAL\">English (Not a real locale)</option>"); 127await context.Response.WriteAsync($" <option value=\"pp-NOTREAL\">Made-up (Not a real anything)</option>");
LocalizationWebsite (29)
StartupBuilderAPIs.cs (1)
34await context.Response.WriteAsync(customerStringLocalizer["Hello"]);
StartupContentLanguageHeader.cs (5)
36var hasContentLanguageHeader = context.Response.Headers.ContainsKey(HeaderNames.ContentLanguage); 37var contentLanguage = context.Response.Headers.ContentLanguage.ToString(); 39await context.Response.WriteAsync(hasContentLanguageHeader.ToString()); 40await context.Response.WriteAsync(" "); 41await context.Response.WriteAsync(contentLanguage);
StartupCustomCulturePreserved.cs (1)
34await context.Response.WriteAsync(10.ToString("C", CultureInfo.CurrentCulture));
StartupGetAllStrings.cs (3)
40await context.Response.WriteAsync(strings.Count().ToString(CultureInfo.InvariantCulture)); 41await context.Response.WriteAsync(" "); 42await context.Response.WriteAsync(string.Join(" ", strings));
StartupResourcesAtRootFolder.cs (5)
44await context.Response.WriteAsync(startupStringLocalizer["Hello"]); 45await context.Response.WriteAsync(" "); 46await context.Response.WriteAsync(stringLocalizer["Hello"]); 47await context.Response.WriteAsync(" "); 48await context.Response.WriteAsync(customerStringLocalizer["Hello"]);
StartupResourcesInClassLibrary.cs (7)
53await context.Response.WriteAsync(noAttributeNameStringLocalizer["Hello"]); 54await context.Response.WriteAsync(" "); 55await context.Response.WriteAsync(noAttributeStringLocalizer["Hello"]); 56await context.Response.WriteAsync(" "); 57await context.Response.WriteAsync(withAttributeNameStringLocalizer["Hello"]); 58await context.Response.WriteAsync(" "); 59await context.Response.WriteAsync(withAttributeStringLocalizer["Hello"]);
StartupResourcesInFolder.cs (7)
47await context.Response.WriteAsync(startupStringLocalizer["Hello"]); 48await context.Response.WriteAsync(" "); 49await context.Response.WriteAsync(stringLocalizer["Hello"]); 50await context.Response.WriteAsync(" "); 51await context.Response.WriteAsync(custromerStringLocalizer["Hello"]); 52await context.Response.WriteAsync(" "); 53await context.Response.WriteAsync(customCultureLocalizer["Hello"]);
Logging.W3C.Sample (2)
Startup.cs (2)
33context.Response.ContentType = "text/plain"; 34await context.Response.WriteAsync("Hello World!");
Microsoft.AspNetCore.Antiforgery (8)
Internal\DefaultAntiforgery.cs (7)
66if (!httpContext.Response.HasStarted) 233if (!httpContext.Response.HasStarted) 247if (!_options.SuppressXFrameOptionsHeader && !httpContext.Response.Headers.ContainsKey(HeaderNames.XFrameOptions)) 252httpContext.Response.Headers.XFrameOptions = "SAMEORIGIN"; 364var responseHeaders = httpContext.Response.Headers; 387httpContext.Response.Headers.Pragma = "no-cache"; 392httpContext.Response.Headers.Pragma = "no-cache";
Internal\DefaultAntiforgeryTokenStore.cs (1)
99httpContext.Response.Cookies.Append(_options.Cookie.Name!, token, options);
Microsoft.AspNetCore.Antiforgery.Test (27)
DefaultAntiforgeryTest.cs (23)
311Assert.Equal("no-cache, no-store", context.HttpContext.Response.Headers.CacheControl); 312Assert.Equal("no-cache", context.HttpContext.Response.Headers.Pragma); 326context.HttpContext.Response.Headers.CacheControl = "public"; 342Assert.Equal("no-cache, no-store", context.HttpContext.Response.Headers.CacheControl); 343Assert.Equal("no-cache", context.HttpContext.Response.Headers.Pragma); 363context.HttpContext.Response.Headers[headerName] = headerValue; 367return context.HttpContext.Response.Headers[headerName].ToString(); 504Assert.Equal("no-cache, no-store", context.HttpContext.Response.Headers.CacheControl); 505Assert.Equal("no-cache", context.HttpContext.Response.Headers.Pragma); 997context.HttpContext.Response.Headers["X-Frame-Options"] = expectedHeaderValue; 1003var xFrameOptions = context.HttpContext.Response.Headers["X-Frame-Options"]; 1026Assert.Equal("no-cache, no-store", context.HttpContext.Response.Headers["Cache-Control"]); 1027Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]); 1049Assert.Equal("no-cache, no-store", context.HttpContext.Response.Headers["Cache-Control"]); 1050Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]); 1067context.HttpContext.Response.Headers["Cache-Control"] = "public"; 1073Assert.Equal("no-cache, no-store", context.HttpContext.Response.Headers["Cache-Control"]); 1074Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]); 1103var xFrameOptions = context.HttpContext.Response.Headers["X-Frame-Options"]; 1266context.HttpContext.Response.Headers["Cache-Control"] = "public"; 1272Assert.Equal("public", context.HttpContext.Response.Headers["Cache-Control"]); 1332context.HttpContext.Response.Headers[headerName] = headerValue; 1366context.HttpContext.Response.Headers[headerName] = headerValue;
DefaultAntiforgeryTokenStoreTest.cs (4)
364.Setup(o => o.Response.Cookies) 406.Setup(hc => hc.Response.Cookies) 442.Setup(hc => hc.Response.Cookies) 481.Setup(hc => hc.Response.Cookies)
Microsoft.AspNetCore.Authentication (2)
AuthenticationHandler.cs (1)
48get => Context.Response;
Events\BaseContext.cs (1)
53public HttpResponse Response => HttpContext.Response;
Microsoft.AspNetCore.Authentication.Cookies (5)
CookieAuthenticationHandler.cs (1)
72Context.Response.OnStarting(FinishResponseAsync);
src\Shared\ChunkingCookieManager\ChunkingCookieManager.cs (4)
151var responseCookies = context.Response.Cookies; 274var responseHeaders = context.Response.Headers; 294var responseCookies = context.Response.Cookies; 332context.Response.Cookies.Append(keyValuePairs.ToArray(), new CookieOptions(options)
Microsoft.AspNetCore.Authentication.Negotiate (1)
NegotiateHandler.cs (1)
167Context.Response.StatusCode = StatusCodes.Status400BadRequest;
Microsoft.AspNetCore.Authentication.Negotiate.Test (60)
EventTests.cs (26)
41Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 42Assert.Equal("Negotiate", result.Response.Headers.WWWAuthenticate); 65Assert.Equal(StatusCodes.Status418ImATeapot, result.Response.StatusCode); 66Assert.Equal("Teapot", result.Response.Headers.WWWAuthenticate); 113Assert.Equal(StatusCodes.Status418ImATeapot, result.Response.StatusCode); 114Assert.Equal("Teapot", result.Response.Headers.WWWAuthenticate); 163Assert.Equal(StatusCodes.Status418ImATeapot, result.Response.StatusCode); 164Assert.Equal("Teapot", result.Response.Headers.WWWAuthenticate); 188Assert.Equal(StatusCodes.Status418ImATeapot, response.Response.StatusCode); 213Assert.Equal(StatusCodes.Status418ImATeapot, result.Response.StatusCode); 214Assert.Equal("Teapot", result.Response.Headers.WWWAuthenticate); 238Assert.Equal(StatusCodes.Status400BadRequest, response.Response.StatusCode); 263Assert.Equal(StatusCodes.Status418ImATeapot, result.Response.StatusCode); 264Assert.Equal("Teapot", result.Response.Headers.WWWAuthenticate); 293Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 294Assert.False(result.Response.Headers.ContainsKey(HeaderNames.WWWAuthenticate)); 339Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 340Assert.Equal("Negotiate", result.Response.Headers.WWWAuthenticate); 363Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 364Assert.Equal("Negotiate", result.Response.Headers.WWWAuthenticate); 398Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 399Assert.Equal("Negotiate ServerKerberosBlob1", result.Response.Headers.WWWAuthenticate); 405Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 406Assert.Equal("Negotiate ServerKerberosBlob2", result.Response.Headers.WWWAuthenticate); 447await context.Response.WriteAsync(name); 452context.Response.StatusCode = StatusCodes.Status418ImATeapot;
NegotiateHandlerTests.cs (34)
40Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 50Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 60Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 61Assert.Equal("Negotiate", result.Response.Headers.WWWAuthenticate); 72Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 73Assert.Equal("Negotiate", result.Response.Headers.WWWAuthenticate); 82Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 83Assert.Equal("Negotiate ServerNtlmBlob1", result.Response.Headers.WWWAuthenticate); 164Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 165Assert.False(result.Response.Headers.ContainsKey(HeaderNames.WWWAuthenticate)); 191Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 192Assert.Equal("Negotiate", result.Response.Headers.WWWAuthenticate); 275return context.Response.WriteAsync("Error Handler"); 289Assert.Equal(StatusCodes.Status500InternalServerError, result.Response.StatusCode); 290Assert.False(result.Response.Headers.ContainsKey(HeaderNames.WWWAuthenticate)); 300Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 301Assert.Equal("Negotiate", result.Response.Headers.WWWAuthenticate); 311Assert.Equal(StatusCodes.Status400BadRequest, result.Response.StatusCode); 312Assert.DoesNotContain(HeaderNames.WWWAuthenticate, result.Response.Headers); 328Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 329Assert.Equal("Negotiate ServerKerberosBlob", result.Response.Headers.WWWAuthenticate); 336Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 337Assert.Equal("Negotiate ServerKerberosBlob", result.Response.Headers.WWWAuthenticate); 349Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 350Assert.Equal("Negotiate ServerKerberosBlob1", result.Response.Headers.WWWAuthenticate); 356Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 357Assert.Equal("Negotiate ServerKerberosBlob2", result.Response.Headers.WWWAuthenticate); 369Assert.Equal(StatusCodes.Status401Unauthorized, result.Response.StatusCode); 370Assert.Equal("Negotiate ServerNtlmBlob1", result.Response.Headers.WWWAuthenticate); 376Assert.Equal(StatusCodes.Status200OK, result.Response.StatusCode); 377Assert.Equal("Negotiate ServerNtlmBlob2", result.Response.Headers.WWWAuthenticate); 432await context.Response.WriteAsync(name); 450await context.Response.WriteAsync(name); 459await context.Response.WriteAsync(name);
Microsoft.AspNetCore.Authentication.OAuth (2)
OAuthHandler.cs (2)
279var location = Context.Response.Headers.Location; 285var cookie = Context.Response.Headers.SetCookie;
Microsoft.AspNetCore.Authentication.OpenIdConnect (2)
OpenIdConnectHandler.cs (2)
365var location = Context.Response.Headers.Location; 371var cookie = Context.Response.Headers.SetCookie;
Microsoft.AspNetCore.Authentication.Test (55)
AuthenticationMiddlewareTests.cs (1)
267_context.Response.StatusCode = _code;
CertificateTests.cs (1)
821var response = context.Response;
CookieTests.cs (3)
1670await DescribeAsync(context.Response, result); 1718await context.Response.WriteAsync("ha+1"); 1818var res = context.Response;
DynamicSchemeTests.cs (1)
140var res = context.Response;
GoogleTests.cs (5)
169var res = context.Response; 221var res = context.Response; 273var res = context.Response; 350var res = context.Response; 1155var res = context.Response;
JwtBearerTests.cs (7)
208context.Response.StatusCode = 401; 209await context.Response.WriteAsync("i got this"); 1189context.Response.StatusCode = 401; 1198context.Response.StatusCode = 500; 1202await context.Response.WriteAsync(identifier.Value); 1207await context.Response.WriteAsync(token); 1231await context.Response.WriteAsJsonAsync(
JwtBearerTests_Handler.cs (7)
195context.Response.StatusCode = 401; 196await context.Response.WriteAsync("i got this"); 1248context.Response.StatusCode = 401; 1257context.Response.StatusCode = 500; 1261await context.Response.WriteAsync(identifier.Value); 1266await context.Response.WriteAsync(token); 1290await context.Response.WriteAsJsonAsync(
MicrosoftAccountTests.cs (1)
366var res = context.Response;
OpenIdConnect\OpenIdConnectAuthenticateTests.cs (2)
29await context.Response.WriteAsync("Hi from the callback path"); 54await context.Response.WriteAsync("Hi from the callback path");
OpenIdConnect\OpenIdConnectEventTests.cs (3)
28private readonly RequestDelegate AppWritePath = context => context.Response.WriteAsync(context.Request.Path); 1058context.Response.StatusCode = StatusCodes.Status202Accepted; 1125context.Response.StatusCode = StatusCodes.Status202Accepted;
OpenIdConnect\OpenIdConnectEventTests_Handler.cs (3)
28private readonly RequestDelegate AppWritePath = context => context.Response.WriteAsync(context.Request.Path); 1058context.Response.StatusCode = StatusCodes.Status202Accepted; 1125context.Response.StatusCode = StatusCodes.Status202Accepted;
OpenIdConnect\TestServerBuilder.cs (1)
73var res = context.Response;
PolicyTests.cs (1)
473var res = context.Response;
TwitterTests.cs (1)
546var res = context.Response;
WsFederation\WsFederationTest.cs (9)
386await context.Response.WriteAsync("Signing out..."); 390await context.Response.WriteAsync("SignedOut"); 399await context.Response.WriteAsync("AuthenticationFailed"); 407await context.Response.WriteAsync("signout-wsfed"); 425await context.Response.WriteAsync("Unauthorized"); 432context.Response.StatusCode = 500; 433await context.Response.WriteAsync("SignIn_Failed"); 437await context.Response.WriteAsync("Provider not invoked"); 442await context.Response.WriteAsync(WsFederationDefaults.AuthenticationScheme);
WsFederation\WsFederationTest_Handler.cs (9)
382await context.Response.WriteAsync("Signing out..."); 386await context.Response.WriteAsync("SignedOut"); 395await context.Response.WriteAsync("AuthenticationFailed"); 403await context.Response.WriteAsync("signout-wsfed"); 421await context.Response.WriteAsync("Unauthorized"); 428context.Response.StatusCode = 500; 429await context.Response.WriteAsync("SignIn_Failed"); 433await context.Response.WriteAsync("Provider not invoked"); 438await context.Response.WriteAsync(WsFederationDefaults.AuthenticationScheme);
Microsoft.AspNetCore.Authorization.Test (1)
AuthorizationMiddlewareTests.cs (1)
1081context.Response.StatusCode = _statusCode;
Microsoft.AspNetCore.Components.Endpoints (38)
Builder\OpaqueRedirection.cs (3)
70httpContext.Response.StatusCode = 400; 88httpContext.Response.StatusCode = 400; 92httpContext.Response.Redirect(url);
Builder\ResourceCollectionUrlEndpoint.cs (12)
187await context.Response.Body.WriteAsync(_gzipContent); 194await context.Response.Body.WriteAsync(_content); 201await context.Response.Body.WriteAsync(_content); 209await context.Response.Body.WriteAsync(_gzipContent); 214context.Response.Headers[HeaderNames.ContentEncoding] = "gzip"; 215context.Response.Headers[HeaderNames.Vary] = HeaderNames.AcceptEncoding; 216context.Response.Headers.ETag = new StringValues(_gzipContentETags); 221context.Response.Headers.ETag = new StringValues(_contentETag); 226context.Response.Headers[HeaderNames.CacheControl] = "max-age=31536000, immutable"; 231context.Response.Headers[HeaderNames.CacheControl] = "no-cache, must-revalidate"; 236context.Response.ContentType = "application/javascript"; 237context.Response.ContentLength = contents.Length;
RazorComponentEndpointInvoker.cs (9)
40context.Response.ContentType = RazorComponentResultExecutor.DefaultContentType; 69context.Response.OnStarting(() => 85await using var writer = new HttpResponseStreamWriter(context.Response.Body, Encoding.UTF8, defaultBufferSize, ArrayPool<byte>.Shared, ArrayPool<char>.Shared); 129context.Response.Headers.ContentEncoding = "identity"; 176context.Response.StatusCode = StatusCodes.Status400BadRequest; 179await context.Response.WriteAsync("The request has an incorrect Content-type."); 223context.Response.StatusCode = StatusCodes.Status400BadRequest; 227await context.Response.WriteAsync("A valid antiforgery token was not provided with the request. Add an antiforgery token, or disable antiforgery validation for this endpoint."); 249context.Response.StatusCode = StatusCodes.Status400BadRequest;
Rendering\EndpointHtmlRenderer.EventDispatch.cs (3)
70_httpContext.Response.StatusCode = 400; 71_httpContext.Response.ContentType = "text/plain"; 73? _httpContext.Response.WriteAsync(detailedMessage)
Rendering\EndpointHtmlRenderer.Prerendering.cs (4)
82context.Response.Headers.Add("blazor-enhanced-nav", "allow"); 196if (httpContext.Response.HasStarted) 216httpContext.Response.Headers.Add("blazor-enhanced-nav-redirect-location", 222httpContext.Response.Redirect(navigationException.Location);
Rendering\EndpointHtmlRenderer.Streaming.cs (4)
32httpContext.Response.Headers.Add(_streamingRenderingFramingHeaderName, id); 89await _httpContext.Response.CompleteAsync(); 269if (!_httpContext.Response.HasStarted && marker.Type is ComponentMarker.ServerMarkerType or ComponentMarker.AutoMarkerType) 271_httpContext.Response.Headers.CacheControl = "no-cache, no-store, max-age=0";
Results\RazorComponentResultExecutor.cs (2)
26var response = httpContext.Response; 64await using var writer = new HttpResponseStreamWriter(httpContext.Response.Body, Encoding.UTF8, defaultBufferSize, ArrayPool<byte>.Shared, ArrayPool<char>.Shared);
src\Components\Shared\src\CacheHeaderSettings.cs (1)
19var headers = ctx.Context.Response.GetTypedHeaders();
Microsoft.AspNetCore.Components.Endpoints.Tests (2)
EndpointHtmlRendererTest.cs (2)
323Assert.Equal("no-cache, no-store, max-age=0", httpContext.Response.Headers.CacheControl); 367Assert.Equal("no-cache, no-store, max-age=0", httpContext.Response.Headers.CacheControl);
Microsoft.AspNetCore.Components.Server (6)
Builder\ServerRazorComponentsEndpointConventionBuilderExtensions.cs (1)
58var headers = context.Response.Headers;
CircuitDisconnectMiddleware.cs (3)
36context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed; 43context.Response.StatusCode = StatusCodes.Status400BadRequest; 49context.Response.StatusCode = StatusCodes.Status200OK;
CircuitJavaScriptInitializationMiddleware.cs (1)
23await context.Response.WriteAsJsonAsync(_initializers);
src\Components\Shared\src\CacheHeaderSettings.cs (1)
19var headers = ctx.Context.Response.GetTypedHeaders();
Microsoft.AspNetCore.Components.WebAssembly.Server (26)
Builder\WebAssemblyRazorComponentsEndpointConventionBuilderExtensions.cs (2)
44httpContext.Response.Headers["Cross-Origin-Embedder-Policy"] = "require-corp"; 45httpContext.Response.Headers["Cross-Origin-Opener-Policy"] = "same-origin";
ComponentsWebAssemblyApplicationBuilderExtensions.cs (5)
48context.Response.Headers.Append("Blazor-Environment", webHostEnvironment.EnvironmentName); 55context.Response.Headers.Append("DOTNET-MODIFIABLE-ASSEMBLIES", s_dotnetModifiableAssemblies); 62context.Response.Headers.Append("ASPNETCORE-BROWSER-TOOLS", s_aspnetcoreBrowserTools); 107fileContext.Context.Response.Headers.Append(HeaderNames.CacheControl, "no-cache"); 123fileContext.Context.Response.ContentType = originalContentType;
ContentEncodingNegotiator.cs (2)
91context.Response.Headers.ContentEncoding = selectedEncoding.Value; 92context.Response.Headers.Append(HeaderNames.Vary, HeaderNames.ContentEncoding);
src\Components\Shared\src\CacheHeaderSettings.cs (1)
19var headers = ctx.Context.Response.GetTypedHeaders();
TargetPickerUi.cs (14)
113context.Response.ContentType = "text/html"; 125context.Response.StatusCode = 404; 126await context.Response.WriteAsync($@"WARNING: 197context.Response.StatusCode = 404; 198await context.Response.WriteAsync("WARNING: Open about:debugging tab before pressing Debugging Hotkey"); 265context.Response.ContentType = "text/html"; 279await context.Response.WriteAsync($@" 310context.Response.Redirect(devToolsUrlWithProxy); 314await context.Response.WriteAsync("<h1>No inspectable pages found</h1>"); 319await context.Response.WriteAsync($"<p>The list of targets returned by {WebUtility.HtmlEncode(debuggerTabsListUrl)} contains no entries{suffix}.</p>"); 320await context.Response.WriteAsync("<p>Make sure your browser is displaying the target application.</p>"); 324await context.Response.WriteAsync("<h1>Inspectable pages</h1>"); 325await context.Response.WriteAsync(@" 357await context.Response.WriteAsync(
WebAssemblyNetDebugProxyAppBuilderExtensions.cs (2)
60context.Response.Redirect($"{debugProxyBaseUrl}{browserUrl!.PathAndQuery}"); 63context.Response.StatusCode = (int)HttpStatusCode.NotFound;
Microsoft.AspNetCore.ConcurrencyLimiter (1)
ConcurrencyLimiterMiddleware.cs (1)
81context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
Microsoft.AspNetCore.CookiePolicy (2)
ResponseCookiesWrapper.cs (2)
69if (!HasConsent && !Context.Response.HasStarted) 81if (HasConsent && !Context.Response.HasStarted)
Microsoft.AspNetCore.CookiePolicy.Test (94)
CookieChunkingTests.cs (12)
18var values = context.Response.Headers["Set-Cookie"]; 41var values = context.Response.Headers["Set-Cookie"]; 53var values = context.Response.Headers["Set-Cookie"]; 72var values = context.Response.Headers["Set-Cookie"]; 100var values = context.Response.Headers["Set-Cookie"]; 131var values = context.Response.Headers["Set-Cookie"]; 214var cookies = context.Response.Headers["Set-Cookie"]; 236var cookies = context.Response.Headers["Set-Cookie"]; 254var cookies = context.Response.Headers["Set-Cookie"]; 290httpContext.Response.Headers[HeaderNames.SetCookie] = new[] 303Assert.Equal(8, httpContext.Response.Headers[HeaderNames.SetCookie].Count); 314}, httpContext.Response.Headers[HeaderNames.SetCookie]);
CookieConsentTests.cs (51)
27context.Response.Cookies.Append("Test", "Value"); 30Assert.Equal("Test=Value; path=/", httpContext.Response.Headers.SetCookie); 46context.Response.Cookies.Append("Test", "Value"); 49Assert.Equal(0, httpContext.Response.Headers.SetCookie.Count); 65context.Response.Cookies.Append("Test", "Value", new CookieOptions() { IsEssential = false }); 68Assert.Equal(0, httpContext.Response.Headers.SetCookie.Count); 91context.Response.Cookies.Append("Test", "Value", new CookieOptions() { IsEssential = false }); 94Assert.Equal("Test=Value; path=/", httpContext.Response.Headers.SetCookie); 110context.Response.Cookies.Append("Test", "Value", new CookieOptions() { IsEssential = true }); 113Assert.Equal("Test=Value; path=/", httpContext.Response.Headers.SetCookie); 140context.Response.Cookies.Append("Test", "Value", new CookieOptions() { IsEssential = true }); 143Assert.Equal(0, httpContext.Response.Headers.SetCookie.Count); 163context.Response.Cookies.Append("Test", "Value"); 166Assert.Equal("Test=Value; path=/", httpContext.Response.Headers.SetCookie); 186context.Response.Cookies.Append("Test", "Value"); 189Assert.Equal(0, httpContext.Response.Headers.SetCookie.Count); 213context.Response.Cookies.Append("Test", "Value"); 217var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); 267var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); 301context.Response.Cookies.Append("Test", "Value"); 305Assert.Equal("Test=Value; path=/", httpContext.Response.Headers.SetCookie); 323await context.Response.WriteAsync("Started."); 331Assert.Throws<InvalidOperationException>(() => context.Response.Cookies.Append("Test", "Value")); 333await context.Response.WriteAsync("Granted."); 336var reader = new StreamReader(httpContext.Response.Body); 338Assert.Equal(0, httpContext.Response.Headers.SetCookie.Count); 362context.Response.Cookies.Append("Test", "Value"); 366Assert.Equal(0, httpContext.Response.Headers.SetCookie.Count); 386context.Response.Cookies.Append("Test", "Value1"); 394context.Response.Cookies.Append("Test", "Value2"); 398var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); 445var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); 471context.Response.Cookies.Append("Test", "Value1"); 473await context.Response.WriteAsync("Started."); 482context.Response.Cookies.Append("Test", "Value2"); 484await context.Response.WriteAsync("Withdrawn."); 487var reader = new StreamReader(httpContext.Response.Body); 489Assert.Equal("Test=Value1; path=/", httpContext.Response.Headers.SetCookie); 506context.Response.Cookies.Delete("Test"); 510var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); 540context.Response.Cookies.Delete("Test"); 544Assert.Equal(0, httpContext.Response.Headers.SetCookie.Count); 569context.Response.Headers["ManualCookie"] = cookie; 574var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); 582cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers["ManualCookie"]); 622context.Response.Headers["ManualCookie"] = cookie; 627var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); 635cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers["ManualCookie"]); 667context.Response.Headers["ManualCookie"] = cookie; 672var cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers.SetCookie); 680cookies = SetCookieHeaderValue.ParseList(httpContext.Response.Headers["ManualCookie"]);
CookiePolicyTests.cs (27)
23context.Response.Cookies.Append("A", "A"); 24context.Response.Cookies.Append("B", "B", new CookieOptions { Secure = false }); 25context.Response.Cookies.Append("C", "C", new CookieOptions()); 26context.Response.Cookies.Append("D", "D", new CookieOptions { Secure = true }); 31context.Response.Cookies.Append("A", "A"); 32context.Response.Cookies.Append("B", "B", new CookieOptions { HttpOnly = false }); 33context.Response.Cookies.Append("C", "C", new CookieOptions()); 34context.Response.Cookies.Append("D", "D", new CookieOptions { HttpOnly = true }); 39context.Response.Cookies.Append("A", "A"); 40context.Response.Cookies.Append("B", "B", new CookieOptions()); 41context.Response.Cookies.Append("C", "C", new CookieOptions { SameSite = Http.SameSiteMode.None }); 42context.Response.Cookies.Append("D", "D", new CookieOptions { SameSite = Http.SameSiteMode.Lax }); 43context.Response.Cookies.Append("E", "E", new CookieOptions { SameSite = Http.SameSiteMode.Strict }); 44context.Response.Cookies.Append("F", "F", new CookieOptions { SameSite = (Http.SameSiteMode)(-1) }); 257context.Response.Cookies.Append("A", "A"); 258context.Response.Cookies.Append("B", "B", new CookieOptions { Secure = false }); 259context.Response.Cookies.Append("C", "C", new CookieOptions() { SameSite = Http.SameSiteMode.Strict }); 260context.Response.Cookies.Append("D", "D", new CookieOptions { Secure = true }); 296context.Response.Cookies.Delete("A"); 297context.Response.Cookies.Delete("B", new CookieOptions { Secure = false }); 298context.Response.Cookies.Delete("C", new CookieOptions()); 299context.Response.Cookies.Delete("D", new CookieOptions { Secure = true }); 338Assert.Throws<NotImplementedException>(() => context.Response.Cookies.Delete("A")); 339Assert.Throws<NotImplementedException>(() => context.Response.Cookies.Delete("A", new CookieOptions())); 340Assert.Throws<NotImplementedException>(() => context.Response.Cookies.Append("A", "A")); 341Assert.Throws<NotImplementedException>(() => context.Response.Cookies.Append("A", "A", new CookieOptions())); 342return context.Response.WriteAsync("Done");
src\Shared\ChunkingCookieManager\ChunkingCookieManager.cs (4)
151var responseCookies = context.Response.Cookies; 274var responseHeaders = context.Response.Headers; 294var responseCookies = context.Response.Cookies; 332context.Response.Cookies.Append(keyValuePairs.ToArray(), new CookieOptions(options)
Microsoft.AspNetCore.Cors (5)
Infrastructure\CorsMiddleware.cs (5)
125context.Response.StatusCode = StatusCodes.Status204NoContent; 179CorsService.ApplyResult(corsResult, context.Response); 183context.Response.StatusCode = StatusCodes.Status204NoContent; 188context.Response.OnStarting(OnResponseStartingDelegate, Tuple.Create(this, context, corsResult)); 198middleware.CorsService.ApplyResult(result, context.Response);
Microsoft.AspNetCore.Cors.Test (13)
CorsMiddlewareTests.cs (13)
39await context.Response.WriteAsync("Cross origin response"); 81await context.Response.WriteAsync("Cross origin response"); 126await context.Response.WriteAsync("Cross origin response"); 175await context.Response.WriteAsync("Cross origin response"); 240await context.Response.WriteAsync("Cross origin response"); 309await context.Response.WriteAsync("Cross origin response"); 352await context.Response.WriteAsync("Cross origin response"); 448await context.Response.WriteAsync("Cross origin response"); 525context.Response.Headers.Add("Test", "Should-Appear"); 526await context.Response.WriteAsync("Cross origin response"); 588context.Response.Clear(); 589context.Response.StatusCode = 500; 601context.Response.Headers.Add("Test", "Should-Not-Exist");
Microsoft.AspNetCore.Diagnostics (37)
DeveloperExceptionPage\DeveloperExceptionPageMiddlewareImpl.cs (9)
125if (!context.Response.HasStarted) 127context.Response.StatusCode = StatusCodes.Status499ClientClosedRequest; 140if (context.Response.HasStarted) 151context.Response.Clear(); 156context.Response.StatusCode = badHttpRequestException.StatusCode; 160context.Response.StatusCode = 500; 235httpContext.Response.ContentType = "text/plain; charset=utf-8"; 247await httpContext.Response.WriteAsync(sb.ToString()); 257Status = httpContext.Response.StatusCode
ExceptionHandler\ExceptionHandlerMiddlewareImpl.cs (10)
121if (!context.Response.HasStarted) 123context.Response.StatusCode = StatusCodes.Status499ClientClosedRequest; 133if (context.Response.HasStarted) 168context.Response.StatusCode = _options.StatusCodeSelector?.Invoke(edi.SourceException) ?? DefaultStatusCode; 169context.Response.OnStarting(_clearCacheHeadersDelegate, context.Response); 195ProblemDetails = { Status = context.Response.StatusCode }, 205if (context.Response.HasStarted || handled || _options.StatusCodeSelector != null || context.Response.StatusCode != StatusCodes.Status404NotFound || _options.AllowStatusCode404Response) 246context.Response.Clear();
src\Shared\Diagnostics\BaseView.cs (1)
65Response = Context.Response;
src\Shared\RazorViews\BaseView.cs (1)
84Response = Context.Response;
StatusCodePage\StatusCodePagesExtensions.cs (8)
78var body = string.Format(CultureInfo.InvariantCulture, bodyFormat, context.HttpContext.Response.StatusCode); 79context.HttpContext.Response.ContentType = contentType; 80return context.HttpContext.Response.WriteAsync(body); 101var location = string.Format(CultureInfo.InvariantCulture, locationFormat, context.HttpContext.Response.StatusCode); 102context.HttpContext.Response.Redirect(context.HttpContext.Request.PathBase + location); 110var location = string.Format(CultureInfo.InvariantCulture, locationFormat, context.HttpContext.Response.StatusCode); 111context.HttpContext.Response.Redirect(location); 167var originalStatusCode = context.HttpContext.Response.StatusCode;
StatusCodePage\StatusCodePagesMiddleware.cs (5)
67if (context.Response.HasStarted 68|| context.Response.StatusCode < 400 69|| context.Response.StatusCode >= 600 70|| context.Response.ContentLength.HasValue 71|| !string.IsNullOrEmpty(context.Response.ContentType))
StatusCodePage\StatusCodePagesOptions.cs (3)
25var statusCode = context.HttpContext.Response.StatusCode; 34context.HttpContext.Response.ContentType = "text/plain"; 35await context.HttpContext.Response.WriteAsync(body);
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (8)
DatabaseDeveloperPageExceptionFilter.cs (1)
95var response = errorContext.HttpContext.Response;
MigrationsEndPointMiddleware.cs (5)
78context.Response.StatusCode = (int)HttpStatusCode.NoContent; 79context.Response.Headers.Add("Pragma", new[] { "no-cache" }); 80context.Response.Headers.Add("Cache-Control", new[] { "no-cache,no-store" }); 104await WriteErrorToResponse(context.Response, Strings.MigrationsEndPointMiddleware_NoContextType); 121await WriteErrorToResponse(context.Response, message);
src\Shared\Diagnostics\BaseView.cs (1)
65Response = Context.Response;
src\Shared\RazorViews\BaseView.cs (1)
84Response = Context.Response;
Microsoft.AspNetCore.Diagnostics.HealthChecks (7)
HealthCheckMiddleware.cs (2)
59httpContext.Response.StatusCode = statusCode; 64var headers = httpContext.Response.Headers;
HealthCheckResponseWriters.cs (5)
18httpContext.Response.ContentType = "text/plain"; 21HealthStatus.Degraded => httpContext.Response.Body.WriteAsync(DegradedBytes.AsMemory()).AsTask(), 22HealthStatus.Healthy => httpContext.Response.Body.WriteAsync(HealthyBytes.AsMemory()).AsTask(), 23HealthStatus.Unhealthy => httpContext.Response.Body.WriteAsync(UnhealthyBytes.AsMemory()).AsTask(), 24_ => httpContext.Response.WriteAsync(result.Status.ToString())
Microsoft.AspNetCore.Diagnostics.HealthChecks.Tests (4)
HealthCheckEndpointRouteBuilderExtensionsTest.cs (2)
103context.Response.ContentType = "text/plain"; 104await context.Response.WriteAsync("Custom!");
HealthCheckMiddlewareTests.cs (2)
308c.Response.ContentType = "application/json"; 309return c.Response.WriteAsync(json);
Microsoft.AspNetCore.Diagnostics.Middleware (10)
Latency\AddServerTimingHeaderMiddleware.cs (4)
33context.Response.OnStarting(static ctx => 42if (httpContext.Response.Headers.TryGetValue(ServerTimingHeaderName, out var existing)) 44httpContext.Response.Headers[ServerTimingHeaderName] = $"{existing}, reqlatency;dur={elapsedMs}"; 48httpContext.Response.Headers.Append(ServerTimingHeaderName, $"reqlatency;dur={elapsedMs}");
Latency\CaptureResponseTimeMiddleware.cs (2)
39context.Response.OnStarting(l => 47context.Response.OnCompleted(l =>
Latency\RequestLatencyTelemetryMiddleware.cs (3)
63context.Response.OnStarting(ctx => 68httpContext.Response.Headers[TelemetryConstants.ServerApplicationNameHeader] = _applicationName; 74context.Response.OnCompleted(async l =>
Logging\HttpLoggingRedactionInterceptor.cs (1)
141_responseHeadersReader.Read(context.Response.Headers, logContext.Parameters);
Microsoft.AspNetCore.Diagnostics.Middleware.Tests (17)
Latency\AcceptanceTests.cs (1)
72await context.Response.WriteAsync("Hello World!");
Latency\ChecpointAcceptanceTests.cs (3)
58app.UseEndpoints(endpoints => endpoints.MapGet("/", async context => await context.Response.WriteAsync("Hello World!"))); 92ctx.Response.Headers.Append("Server-Timing", alreadySetServerTimingHeader); 99app.UseEndpoints(endpoints => endpoints.MapGet("/", async context => await context.Response.WriteAsync("Hello World!")));
Latency\RequestLatencyTelemetryMiddlewareTests.cs (6)
44var header = httpContextMock.Response.Headers[TelemetryConstants.ServerApplicationNameHeader]; 74Assert.False(httpContextMock.Response.Headers.TryGetValue(TelemetryConstants.ServerApplicationNameHeader, out var val)); 98httpContextMock.Response.Headers.Append(TelemetryConstants.ServerApplicationNameHeader, "testValue"); 102var header = httpContextMock.Response.Headers[TelemetryConstants.ServerApplicationNameHeader]; 133Assert.False(httpContextMock.Response.Headers.TryGetValue(TelemetryConstants.ServerApplicationNameHeader, out var val)); 180await httpContextMock.Response.CompleteAsync();
Logging\AcceptanceTests.cs (7)
67context.Response.StatusCode = StatusCodes.Status400BadRequest; 72context.Response.ContentType = MediaTypeNames.Text.Plain; 73await context.Response.WriteAsync("test body"); 89context.Response.ContentType = MediaTypeNames.Text.Plain; 90context.Response.Headers.Append(HeaderNames.TransferEncoding, "chunked"); 91await context.Response.WriteAsync("Server: hello!").ConfigureAwait(false); 94await context.Response.WriteAsync("Server: world!").ConfigureAwait(false);
Microsoft.AspNetCore.Diagnostics.Tests (71)
DeveloperExceptionPageMiddlewareTest.cs (3)
653return context.HttpContext.Response.WriteAsync(context.Exception.Message); 661return context.HttpContext.Response.WriteAsync(context.Exception.ToString()); 669return context.HttpContext.Response.WriteAsync("An error occurred");
ExceptionHandlerMiddlewareTest.cs (1)
431c.Response.StatusCode = 404;
ExceptionHandlerTest.cs (56)
43await httpContext.Response.WriteAsync("Handled error in a custom way."); 49context.Response.StatusCode = (int)expectedStatusCode; 50context.Response.ContentType = "text/plain; charset=utf-8"; 51await context.Response.WriteAsync("An error occurred while adding a product"); 99await httpContext.Response.WriteAsync("Handled error in a custom way."); 105await httpContext.Response.WriteAsync("Hello"); 136var response = httpContext.Response; 160Assert.True(httpContext.Response.Body.CanSeek); 161Assert.Equal(0, httpContext.Response.Body.Position); 163await httpContext.Response.WriteAsync(expectedResponseBody); 170await context.Response.WriteAsync(new string('a', 100)); 216httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=600" }); 217httpContext.Response.Headers.Add("Pragma", new[] { "max-age=600" }); 218httpContext.Response.Headers.Add( 220httpContext.Response.Headers.Add("ETag", new[] { "12345" }); 222await httpContext.Response.WriteAsync(expectedResponseBody); 272await httpContext.Response.WriteAsync("Handled error in a custom way."); 278httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=3600" }); 279httpContext.Response.Headers.Add("Pragma", new[] { "max-age=3600" }); 280httpContext.Response.Headers.Add("Expires", new[] { expiresTime }); 281httpContext.Response.Headers.Add("ETag", new[] { "abcdef" }); 283await httpContext.Response.WriteAsync(expectedResponseBody); 343httpContext.Response.StatusCode = StatusCodes.Status404NotFound; 344await httpContext.Response.WriteAsync("Custom 404"); 350httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=3600" }); 351httpContext.Response.Headers.Add("Pragma", new[] { "max-age=3600" }); 352httpContext.Response.Headers.Add("Expires", new[] { DateTime.UtcNow.AddDays(10).ToString("R") }); 353httpContext.Response.Headers.Add("ETag", new[] { "abcdef" }); 412await httpContext.Response.WriteAsync("Handled error in a custom way."); 418httpContext.Response.Headers.Add("Cache-Control", new[] { "max-age=3600" }); 419httpContext.Response.Headers.Add("Pragma", new[] { "max-age=3600" }); 420httpContext.Response.Headers.Add("Expires", new[] { expiresTime }); 421httpContext.Response.Headers.Add("ETag", new[] { "abcdef" }); 423await httpContext.Response.WriteAsync("Hello"); 474await httpContext.Response.WriteAsync("Handled error in a custom way."); 558httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; 580await httpContext.Response.WriteAsync("Handled error in a custom way."); 624httpContext.Response.StatusCode = StatusCodes.Status404NotFound; 749c.Response.StatusCode = 200; 750return c.Response.WriteAsync("separate pipeline"); 805c.Response.StatusCode = 200; 806return c.Response.WriteAsync("Handled"); 859c.Response.StatusCode = 200; 860return c.Response.WriteAsync("Handled"); 911c.Response.StatusCode = 200; 912return c.Response.WriteAsync("Handled"); 960httpContext.Response.StatusCode = StatusCodes.Status404NotFound; 961return httpContext.Response.WriteAsync("Custom handler"); 969c.Response.StatusCode = 200; 970return c.Response.WriteAsync("Handled"); 1012httpContext.Response.StatusCode = StatusCodes.Status404NotFound; 1013return httpContext.Response.WriteAsync("Custom handler"); 1067httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; 1082httpContext.Response.StatusCode = StatusCodes.Status404NotFound; 1145httpContext.Response.StatusCode = StatusCodes.Status404NotFound; 1146return httpContext.Response.WriteAsync("Custom handler");
StatusCodeMiddlewareTest.cs (11)
35httpContext.Response.StatusCode = expectedStatusCode; 44await httpContext.Response.WriteAsync(httpContext.Request.QueryString.Value); 97httpContext.Response.StatusCode = expectedStatusCode; 107await httpContext.Response.WriteAsync( 159httpContext.Response.StatusCode = expectedStatusCode; 169await httpContext.Response.WriteAsync( 215httpContext.Response.StatusCode = expectedStatusCode; 262c.Response.StatusCode = 404; 298c.Response.StatusCode = 404; 334c.Response.StatusCode = 400; 372c.Response.StatusCode = 400;
Microsoft.AspNetCore.FunctionalTests (1)
WebHostFunctionalTests.cs (1)
122using (var webHost = WebHost.Start("http://127.0.0.1:0", context => context.Response.WriteAsync("Hello, World!")))
Microsoft.AspNetCore.Grpc.JsonTranscoding (13)
Internal\CallHandlers\UnaryServerCallHandler.cs (1)
49await serverCallContext.HttpContext.Response.Body.WriteAsync(httpBody.Data.Memory);
Internal\HttpContextStreamWriter.cs (2)
89await _context.HttpContext.Response.Body.WriteAsync(httpBody.Data.Memory, cancellationToken); 97await _context.HttpContext.Response.Body.WriteAsync(GrpcProtocolConstants.StreamingDelimiter, cancellationToken);
Internal\JsonRequestHelpers.cs (1)
373var response = serverCallContext.HttpContext.Response;
Internal\JsonTranscodingServerCallContext.cs (9)
129await JsonRequestHelpers.SendErrorResponse(HttpContext.Response, RequestEncoding, ResponseTrailers, status, options); 132await HttpContext.Response.Body.WriteAsync(GrpcProtocolConstants.StreamingDelimiter); 209if (HttpContext.Response.HasStarted) 220HttpContext.Response.Headers[entry.Key] = Convert.ToBase64String(entry.ValueBytes); 224HttpContext.Response.Headers[entry.Key] = entry.Value; 231return HttpContext.Response.BodyWriter.FlushAsync().GetAsTask(); 236if (!HttpContext.Response.HasStarted) 238HttpContext.Response.StatusCode = StatusCodes.Status200OK; 239HttpContext.Response.ContentType = contentType ?? MediaType.ReplaceEncoding("application/json", RequestEncoding);
Microsoft.AspNetCore.HostFiltering (4)
HostFilteringMiddleware.cs (4)
68context.Response.StatusCode = 400; 72context.Response.ContentLength = DefaultResponse.Length; 73context.Response.ContentType = "text/html"; 74return context.Response.Body.WriteAsync(DefaultResponse, 0, DefaultResponse.Length);
Microsoft.AspNetCore.Hosting (15)
Internal\ErrorPageBuilder.cs (4)
30context.Response.StatusCode = 500; 31context.Response.Headers.CacheControl = "no-cache,no-store"; 32context.Response.Headers.Pragma = "no-cache"; 33context.Response.ContentType = "text/html; charset=utf-8";
Internal\HostingApplicationDiagnostics.cs (5)
169httpContext.Response.StatusCode, 232if (httpContext.Response.StatusCode >= 500) 335[DynamicDependency(nameof(HttpContext.Response), typeof(HttpContext))] 356[DynamicDependency(nameof(HttpContext.Response), typeof(HttpContext))] 466[DynamicDependency(nameof(HttpContext.Response), typeof(HttpContext))]
Internal\HostingRequestFinishedLog.cs (2)
31var response = _context.HttpContext.Response; 65var response = _context.HttpContext.Response;
Internal\HostingRequestUnhandledLog.cs (3)
285 => new KeyValuePair<string, object?>(nameof(_httpContext.Response.StatusCode), _httpContext.Response.StatusCode), 43var response = _httpContext.Response;
src\Shared\RazorViews\BaseView.cs (1)
84Response = Context.Response;
Microsoft.AspNetCore.Hosting.Tests (3)
WebHostBuilderTests.cs (3)
97return context.Response.WriteAsync("This wins"); 115app.Run(context => context.Response.WriteAsync("UseStartupFactoryWorks")); 851app.Run(context => context.Response.WriteAsync("Configure"));
Microsoft.AspNetCore.Hosting.TestSites (1)
StartupShutdown.cs (1)
35return context.Response.WriteAsync("Hello World");
Microsoft.AspNetCore.Http (12)
Builder\ApplicationBuilder.cs (2)
184if (!context.Response.HasStarted) 186context.Response.StatusCode = StatusCodes.Status404NotFound;
Features\FormFeature.cs (1)
255_request.HttpContext.Response.RegisterForDispose,
Features\RequestBodyPipeFeature.cs (1)
41_context.Response.OnCompleted((self) =>
Features\RequestServicesFeature.cs (1)
37_context.Response.RegisterForDisposeAsync(this);
Internal\BufferingHelper.cs (1)
22request.HttpContext.Response.RegisterForDispose(fileStream);
src\Shared\Debugger\HttpContextDebugFormatter.cs (2)
73sb.Append(context.Response.StatusCode); 74var resolvedReasonPhrase = ResolveReasonPhrase(context.Response, reasonPhrase);
Timeouts\CancellationTokenLinker.cs (1)
16httpContext.Response.RegisterForDispose(timeoutCts);
Timeouts\RequestTimeoutsMiddleware.cs (3)
112if (context.Response.HasStarted) 120context.Response.Clear(); 122context.Response.StatusCode = selectedPolicy?.TimeoutStatusCode ?? StatusCodes.Status504GatewayTimeout;
Microsoft.AspNetCore.Http.Abstractions.Tests (29)
HttpResponseWritingExtensionsTests.cs (11)
14await context.Response.WriteAsync("Hello World"); 16Assert.Equal(11, context.Response.Body.Length); 23await context.Response.WriteAsync("Hello World"); 24await context.Response.WriteAsync("Hello World"); 26Assert.Equal(22, context.Response.Body.Length); 36context.Response.Body = outputStream; 40await context.Response.WriteAsync(inputString, encoding); 58await context.Response.WriteAsync(inputString, encoding); 60context.Response.Body.Position = 0; 62var length = context.Response.Body.Read(actual); 87context.Response.Body = new MemoryStream();
MapPathMiddlewareTests.cs (10)
14context.Response.StatusCode = 200; 62Assert.Equal(200, context.Response.StatusCode); 92Assert.Equal(200, context.Response.StatusCode); 120Assert.Equal(200, context.Response.StatusCode); 151Assert.Equal(200, context.Response.StatusCode); 173Assert.Equal(200, context.Response.StatusCode); 195Assert.Equal(200, context.Response.StatusCode); 201Assert.Equal(404, context.Response.StatusCode); 207Assert.Equal(200, context.Response.StatusCode); 213Assert.Equal(200, context.Response.StatusCode);
MapPredicateMiddlewareTests.cs (5)
16context.Response.StatusCode = 200; 68Assert.Equal(200, context.Response.StatusCode); 80Assert.Equal(200, context.Response.StatusCode); 93Assert.Equal(200, context.Response.StatusCode); 110Assert.Equal(200, context.Response.StatusCode);
UsePathBaseExtensionsTests.cs (3)
154endpoints.Map("/path", context => context.Response.WriteAsync("Response")); 177app.MapGet("/path", context => context.Response.WriteAsync("Response")); 197app.MapGet("/path", context => context.Response.WriteAsync("Response"));
Microsoft.AspNetCore.Http.Connections (75)
Internal\HttpConnectionContext.cs (13)
462nonClonedContext.Response.ContentType = "application/octet-stream"; 465nonClonedContext.Response.ContentLength = 0; 472await nonClonedContext.Response.Body.FlushAsync(); 487nonClonedContext.Response.RegisterForDispose(timeoutSource); 488nonClonedContext.Response.RegisterForDispose(tokenSource); 517nonClonedContext.Response.StatusCode = StatusCodes.Status409Conflict; 518nonClonedContext.Response.ContentType = "text/plain"; 527nonClonedContext.Response.StatusCode = StatusCodes.Status404NotFound; 528nonClonedContext.Response.ContentType = "text/plain"; 561context.Response.ContentType = "text/plain"; 562context.Response.StatusCode = StatusCodes.Status204NoContent; 575context.Response.ContentType = "text/plain"; 576context.Response.StatusCode = StatusCodes.Status204NoContent;
Internal\HttpConnectionDispatcher.cs (41)
96context.Response.ContentType = "text/plain"; 97context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed; 115context.Response.ContentType = "text/plain"; 116context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed; 182AddNoCacheHeaders(context.Response); 272if (context.Response.StatusCode == StatusCodes.Status204NoContent) 338context.Response.ContentType = "application/json"; 397context.Response.ContentLength = writer.Length; 398await writer.CopyToAsync(context.Response.Body); 458context.Response.ContentType = "text/plain"; 463context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed; 464await context.Response.WriteAsync("POST requests are not allowed for WebSocket connections."); 479context.Response.StatusCode = StatusCodes.Status404NotFound; 480context.Response.ContentType = "text/plain"; 497context.Response.StatusCode = StatusCodes.Status404NotFound; 498context.Response.ContentType = "text/plain"; 506context.Response.StatusCode = StatusCodes.Status404NotFound; 507context.Response.ContentType = "text/plain"; 523context.Response.StatusCode = StatusCodes.Status400BadRequest; 524context.Response.ContentType = "text/plain"; 555context.Response.StatusCode = StatusCodes.Status400BadRequest; 556context.Response.ContentType = "text/plain"; 557await context.Response.WriteAsync("Cannot terminate this connection using the DELETE endpoint."); 566context.Response.StatusCode = StatusCodes.Status202Accepted; 567context.Response.ContentType = "text/plain"; 574context.Response.ContentType = "text/plain"; 575context.Response.StatusCode = StatusCodes.Status404NotFound; 577await context.Response.WriteAsync($"{transportType} transport not supported by this end point type"); 590context.Response.StatusCode = StatusCodes.Status409Conflict; 591context.Response.ContentType = "text/plain"; 595context.Response.ContentType = "text/plain"; 596context.Response.StatusCode = StatusCodes.Status400BadRequest; 598await context.Response.WriteAsync("Cannot change transports mid-connection"); 780context.Response.StatusCode = StatusCodes.Status400BadRequest; 781context.Response.ContentType = "text/plain"; 782await context.Response.WriteAsync("Connection ID required"); 790context.Response.StatusCode = StatusCodes.Status404NotFound; 791context.Response.ContentType = "text/plain"; 792await context.Response.WriteAsync("No Connection with that ID"); 814context.Response.StatusCode = StatusCodes.Status404NotFound; 815await context.Response.WriteAsync("No Connection with that ID");
Internal\Transports\LongPollingServerTransport.cs (14)
44context.Response.ContentType = "text/plain"; 45context.Response.StatusCode = StatusCodes.Status204NoContent; 54context.Response.ContentLength = buffer.Length; 55context.Response.ContentType = "application/octet-stream"; 58await context.Response.Body.WriteAsync(buffer, _connection?.SendingToken ?? default); 86context.Response.ContentLength = 0; 87context.Response.ContentType = "text/plain"; 88context.Response.StatusCode = StatusCodes.Status200OK; 93context.Response.ContentType = "text/plain"; 94context.Response.StatusCode = StatusCodes.Status204NoContent; 101context.Response.ContentType = "text/plain"; 102context.Response.StatusCode = StatusCodes.Status204NoContent; 108context.Response.ContentType = "text/plain"; 109context.Response.StatusCode = StatusCodes.Status500InternalServerError;
Internal\Transports\ServerSentEventsServerTransport.cs (7)
33context.Response.ContentType = "text/event-stream"; 34context.Response.Headers.CacheControl = "no-cache,no-store"; 35context.Response.Headers.Pragma = "no-cache"; 41context.Response.Headers.ContentEncoding = "identity"; 47await context.Response.WriteAsync(":\r\n", cancellationToken); 48await context.Response.Body.FlushAsync(cancellationToken); 66await ServerSentEventsMessageFormatter.WriteMessageAsync(buffer, context.Response.Body, _connection?.SendingToken ?? default);
Microsoft.AspNetCore.Http.Connections.Tests (6)
HttpConnectionDispatcherTests.cs (6)
831Assert.Equal(Stream.Null, connectionHttpContext.Response.Body); 832Assert.NotNull(connectionHttpContext.Response.Headers); 833Assert.Equal("application/xml", connectionHttpContext.Response.ContentType); 3237return context.Response.WriteAsync(GenerateToken(context)); 3399return context.Response.WriteAsync(GenerateToken(context)); 3859context.Response.ContentType = "application/xml";
Microsoft.AspNetCore.Http.Extensions (30)
DefaultProblemDetailsWriter.cs (2)
56ProblemDetailsDefaults.Apply(context.ProblemDetails, httpContext.Response.StatusCode); 65return new ValueTask(httpContext.Response.WriteAsJsonAsync(
RequestDelegateFactory.cs (25)
93private static readonly MemberExpression HttpResponseExpr = Expression.Property(HttpContextExpr, typeof(HttpContext).GetProperty(nameof(HttpContext.Response))!); 117private static readonly MemberExpression FilterContextHttpContextResponseExpr = Expression.Property(FilterContextHttpContextExpr, typeof(HttpContext).GetProperty(nameof(HttpContext.Response))!); 1390httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; 1400httpContext.Response.StatusCode = ex.StatusCode; 1406httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; 1412httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; 1507httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; 1514httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; 1521httpContext.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; 1532httpContext.Response.StatusCode = ex.StatusCode; 1538httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; 1544httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; 2430await WriteJsonResponseFast(httpContext.Response, await task, jsonTypeInfo); 2435return WriteJsonResponseFast(httpContext.Response, task.GetAwaiter().GetResult(), jsonTypeInfo); 2447await WriteJsonResponse(httpContext.Response, await task, jsonTypeInfo); 2452return WriteJsonResponse(httpContext.Response, task.GetAwaiter().GetResult(), jsonTypeInfo); 2465await httpContext.Response.WriteAsync(await task); 2470return httpContext.Response.WriteAsync(task.GetAwaiter().GetResult()!); 2479return httpContext.Response.WriteAsync(text); 2535await WriteJsonResponseFast(httpContext.Response, await task, jsonTypeInfo); 2540return WriteJsonResponseFast(httpContext.Response, task.GetAwaiter().GetResult(), jsonTypeInfo); 2550await WriteJsonResponse(httpContext.Response, await task, jsonTypeInfo); 2555return WriteJsonResponse(httpContext.Response, task.GetAwaiter().GetResult(), jsonTypeInfo); 2567await httpContext.Response.WriteAsync(await task); 2572return httpContext.Response.WriteAsync(task.GetAwaiter().GetResult()!);
src\Shared\RouteHandlers\ExecuteHandlerHelper.cs (3)
22return httpContext.Response.WriteAsync(stringValue); 27return WriteJsonResponseAsync(httpContext.Response, obj, jsonTypeInfo); 33httpContext.Response.ContentType ??= "text/plain; charset=utf-8";
Microsoft.AspNetCore.Http.Extensions.Tests (76)
HttpResponseJsonExtensionsTests.cs (2)
503httpContext.Response.Headers["Test"] = "t"; 535httpContext.Response.Headers["Test"] = "t";
ProblemDetailsServiceTest.cs (1)
165=> new(context.HttpContext.Response.WriteAsJsonAsync(_content));
RequestDelegateFactoryTests.cs (3)
2403c.Response.StatusCode = 400; 3612return httpContext.Response.WriteAsync(_resultString); 3627return httpContext.Response.WriteAsync(_resultString);
RequestDelegateGenerator\CompileTimeCreationTests.cs (3)
386Assert.Equal(400, httpContext.Response.StatusCode); 561Assert.Equal(400, httpContext1.Response.StatusCode); 569Assert.Equal(400, httpContext2.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTestBase.cs (5)
234var httpResponse = httpContext.Response; 248Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 257Assert.Equal(expectedContentType, httpContext.Response.ContentType); 258Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 265Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.AsParameters.cs (1)
387Assert.Equal(400, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.BindAsync.cs (5)
61Assert.Equal(200, httpContext.Response.StatusCode); 82Assert.Equal(200, httpContext.Response.StatusCode); 111Assert.Equal(200, httpContext.Response.StatusCode); 140Assert.Equal(400, httpContext.Response.StatusCode); 141Assert.Equal(400, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.cs (6)
440Assert.Equal(200, httpContext.Response.StatusCode); 466Assert.Equal(200, httpContext.Response.StatusCode); 488Assert.Equal(400, httpContext.Response.StatusCode); 513Assert.Equal(200, httpContext.Response.StatusCode); 538Assert.Equal(200, httpContext.Response.StatusCode); 563Assert.Equal(200, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.Forms.cs (7)
343Assert.Equal(415, httpContext.Response.StatusCode); 376Assert.Equal(400, httpContext.Response.StatusCode); 880Assert.Equal(400, httpContext.Response.StatusCode); 971Assert.Equal(400, httpContext.Response.StatusCode); 972Assert.False(httpContext.Response.HasStarted); 1010Assert.Equal(200, httpContext.Response.StatusCode); 1011Assert.False(httpContext.Response.HasStarted);
RequestDelegateGenerator\RequestDelegateCreationTests.JsonBody.cs (3)
143Assert.Equal(400, httpContext.Response.StatusCode); 473Assert.Equal(400, httpContext.Response.StatusCode); 481Assert.Equal(200, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.JsonBodyOrService.cs (1)
130Assert.Equal(400, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.KeyServices.cs (1)
144Assert.Equal(StatusCodes.Status200OK, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.Logging.cs (24)
42Assert.Equal(400, httpContext.Response.StatusCode); 43Assert.False(httpContext.Response.HasStarted); 105Assert.Equal(400, httpContext.Response.StatusCode); 106Assert.False(httpContext.Response.HasStarted); 158Assert.Equal(200, httpContext.Response.StatusCode); 159Assert.False(httpContext.Response.HasStarted); 195Assert.Equal(200, httpContext.Response.StatusCode); 196Assert.False(httpContext.Response.HasStarted); 226Assert.Equal(400, httpContext.Response.StatusCode); 275Assert.Equal(200, httpContext.Response.StatusCode); 276Assert.False(httpContext.Response.HasStarted); 306Assert.Equal(400, httpContext.Response.StatusCode); 354Assert.Equal(200, httpContext.Response.StatusCode); 355Assert.False(httpContext.Response.HasStarted); 400Assert.Equal(415, httpContext.Response.StatusCode); 449Assert.Equal(415, httpContext.Response.StatusCode); 526Assert.Equal(400, httpContext.Response.StatusCode); 527Assert.False(httpContext.Response.HasStarted); 568Assert.Equal(200, httpContext.Response.StatusCode); 569Assert.False(httpContext.Response.HasStarted); 606Assert.Equal(400, httpContext.Response.StatusCode); 607Assert.False(httpContext.Response.HasStarted); 647Assert.Equal(200, httpContext.Response.StatusCode); 648Assert.False(httpContext.Response.HasStarted);
RequestDelegateGenerator\RequestDelegateCreationTests.QueryParameters.cs (3)
50httpContext.Response.Body = responseBodyStream; 66Assert.Equal(400, httpContext.Response.StatusCode); 76Assert.Equal(200, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.Responses.cs (4)
315var deserializedResponseBody = JsonSerializer.Deserialize<Todo>(((MemoryStream)httpContext.Response.Body).ToArray(), new JsonSerializerOptions 765Assert.Equal("text/plain; charset=utf-8", httpContext.Response.ContentType); 776httpContext.Response.ContentType = "binary; charset=utf-31"; 780Assert.Equal("binary; charset=utf-31", httpContext.Response.ContentType);
RequestDelegateGenerator\RequestDelegateCreationTests.RouteParameter.cs (1)
208Assert.Equal(400, httpContext.Response.StatusCode);
RequestDelegateGenerator\RequestDelegateCreationTests.SpecialTypes.cs (2)
122Assert.Equal(httpContext.Response, httpContext.Items["arg"]); 150Assert.Same(httpContext.Response, httpContext.Items["response"]);
RequestDelegateGenerator\RequestDelegateCreationTests.TryParse.cs (1)
82Assert.Equal(200, httpContext.Response.StatusCode);
RequestDelegateGenerator\RuntimeCreationTests.ComplexFormBinding.cs (1)
177Assert.Equal(StatusCodes.Status400BadRequest, httpContext.Response.StatusCode);
RequestDelegateGenerator\SharedTypes.cs (2)
977httpContext.Response.StatusCode = StatusCodes.Status410Gone; 978httpContext.Response.WriteAsync("Already gone!");
Microsoft.AspNetCore.Http.Microbenchmarks (7)
src\Http\Http.Extensions\test\RequestDelegateGenerator\RequestDelegateCreationTestBase.cs (5)
234var httpResponse = httpContext.Response; 248Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 257Assert.Equal(expectedContentType, httpContext.Response.ContentType); 258Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 265Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode);
src\Http\Http.Extensions\test\RequestDelegateGenerator\SharedTypes.cs (2)
977httpContext.Response.StatusCode = StatusCodes.Status410Gone; 978httpContext.Response.WriteAsync("Already gone!");
Microsoft.AspNetCore.Http.Results (58)
Accepted.cs (2)
69httpContext.Response.Headers.Location = Location; 73httpContext.Response.StatusCode = StatusCode;
AcceptedAtRoute.cs (2)
97httpContext.Response.Headers.Location = url; 100httpContext.Response.StatusCode = StatusCode;
AcceptedAtRouteOfT.cs (2)
111httpContext.Response.Headers.Location = url; 114httpContext.Response.StatusCode = StatusCode;
AcceptedOfT.cs (2)
81httpContext.Response.Headers.Location = Location; 89httpContext.Response.StatusCode = StatusCode;
BadRequest.cs (1)
43httpContext.Response.StatusCode = StatusCode;
BadRequestOfT.cs (1)
54httpContext.Response.StatusCode = StatusCode;
Conflict.cs (1)
43httpContext.Response.StatusCode = StatusCode;
ConflictOfT.cs (1)
54httpContext.Response.StatusCode = StatusCode;
ContentHttpResult.cs (1)
69httpContext.Response.StatusCode = statusCode;
Created.cs (2)
69httpContext.Response.Headers.Location = Location; 73httpContext.Response.StatusCode = StatusCode;
CreatedAtRoute.cs (2)
97httpContext.Response.Headers.Location = url; 100httpContext.Response.StatusCode = StatusCode;
CreatedAtRouteOfT.cs (2)
111httpContext.Response.Headers.Location = url; 114httpContext.Response.StatusCode = StatusCode;
CreatedOfT.cs (2)
80httpContext.Response.Headers.Location = Location; 88httpContext.Response.StatusCode = StatusCode;
HttpResultsHelper.cs (3)
44return httpContext.Response.WriteAsJsonAsync( 57return httpContext.Response.WriteAsJsonAsync<object>( 69var response = httpContext.Response;
InternalServerError.cs (1)
43httpContext.Response.StatusCode = StatusCode;
InternalServerErrorOfT.cs (1)
54httpContext.Response.StatusCode = StatusCode;
JsonHttpResultOfT.cs (3)
100httpContext.Response.StatusCode = statusCode; 115return httpContext.Response.WriteAsJsonAsync( 121return httpContext.Response.WriteAsJsonAsync(
NoContent.cs (1)
43httpContext.Response.StatusCode = StatusCode;
NotFound.cs (1)
42httpContext.Response.StatusCode = StatusCode;
NotFoundOfT.cs (1)
53httpContext.Response.StatusCode = StatusCode;
Ok.cs (1)
42httpContext.Response.StatusCode = StatusCode;
OkOfT.cs (1)
53httpContext.Response.StatusCode = StatusCode;
PhysicalFileHttpResult.cs (1)
142var response = httpContext.Response;
ProblemHttpResult.cs (1)
60httpContext.Response.StatusCode = code;
PushStreamHttpResult.cs (1)
121_streamWriterCallback(httpContext.Response.Body);
RedirectHttpResult.cs (3)
111httpContext.Response.StatusCode = Permanent 114httpContext.Response.Headers.Location = destinationUrl; 118httpContext.Response.Redirect(destinationUrl, Permanent);
RedirectToRouteHttpResult.cs (3)
181httpContext.Response.StatusCode = Permanent ? 183httpContext.Response.Headers.Location = destinationUrl; 187httpContext.Response.Redirect(destinationUrl, Permanent);
src\Shared\ResultsHelpers\FileResultHelper.cs (5)
32var outputStream = context.Response.Body; 58var outputStream = context.Response.Body; 111var response = httpContext.Response; 292var response = httpContext.Response; 354httpContext.Response.Headers.ContentDisposition = contentDisposition.ToString();
StatusCodeHttpResult.cs (1)
46httpContext.Response.StatusCode = StatusCode;
UnauthorizedHttpResult.cs (1)
39httpContext.Response.StatusCode = StatusCode;
UnprocessableEntity.cs (1)
43httpContext.Response.StatusCode = StatusCode;
UnprocessableEntityOfT.cs (1)
54httpContext.Response.StatusCode = StatusCode;
Utf8ContentHttpResult.cs (4)
62httpContext.Response.StatusCode = statusCode; 65httpContext.Response.ContentType = ContentType ?? ContentTypeConstants.DefaultContentType; 67httpContext.Response.ContentLength = ResponseContent.Length; 68return httpContext.Response.Body.WriteAsync(ResponseContent).AsTask();
ValidationProblem.cs (1)
61httpContext.Response.StatusCode = StatusCode;
VirtualFileHttpResult.cs (1)
137var response = httpContext.Response;
Microsoft.AspNetCore.Http.Results.Tests (127)
AcceptedAtRouteOfTResultTests.cs (3)
43httpContext.Response.Body = stream; 98Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); 99Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
AcceptedAtRouteResultTests.cs (2)
52Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); 53Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
AcceptedOfTResultTests.cs (3)
22httpContext.Response.Body = stream; 44Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); 45Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
AcceptedResultTests.cs (2)
28Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); 29Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
ContentResultTests.cs (5)
30Assert.Equal("text/plain; charset=utf-16", httpContext.Response.ContentType); 113httpContext.Response.Body = memoryStream; 114httpContext.Response.ContentType = responseContentType; 120var finalResponseContentType = httpContext.Response.ContentType; 123Assert.Equal(expectedContentData.Length, httpContext.Response.ContentLength);
CreatedAtRouteOfTResultTests.cs (2)
68Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 69Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
CreatedAtRouteResultTests.cs (2)
51Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 52Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
CreatedOfTResultTests.cs (7)
57Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 58Assert.Equal(location, httpContext.Response.Headers["Location"]); 67httpContext.Response.Headers["Location"] = "/different/location/"; 74Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 75Assert.Equal(location, httpContext.Response.Headers["Location"]); 85httpContext.Response.Body = stream; 86httpContext.Response.Headers["Location"] = "/different/location/";
CreatedResultTests.cs (5)
42Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 43Assert.Equal(location, httpContext.Response.Headers["Location"]); 52httpContext.Response.Headers["Location"] = "/different/location/"; 59Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 60Assert.Equal(location, httpContext.Response.Headers["Location"]);
EmptyResultTests.cs (2)
18var memoryStream = httpContext.Response.Body as MemoryStream; 22Assert.Equal(StatusCodes.Status200OK, httpContext.Response.StatusCode);
LocalRedirectResultTests.cs (2)
72Assert.Equal(expectedPath, httpContext.Response.Headers.Location.ToString()); 73Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode);
NoContentResultTests.cs (1)
39Assert.Equal(StatusCodes.Status204NoContent, httpContext.Response.StatusCode);
NotFoundOfTResultTests.cs (1)
62Assert.Equal(StatusCodes.Status404NotFound, httpContext.Response.StatusCode);
NotFoundResultTests.cs (1)
38Assert.Equal(StatusCodes.Status404NotFound, httpContext.Response.StatusCode);
RedirectToRouteResultTests.cs (6)
47Assert.True(httpContext.Response.Headers.ContainsKey("Location"), "Location header not found"); 48Assert.Equal(locationUrl, httpContext.Response.Headers["Location"]); 65Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 66Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]); 83Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 84Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
src\Shared\ResultsTests\FileContentResultTestBase.cs (19)
35httpContext.Response.Body = outStream; 69httpContext.Response.Body = new MemoryStream(); 77var httpResponse = httpContext.Response; 109httpContext.Response.Body = new MemoryStream(); 115var httpResponse = httpContext.Response; 148httpContext.Response.Body = new MemoryStream(); 154var httpResponse = httpContext.Response; 182httpContext.Response.Body = new MemoryStream(); 188var httpResponse = httpContext.Response; 213httpContext.Response.Body = new MemoryStream(); 219var httpResponse = httpContext.Response; 244httpContext.Response.Body = new MemoryStream(); 250var httpResponse = httpContext.Response; 281httpContext.Response.Body = new MemoryStream(); 287var httpResponse = httpContext.Response; 315httpContext.Response.Body = new MemoryStream(); 321var httpResponse = httpContext.Response; 343httpContext.Response.Body = outStream; 350Assert.Equal(expectedContentType, httpContext.Response.ContentType);
src\Shared\ResultsTests\FileStreamResultTestBase.cs (24)
47httpContext.Response.Body = new MemoryStream(); 55var httpResponse = httpContext.Response; 90httpContext.Response.Body = new MemoryStream(); 96var httpResponse = httpContext.Response; 131httpContext.Response.Body = new MemoryStream(); 137var httpResponse = httpContext.Response; 168httpContext.Response.Body = new MemoryStream(); 174var httpResponse = httpContext.Response; 201httpContext.Response.Body = new MemoryStream(); 207var httpResponse = httpContext.Response; 234httpContext.Response.Body = new MemoryStream(); 240var httpResponse = httpContext.Response; 273httpContext.Response.Body = new MemoryStream(); 279var httpResponse = httpContext.Response; 309httpContext.Response.Body = new MemoryStream(); 315var httpResponse = httpContext.Response; 350httpContext.Response.Body = new MemoryStream(); 356var httpResponse = httpContext.Response; 384httpContext.Response.Body = outStream; 409httpContext.Response.Body = outStream; 417Assert.Equal(expectedContentType, httpContext.Response.ContentType); 430httpContext.Response.Body = outStream; 437Assert.Equal(200, httpContext.Response.StatusCode); 438Assert.Equal(0, httpContext.Response.Body.Length);
src\Shared\ResultsTests\PhysicalFileResultTestBase.cs (13)
53var httpResponse = httpContext.Response; 84var httpResponse = httpContext.Response; 116var httpResponse = httpContext.Response; 143var httpResponse = httpContext.Response; 171var httpResponse = httpContext.Response; 192httpContext.Response.Body = new MemoryStream(); 198var httpResponse = httpContext.Response; 221httpContext.Response.Body = new MemoryStream(); 227var httpResponse = httpContext.Response; 248httpContext.Response.Body = new MemoryStream(); 254var httpResponse = httpContext.Response; 309var httpResponse = httpContext.Response; 336Assert.Equal(expectedContentType, httpContext.Response.ContentType);
src\Shared\ResultsTests\RedirectResultTestBase.cs (4)
34Assert.Equal(expectedPath, httpContext.Response.Headers.Location.ToString()); 35Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode); 57Assert.Equal(expectedPath, httpContext.Response.Headers.Location.ToString()); 58Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode);
src\Shared\ResultsTests\VirtualFileResultTestBase.cs (15)
65var httpResponse = httpContext.Response; 102var httpResponse = httpContext.Response; 139var httpResponse = httpContext.Response; 172var httpResponse = httpContext.Response; 206var httpResponse = httpContext.Response; 228httpContext.Response.Body = new MemoryStream(); 234httpContext.Response.Body = new MemoryStream(); 240var httpResponse = httpContext.Response; 276var httpResponse = httpContext.Response; 307var httpResponse = httpContext.Response; 344var httpResponse = httpContext.Response; 371Assert.Equal(expectedContentType, httpContext.Response.ContentType); 453httpContext.Response.Body = new MemoryStream(); 459httpContext.Response.Body.Position = 0; 460var contents = await new StreamReader(httpContext.Response.Body).ReadToEndAsync();
StatusCodeResultTests.cs (1)
24Assert.Equal(StatusCodes.Status404NotFound, httpContext.Response.StatusCode);
UnauthorizedResultTests.cs (1)
34Assert.Equal(StatusCodes.Status401Unauthorized, httpContext.Response.StatusCode);
Utf8ContentResultTests.cs (6)
37context.Response.Body = ms; 44Assert.Equal(data.Length, context.Response.ContentLength); 45Assert.Equal("text/plain; charset=utf-8", context.Response.ContentType); 55context.Response.Body = ms; 62Assert.Equal(data.Length, context.Response.ContentLength); 63Assert.Equal("text/plain; charset=utf-8", context.Response.ContentType);
Microsoft.AspNetCore.Http.Tests (3)
ApplicationBuilderTests.cs (1)
115context.Response.StatusCode = StatusCodes.Status204NoContent;
DefaultHttpContextTests.cs (2)
328TestCachedFeaturesAreNull(context.Response, features); 356TestCachedFeaturesAreSet(context.Response, features);
Microsoft.AspNetCore.HttpLogging (4)
HttpLoggingMiddleware.cs (2)
186var response = context.Response; 331var response = logContext.HttpContext.Response;
ResponseBufferingStream.cs (1)
128if (MediaTypeHelpers.TryGetEncodingForMediaType(_logContext.HttpContext.Response.ContentType,
W3CLoggingMiddleware.cs (1)
191var response = context.Response;
Microsoft.AspNetCore.HttpLogging.Tests (65)
HttpLoggingMiddlewareTests.cs (58)
819c.Response.StatusCode = 200; 820c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 821c.Response.ContentType = "text/plain"; 822await c.Response.WriteAsync("test"); 842c.Response.StatusCode = 200; 843c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 844c.Response.ContentType = "text/plain"; 845await c.Response.WriteAsync("test"); 866c.Response.StatusCode = 200; 867c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 868c.Response.ContentType = "text/plain"; 869await c.Response.WriteAsync("test"); 888c.Response.StatusCode = 200; 889c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 890c.Response.ContentType = "text/plain"; 912c.Response.StatusCode = 200; 913c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 914c.Response.ContentType = "text/plain"; 915await c.Response.WriteAsync("test"); 938c.Response.StatusCode = 200; 939c.Response.Headers["Server"] = "Kestrel"; 940c.Response.ContentType = "text/plain"; 941await c.Response.WriteAsync("test"); 962c.Response.StatusCode = 200; 963c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 964c.Response.ContentType = "text/plain"; 965await c.Response.WriteAsync("test"); 986c.Response.Headers["Test"] = "Kestrel"; 1008c.Response.Headers["Test"] = "Kestrel"; 1009c.Response.Headers["Server"] = "Kestrel"; 1030c.Response.ContentType = "text/plain"; 1031return c.Response.WriteAsync(expected); 1050c.Response.ContentType = "text/plain"; 1071c.Response.ContentType = "text/plain"; 1072return c.Response.WriteAsync(input); 1096c.Response.StatusCode = 200; 1097c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 1098c.Response.ContentType = "text/plain"; 1099await c.Response.WriteAsync("test"); 1134c.Response.StatusCode = 200; 1135c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 1136c.Response.ContentType = "text/plain"; 1137await c.Response.StartAsync(); 1167c.Response.ContentType = "foo/*"; 1168return c.Response.WriteAsync(expected); 1402c.Response.StatusCode = 200; 1403c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 1404c.Response.ContentType = "text/plain"; 1405await c.Response.StartAsync(); 1511c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 1514c.Response.ContentType = "text/plain2"; 1515await c.Response.WriteAsync("test response"); 1580c.Response.Headers[HeaderNames.TransferEncoding] = "test"; 1581c.Response.ContentType = "text/plain2"; 2000context.Response.StatusCode = StatusCodes.Status418ImATeapot; 2001context.Response.ContentType = "text/plain; p=response"; 2002await context.Response.WriteAsync("Hello World"); 2046c.Response.ContentType = "text/plain";
W3CLoggingMiddlewareTests.cs (7)
48c.Response.StatusCode = 200; 75c.Response.StatusCode = 200; 117c.Response.StatusCode = 200; 161c.Response.StatusCode = 200; 192c.Response.StatusCode = 200; 237c.Response.StatusCode = 200; 281c.Response.StatusCode = 200;
Microsoft.AspNetCore.HttpsPolicy (3)
HstsMiddleware.cs (1)
76context.Response.Headers.StrictTransportSecurity = _strictTransportSecurityValue;
HttpsRedirectionMiddleware.cs (2)
109context.Response.StatusCode = _statusCode; 110context.Response.Headers.Location = redirectUrl;
Microsoft.AspNetCore.HttpsPolicy.Tests (18)
HstsMiddlewareTests.cs (8)
55return context.Response.WriteAsync("Hello world"); 102return context.Response.WriteAsync("Hello world"); 148return context.Response.WriteAsync("Hello world"); 193return context.Response.WriteAsync("Hello world"); 248return context.Response.WriteAsync("Hello world"); 303return context.Response.WriteAsync("Hello world"); 350return context.Response.WriteAsync("Hello world"); 397return context.Response.WriteAsync("Hello world");
HttpsPolicyTests.cs (1)
54return context.Response.WriteAsync("Hello world");
HttpsRedirectionMiddlewareTests.cs (9)
41return context.Response.WriteAsync("Hello world"); 96return context.Response.WriteAsync("Hello world"); 152return context.Response.WriteAsync("Hello world"); 206return context.Response.WriteAsync("Hello world"); 252return context.Response.WriteAsync("Hello world"); 295return context.Response.WriteAsync("Hello world"); 338return context.Response.WriteAsync("Hello world"); 391return context.Response.WriteAsync("Hello world"); 433return context.Response.WriteAsync("Hello world");
Microsoft.AspNetCore.Identity.InMemory.Test (1)
FunctionalTest.cs (1)
301var res = context.Response;
Microsoft.AspNetCore.Localization (1)
RequestLocalizationMiddleware.cs (1)
116var headers = context.Response.Headers;
Microsoft.AspNetCore.Localization.Routing.Tests (3)
RouteDataRequestCultureProviderTest.cs (3)
67return context.Response.WriteAsync( 119return context.Response.WriteAsync( 189return context.Response.WriteAsync(
Microsoft.AspNetCore.Mvc.Core (53)
AcceptedAtActionResult.cs (1)
90context.HttpContext.Response.Headers.Location = url;
AcceptedAtRouteResult.cs (1)
86context.HttpContext.Response.Headers.Location = url;
AcceptedResult.cs (1)
77context.HttpContext.Response.Headers.Location = Location;
CacheProfile.cs (4)
15/// <see cref="Microsoft.AspNetCore.Http.HttpContext.Response" />. 22/// the "Cache-control" header is set in the <see cref="Microsoft.AspNetCore.Http.HttpContext.Response" />. 29/// <see cref="Microsoft.AspNetCore.Http.HttpContext.Response" /> to "no-store". 36/// Gets or sets the value for the Vary header in <see cref="Microsoft.AspNetCore.Http.HttpContext.Response" />.
ControllerBase.cs (1)
47public HttpResponse Response => HttpContext?.Response!;
CreatedAtActionResult.cs (1)
90context.HttpContext.Response.Headers.Location = url;
CreatedAtRouteResult.cs (1)
86context.HttpContext.Response.Headers.Location = url;
CreatedResult.cs (1)
85context.HttpContext.Response.Headers.Location = Location;
Filters\ResponseCacheFilterExecutor.cs (1)
69var headers = context.HttpContext.Response.Headers;
Formatters\FormatFilter.cs (1)
151!string.IsNullOrEmpty(context.HttpContext.Response.ContentType))
Formatters\HttpNoContentOutputFormatter.cs (1)
36var response = context.HttpContext.Response;
Formatters\OutputFormatter.cs (1)
173var response = context.HttpContext.Response;
Formatters\StreamOutputFormatter.cs (1)
33var response = context.HttpContext.Response;
Formatters\StringOutputFormatter.cs (1)
54var response = context.HttpContext.Response;
Formatters\SystemTextJsonOutputFormatter.cs (2)
90var responseWriter = httpContext.Response.BodyWriter; 107var transcodingStream = Encoding.CreateTranscodingStream(httpContext.Response.Body, selectedEncoding, Encoding.UTF8, leaveOpen: true);
Formatters\TextOutputFormatter.cs (1)
131context.HttpContext.Response.StatusCode = statusCode;
Infrastructure\ContentResultExecutor.cs (1)
39var response = context.HttpContext.Response;
Infrastructure\DefaultApiProblemDetailsWriter.cs (1)
58context.ProblemDetails.Status ?? context.HttpContext.Response.StatusCode,
Infrastructure\LocalRedirectResultExecutor.cs (3)
54context.HttpContext.Response.StatusCode = result.Permanent ? 56context.HttpContext.Response.Headers.Location = destinationUrl; 60context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
Infrastructure\ObjectResultExecutor.cs (2)
102context.HttpContext.Response.StatusCode = statusCode; 128var responseContentType = context.HttpContext.Response.ContentType;
Infrastructure\PhysicalFileResultExecutor.cs (1)
78var response = httpContext.Response;
Infrastructure\RedirectResultExecutor.cs (3)
51context.HttpContext.Response.StatusCode = result.Permanent ? 53context.HttpContext.Response.Headers.Location = destinationUrl; 57context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
Infrastructure\RedirectToActionResultExecutor.cs (3)
57context.HttpContext.Response.StatusCode = result.Permanent ? 59context.HttpContext.Response.Headers.Location = destinationUrl; 63context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
Infrastructure\RedirectToPageResultExecutor.cs (3)
57context.HttpContext.Response.StatusCode = result.Permanent ? 59context.HttpContext.Response.Headers.Location = destinationUrl; 63context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
Infrastructure\RedirectToRouteResultExecutor.cs (3)
53context.HttpContext.Response.StatusCode = result.Permanent ? 55context.HttpContext.Response.Headers.Location = destinationUrl; 59context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
Infrastructure\SystemTextJsonResultExecutor.cs (1)
41var response = context.HttpContext.Response;
Infrastructure\VirtualFileResultExecutor.cs (1)
86var response = httpContext.Response;
ObjectResult.cs (1)
87context.HttpContext.Response.StatusCode = StatusCode.Value;
src\Shared\ChunkingCookieManager\ChunkingCookieManager.cs (4)
151var responseCookies = context.Response.Cookies; 274var responseHeaders = context.Response.Headers; 294var responseCookies = context.Response.Cookies; 332context.Response.Cookies.Append(keyValuePairs.ToArray(), new CookieOptions(options)
src\Shared\ResultsHelpers\FileResultHelper.cs (5)
32var outputStream = context.Response.Body; 58var outputStream = context.Response.Body; 111var response = httpContext.Response; 292var response = httpContext.Response; 354httpContext.Response.Headers.ContentDisposition = contentDisposition.ToString();
StatusCodeResult.cs (1)
43httpContext.Response.StatusCode = StatusCode;
Microsoft.AspNetCore.Mvc.Core.Test (195)
AcceptedAtActionResultTests.cs (3)
167Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); 168Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]); 209var header = context.HttpContext.Response.Headers.Last();
AcceptedAtRouteResultTests.cs (2)
118Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); 119Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
AcceptedResultTests.cs (5)
80Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); 81Assert.Equal(location, httpContext.Response.Headers["Location"]); 92httpContext.Response.Headers["Location"] = "/different/location/"; 99Assert.Equal(StatusCodes.Status202Accepted, httpContext.Response.StatusCode); 100Assert.Equal(location, httpContext.Response.Headers["Location"]);
ContentResultTest.cs (6)
42MediaTypeAssert.Equal("text/plain; charset=utf-16", httpContext.Response.ContentType); 129httpContext.Response.Body = memoryStream; 130httpContext.Response.ContentType = responseContentType; 137var finalResponseContentType = httpContext.Response.ContentType; 140Assert.Equal(expectedContentData.Length, httpContext.Response.ContentLength); 232httpContext.Response.Body = memoryStream;
ControllerBaseTest.cs (3)
1861mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>())); 1888mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>())); 3035httpContext.Setup(c => c.Response)
CreatedAtActionResultTests.cs (2)
40Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 41Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
CreatedAtRouteResultTests.cs (2)
54Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 55Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
CreatedResultTests.cs (7)
74Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 75Assert.Equal(location, httpContext.Response.Headers["Location"]); 90Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 91Assert.Equal(0, httpContext.Response.Headers["Location"].Count); 101httpContext.Response.Headers["Location"] = "/different/location/"; 108Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode); 109Assert.Equal(location, httpContext.Response.Headers["Location"]);
FileResultHelperTest.cs (9)
48Assert.Equal("application/my-type", httpContext.Response.Headers["Content-Type"]); 49Assert.Equal(@"attachment; filename=""some\\file""; filename*=UTF-8''some%5Cfile", httpContext.Response.Headers["Content-Disposition"]); 69Assert.Equal("application/my-type", httpContext.Response.Headers["Content-Type"]); 71httpContext.Response.Headers["Content-Disposition"]); 116Assert.Equal("application/my-type", httpContext.Response.ContentType); 117Assert.Equal("attachment; filename=filename.ext; filename*=UTF-8''filename.ext", httpContext.Response.Headers["Content-Disposition"]); 234Assert.Equal("bytes", httpContext.Response.Headers.AcceptRanges); 419Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 457Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode);
Filters\MiddlewareFilterTest.cs (12)
55httpContext.Response.Headers.Add(expectedHeader, ""); 77Assert.True(resourceExecutedContext.HttpContext.Response.Headers.ContainsKey(expectedHeader)); 93httpContext.Response.Headers["h1"] = "pipeline1"; 101httpContext.Response.Headers["h1"] = httpContext.Response.Headers["h1"] + "-pipeline2"; 125var response = resourceExecutedContext.HttpContext.Response; 179httpContext.Response.StatusCode = 500; 180httpContext.Response.Headers.Add("Error", "Error!!!!"); 211var response = resourceExecutedContext.HttpContext.Response; 262httpContext.Response.Body = new MemoryStream(); 499context.HttpContext.Response.StatusCode = 200; 500return context.HttpContext.Response.WriteAsync("Shortcircuited");
Filters\ResponseCacheFilterExecutorTest.cs (12)
29Assert.Equal("no-store", context.HttpContext.Response.Headers["Cache-control"]); 188Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]); 245Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]); 325Assert.Equal(varyOutput, context.HttpContext.Response.Headers["Vary"]); 326Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers["Cache-control"]); 409Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers.CacheControl); 450Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers["Cache-control"]); 451Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]); 470Assert.Equal("public,max-age=20", context.HttpContext.Response.Headers["Cache-control"]); 490Assert.Equal("private,max-age=10", context.HttpContext.Response.Headers["Cache-control"]); 510Assert.Equal("public,max-age=10", context.HttpContext.Response.Headers["Cache-control"]); 530Assert.Equal("Test", context.HttpContext.Response.Headers["Vary"]);
Formatters\FormatFilterTest.cs (4)
66httpContext.Setup(c => c.Response).Returns(new Mock<HttpResponse>().Object); 328httpContext.Setup(c => c.Response).Returns(new Mock<HttpResponse>().Object); 365httpContext.Setup(c => c.Response).Returns(response.Object); 402httpContext.Setup(c => c.Response).Returns(new Mock<HttpResponse>().Object);
Formatters\JsonOutputFormatterTestBase.cs (1)
153var body = outputFormatterContext.HttpContext.Response.Body;
Formatters\NoContentFormatterTests.cs (2)
130Assert.Equal(StatusCodes.Status204NoContent, context.HttpContext.Response.StatusCode); 150Assert.Null(context.HttpContext.Response.ContentLength);
Formatters\StringOutputFormatterTests.cs (1)
138httpContext.Setup(o => o.Response).Returns(response.Object);
Formatters\TextOutputFormatterTests.cs (2)
206Assert.Equal(MediaTypeHeaderValue.Parse(testContentType.Value), context.HttpContext.Response.GetTypedHeaders().ContentType); 231Assert.Equal(StatusCodes.Status406NotAcceptable, context.HttpContext.Response.StatusCode);
HttpNotFoundObjectResultTest.cs (1)
52Assert.Equal(StatusCodes.Status404NotFound, httpContext.Response.StatusCode);
HttpOkResultTest.cs (1)
39Assert.Equal(StatusCodes.Status200OK, context.HttpContext.Response.StatusCode);
HttpStatusCodeResultTests.cs (1)
32Assert.Equal(StatusCodes.Status404NotFound, httpContext.Response.StatusCode);
Infrastructure\ControllerActionInvokerTest.cs (1)
1728await c.HttpContext.Response.WriteAsync(c.Object.ToString());
Infrastructure\DefaultApiProblemDetailsWriterTest.cs (1)
245return context.HttpContext.Response.WriteAsJsonAsync(context.Object);
Infrastructure\JsonResultExecutorTestBase.cs (15)
39Assert.Equal("application/json; charset=utf-8", context.HttpContext.Response.ContentType); 60Assert.Equal("text/json", context.HttpContext.Response.ContentType); 70context.HttpContext.Response.ContentType = "text/json; charset=utf-8"; 84Assert.Equal("text/json; charset=utf-16", context.HttpContext.Response.ContentType); 94context.HttpContext.Response.ContentType = "text/json; charset=utf-16"; 104Assert.Equal("text/json; charset=utf-16", context.HttpContext.Response.ContentType); 128Assert.Equal("text/json; charset=us-ascii", context.HttpContext.Response.ContentType); 139context.HttpContext.Response.ContentType = expectedContentType; 150Assert.Equal(expectedContentType, context.HttpContext.Response.ContentType); 164context.HttpContext.Response.ContentType = responseContentType; 175Assert.Equal(expectedContentType, context.HttpContext.Response.ContentType); 199Assert.Equal("application/json; charset=utf-8", context.HttpContext.Response.ContentType); 280context.HttpContext.Response.Body = stream.Object; 498context.Response.Body.Seek(0, SeekOrigin.Begin); 499return Assert.IsType<MemoryStream>(context.Response.Body).ToArray();
Infrastructure\ObjectResultExecutorTest.cs (6)
100httpContext.Response.ContentType = "application/json"; 109Assert.Equal(406, httpContext.Response.StatusCode); 276Assert.Equal(StatusCodes.Status406NotAcceptable, actionContext.HttpContext.Response.StatusCode); 301actionContext.HttpContext.Response.Headers.ContentType); 395Assert.Equal(expectedContentType, actionContext.HttpContext.Response.Headers.ContentType); 432var responseContentType = actionContext.HttpContext.Response.Headers.ContentType;
LocalRedirectResultTest.cs (2)
78Assert.Equal(expectedPath, httpContext.Response.Headers.Location.ToString()); 79Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode);
ObjectResultTests.cs (3)
59Assert.Equal(404, actionContext.HttpContext.Response.StatusCode); 122Assert.Equal(StatusCodes.Status413RequestEntityTooLarge, actionContext.HttpContext.Response.StatusCode); 153Assert.Equal(StatusCodes.Status400BadRequest, actionContext.HttpContext.Response.StatusCode);
RedirectToActionResultTest.cs (2)
33.Setup(o => o.Response) 60.Setup(o => o.Response)
RedirectToPageResultTest.cs (3)
54httpContext.SetupGet(c => c.Response) 193httpContext.SetupGet(c => c.Response) 243httpContext.SetupGet(c => c.Response)
RedirectToRouteResultTest.cs (8)
32httpContext.Setup(o => o.Response).Returns(httpResponse.Object); 60.Setup(o => o.Response) 111Assert.True(httpContext.Response.Headers.ContainsKey("Location"), "Location header not found"); 112Assert.Equal(locationUrl, httpContext.Response.Headers["Location"]); 136Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 137Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]); 161Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); 162Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
ResponseCacheAttributeTest.cs (3)
219var response = context.HttpContext.Response; 277Assert.True(context.HttpContext.Response.Headers.TryGetValue("Cache-Control", out values)); 296Assert.True(context.HttpContext.Response.Headers.TryGetValue("Cache-Control", out values));
src\Shared\ResultsTests\FileContentResultTestBase.cs (19)
35httpContext.Response.Body = outStream; 69httpContext.Response.Body = new MemoryStream(); 77var httpResponse = httpContext.Response; 109httpContext.Response.Body = new MemoryStream(); 115var httpResponse = httpContext.Response; 148httpContext.Response.Body = new MemoryStream(); 154var httpResponse = httpContext.Response; 182httpContext.Response.Body = new MemoryStream(); 188var httpResponse = httpContext.Response; 213httpContext.Response.Body = new MemoryStream(); 219var httpResponse = httpContext.Response; 244httpContext.Response.Body = new MemoryStream(); 250var httpResponse = httpContext.Response; 281httpContext.Response.Body = new MemoryStream(); 287var httpResponse = httpContext.Response; 315httpContext.Response.Body = new MemoryStream(); 321var httpResponse = httpContext.Response; 343httpContext.Response.Body = outStream; 350Assert.Equal(expectedContentType, httpContext.Response.ContentType);
src\Shared\ResultsTests\FileStreamResultTestBase.cs (24)
47httpContext.Response.Body = new MemoryStream(); 55var httpResponse = httpContext.Response; 90httpContext.Response.Body = new MemoryStream(); 96var httpResponse = httpContext.Response; 131httpContext.Response.Body = new MemoryStream(); 137var httpResponse = httpContext.Response; 168httpContext.Response.Body = new MemoryStream(); 174var httpResponse = httpContext.Response; 201httpContext.Response.Body = new MemoryStream(); 207var httpResponse = httpContext.Response; 234httpContext.Response.Body = new MemoryStream(); 240var httpResponse = httpContext.Response; 273httpContext.Response.Body = new MemoryStream(); 279var httpResponse = httpContext.Response; 309httpContext.Response.Body = new MemoryStream(); 315var httpResponse = httpContext.Response; 350httpContext.Response.Body = new MemoryStream(); 356var httpResponse = httpContext.Response; 384httpContext.Response.Body = outStream; 409httpContext.Response.Body = outStream; 417Assert.Equal(expectedContentType, httpContext.Response.ContentType); 430httpContext.Response.Body = outStream; 437Assert.Equal(200, httpContext.Response.StatusCode); 438Assert.Equal(0, httpContext.Response.Body.Length);
src\Shared\ResultsTests\PhysicalFileResultTestBase.cs (13)
53var httpResponse = httpContext.Response; 84var httpResponse = httpContext.Response; 116var httpResponse = httpContext.Response; 143var httpResponse = httpContext.Response; 171var httpResponse = httpContext.Response; 192httpContext.Response.Body = new MemoryStream(); 198var httpResponse = httpContext.Response; 221httpContext.Response.Body = new MemoryStream(); 227var httpResponse = httpContext.Response; 248httpContext.Response.Body = new MemoryStream(); 254var httpResponse = httpContext.Response; 309var httpResponse = httpContext.Response; 336Assert.Equal(expectedContentType, httpContext.Response.ContentType);
src\Shared\ResultsTests\RedirectResultTestBase.cs (4)
34Assert.Equal(expectedPath, httpContext.Response.Headers.Location.ToString()); 35Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode); 57Assert.Equal(expectedPath, httpContext.Response.Headers.Location.ToString()); 58Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode);
src\Shared\ResultsTests\VirtualFileResultTestBase.cs (15)
65var httpResponse = httpContext.Response; 102var httpResponse = httpContext.Response; 139var httpResponse = httpContext.Response; 172var httpResponse = httpContext.Response; 206var httpResponse = httpContext.Response; 228httpContext.Response.Body = new MemoryStream(); 234httpContext.Response.Body = new MemoryStream(); 240var httpResponse = httpContext.Response; 276var httpResponse = httpContext.Response; 307var httpResponse = httpContext.Response; 344var httpResponse = httpContext.Response; 371Assert.Equal(expectedContentType, httpContext.Response.ContentType); 453httpContext.Response.Body = new MemoryStream(); 459httpContext.Response.Body.Position = 0; 460var contents = await new StreamReader(httpContext.Response.Body).ReadToEndAsync();
Microsoft.AspNetCore.Mvc.Cors (1)
CorsAuthorizationFilter.cs (1)
87_corsService.ApplyResult(result, context.HttpContext.Response);
Microsoft.AspNetCore.Mvc.Cors.Test (6)
CorsAuthorizationFilterTest.cs (6)
40var response = authorizationContext.HttpContext.Response; 69Assert.Equal(204, authorizationContext.HttpContext.Response.StatusCode); 70Assert.Empty(authorizationContext.HttpContext.Response.Headers); 90var response = authorizationContext.HttpContext.Response; 112Assert.Equal(200, authorizationContext.HttpContext.Response.StatusCode); 113Assert.Empty(authorizationContext.HttpContext.Response.Headers);
Microsoft.AspNetCore.Mvc.Formatters.Xml (4)
XmlDataContractSerializerInputFormatter.cs (1)
132request.HttpContext.Response.RegisterForDispose(readStream);
XmlDataContractSerializerOutputFormatter.cs (1)
222var response = httpContext.Response;
XmlSerializerInputFormatter.cs (1)
116request.HttpContext.Response.RegisterForDispose(readStream);
XmlSerializerOutputFormatter.cs (1)
201var response = httpContext.Response;
Microsoft.AspNetCore.Mvc.Formatters.Xml.Test (30)
XmlDataContractSerializerOutputFormatterTest.cs (15)
108var body = outputFormatterContext.HttpContext.Response.Body; 172var body = formatterContext.HttpContext.Response.Body; 197var body = outputFormatterContext.HttpContext.Response.Body; 232var body = outputFormatterContext.HttpContext.Response.Body; 263var body = outputFormatterContext.HttpContext.Response.Body; 291var body = outputFormatterContext.HttpContext.Response.Body; 319var body = outputFormatterContext.HttpContext.Response.Body; 340var body = outputFormatterContext.HttpContext.Response.Body; 354var response = outputFormatterContext.HttpContext.Response; 530var body = outputFormatterContext.HttpContext.Response.Body; 577var body = outputFormatterContext.HttpContext.Response.Body; 624var body = outputFormatterContext.HttpContext.Response.Body; 714var body = outputFormatterContext.HttpContext.Response.Body; 735outputFormatterContext.HttpContext.Response.Body = body; 772outputFormatterContext.HttpContext.Response.Body = body;
XmlSerializerOutputFormatterTest.cs (15)
62var body = outputFormatterContext.HttpContext.Response.Body; 98var body = outputFormatterContext.HttpContext.Response.Body; 118var body = outputFormatterContext.HttpContext.Response.Body; 174var body = formatterContext.HttpContext.Response.Body; 197var body = outputFormatterContext.HttpContext.Response.Body; 230var body = outputFormatterContext.HttpContext.Response.Body; 259var body = outputFormatterContext.HttpContext.Response.Body; 285var body = outputFormatterContext.HttpContext.Response.Body; 310var body = outputFormatterContext.HttpContext.Response.Body; 329Assert.NotNull(outputFormatterContext.HttpContext.Response.Body); 330Assert.True(outputFormatterContext.HttpContext.Response.Body.CanRead); 408var response = outputFormatterContext.HttpContext.Response; 414Assert.NotNull(outputFormatterContext.HttpContext.Response.ContentLength); 517outputFormatterContext.HttpContext.Response.Body = body; 554outputFormatterContext.HttpContext.Response.Body = body;
Microsoft.AspNetCore.Mvc.NewtonsoftJson (3)
NewtonsoftJsonInputFormatter.cs (1)
132httpContext.Response.RegisterForDispose(readStream);
NewtonsoftJsonOutputFormatter.cs (1)
142var response = context.HttpContext.Response;
NewtonsoftJsonResultExecutor.cs (1)
75var response = context.HttpContext.Response;
Microsoft.AspNetCore.Mvc.NewtonsoftJson.Test (28)
JsonResultTest.cs (3)
36Assert.Equal("application/json; charset=utf-8", context.HttpContext.Response.ContentType); 65context.Response.Body.Seek(0, SeekOrigin.Begin); 66return Assert.IsType<MemoryStream>(context.Response.Body).ToArray();
NewtonsoftJsonInputFormatterTest.cs (1)
456httpContext.Setup(h => h.Response.RegisterForDispose(It.IsAny<IDisposable>()))
NewtonsoftJsonOutputFormatterTest.cs (8)
139var body = outputFormatterContext.HttpContext.Response.Body; 171var body = outputFormatterContext2.HttpContext.Response.Body; 214var body = context.HttpContext.Response.Body; 266var body = context.HttpContext.Response.Body; 302var body = context.HttpContext.Response.Body; 337var body = context.HttpContext.Response.Body; 397Assert.NotNull(outputFormatterContext.HttpContext.Response.ContentLength); 424var body = context.HttpContext.Response.Body;
src\Mvc\Mvc.Core\test\Formatters\JsonOutputFormatterTestBase.cs (1)
153var body = outputFormatterContext.HttpContext.Response.Body;
src\Mvc\Mvc.Core\test\Infrastructure\JsonResultExecutorTestBase.cs (15)
39Assert.Equal("application/json; charset=utf-8", context.HttpContext.Response.ContentType); 60Assert.Equal("text/json", context.HttpContext.Response.ContentType); 70context.HttpContext.Response.ContentType = "text/json; charset=utf-8"; 84Assert.Equal("text/json; charset=utf-16", context.HttpContext.Response.ContentType); 94context.HttpContext.Response.ContentType = "text/json; charset=utf-16"; 104Assert.Equal("text/json; charset=utf-16", context.HttpContext.Response.ContentType); 128Assert.Equal("text/json; charset=us-ascii", context.HttpContext.Response.ContentType); 139context.HttpContext.Response.ContentType = expectedContentType; 150Assert.Equal(expectedContentType, context.HttpContext.Response.ContentType); 164context.HttpContext.Response.ContentType = responseContentType; 175Assert.Equal(expectedContentType, context.HttpContext.Response.ContentType); 199Assert.Equal("application/json; charset=utf-8", context.HttpContext.Response.ContentType); 280context.HttpContext.Response.Body = stream.Object; 498context.Response.Body.Seek(0, SeekOrigin.Begin); 499return Assert.IsType<MemoryStream>(context.Response.Body).ToArray();
Microsoft.AspNetCore.Mvc.Razor (1)
RazorPageBase.cs (1)
701await ViewContext.HttpContext.Response.Body.FlushAsync();
Microsoft.AspNetCore.Mvc.RazorPages (2)
PageBase.cs (1)
52public HttpResponse Response => HttpContext?.Response!;
PageModel.cs (1)
71public HttpResponse Response => HttpContext?.Response!;
Microsoft.AspNetCore.Mvc.RazorPages.Test (2)
PageModelTest.cs (1)
1444mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()));
PageTest.cs (1)
1434mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()));
Microsoft.AspNetCore.Mvc.ViewFeatures (7)
CookieTempDataProvider.cs (1)
86if (!context.Response.HasStarted)
Filters\SaveTempDataFilter.cs (4)
42if (!context.HttpContext.Response.HasStarted) 44context.HttpContext.Response.OnStarting( 84if (!context.HttpContext.Response.HasStarted && context.Exception != null) 105if (!context.HttpContext.Response.HasStarted)
ViewComponentResultExecutor.cs (1)
72var response = context.HttpContext.Response;
ViewExecutor.cs (1)
187var response = viewContext.HttpContext.Response;
Microsoft.AspNetCore.Mvc.ViewFeatures.Test (23)
ControllerUnitTestabilityTests.cs (1)
159mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()));
CookieTempDataProviderTest.cs (1)
322var responseCookies = httpContext.Response.GetTypedHeaders().SetCookie;
Filters\SaveTempDataFilterTest.cs (2)
385return context.HttpContext.Response.WriteAsync($"Hello from {nameof(TestActionResult)}"); 393return context.HttpContext.Response.WriteAsync($"Hello from {nameof(TestKeepTempDataActionResult)}");
PartialViewResultExecutorTest.cs (2)
301Assert.Equal("application/x-my-content-type", context.HttpContext.Response.ContentType); 330Assert.Equal(404, context.HttpContext.Response.StatusCode);
ViewComponentResultTest.cs (15)
194var body = ReadBody(actionContext.HttpContext.Response); 225var body = ReadBody(actionContext.HttpContext.Response); 256var body = ReadBody(actionContext.HttpContext.Response); 289var body = ReadBody(actionContext.HttpContext.Response); 328var body = ReadBody(actionContext.HttpContext.Response); 359var body = ReadBody(actionContext.HttpContext.Response); 390var body = ReadBody(actionContext.HttpContext.Response); 432var body = ReadBody(actionContext.HttpContext.Response); 474var body = ReadBody(actionContext.HttpContext.Response); 506Assert.Equal(404, actionContext.HttpContext.Response.StatusCode); 568var resultContentType = actionContext.HttpContext.Response.ContentType; 595actionContext.HttpContext.Response.ContentType = "application/x-will-be-overridden"; 609Assert.Equal(expectedContentType, actionContext.HttpContext.Response.ContentType); 633actionContext.HttpContext.Response.ContentType = expectedContentType; 646Assert.Equal(expectedContentType, actionContext.HttpContext.Response.ContentType);
ViewResultExecutorTest.cs (2)
296Assert.Equal("application/x-my-content-type", context.HttpContext.Response.ContentType); 320Assert.Equal(404, context.HttpContext.Response.StatusCode);
Microsoft.AspNetCore.OpenApi (6)
Extensions\OpenApiEndpointRouteBuilderExtensions.cs (6)
40context.Response.StatusCode = StatusCodes.Status404NotFound; 41context.Response.ContentType = "text/plain;charset=utf-8"; 42await context.Response.WriteAsync($"No OpenAPI document with the name '{documentName}' was found."); 53context.Response.ContentType = "application/json;charset=utf-8"; 54await context.Response.BodyWriter.WriteAsync(output.ToArray(), context.RequestAborted); 55await context.Response.BodyWriter.FlushAsync(context.RequestAborted);
Microsoft.AspNetCore.OutputCaching.Tests (70)
OutputCacheMiddlewareTests.cs (34)
46Assert.Equal(StatusCodes.Status504GatewayTimeout, context.HttpContext.Response.StatusCode); 106context.HttpContext.Response.Headers["MyHeader"] = "OldValue"; 119Assert.Equal("NewValue", context.HttpContext.Response.Headers["MyHeader"]); 433context.HttpContext.Response.Headers.Expires = HeaderUtilities.FormatDate(timeProvider.GetUtcNow() + TimeSpan.FromSeconds(11)); 456context.HttpContext.Response.Headers.CacheControl = new CacheControlHeaderValue() 461context.HttpContext.Response.Headers.Expires = HeaderUtilities.FormatDate(timeProvider.GetUtcNow() + TimeSpan.FromSeconds(11)); 482context.HttpContext.Response.Headers.CacheControl = new CacheControlHeaderValue() 487context.HttpContext.Response.Headers.Expires = HeaderUtilities.FormatDate(timeProvider.GetUtcNow() + TimeSpan.FromSeconds(11)); 522context.HttpContext.Response.Headers.Vary = vary; 543Assert.True(StringValues.IsNullOrEmpty(context.HttpContext.Response.Headers.Date)); 547Assert.Equal(HeaderUtilities.FormatDate(utcNow), context.HttpContext.Response.Headers.Date); 562context.HttpContext.Response.Headers.Date = HeaderUtilities.FormatDate(utcNow); 565Assert.Equal(HeaderUtilities.FormatDate(utcNow), context.HttpContext.Response.Headers.Date); 569Assert.Equal(HeaderUtilities.FormatDate(responseTime), context.HttpContext.Response.Headers.Date); 595context.HttpContext.Response.Headers.Vary = "HeaderB, heaDera"; 611context.HttpContext.Response.ContentLength = 20; 613await context.HttpContext.Response.WriteAsync(new string('0', 20)); 639context.HttpContext.Response.ContentLength = 9; 642await context.HttpContext.Response.WriteAsync(new string('0', 10)); 668context.HttpContext.Response.ContentLength = 10; 674await context.HttpContext.Response.WriteAsync(new string('0', 10)); 700await context.HttpContext.Response.WriteAsync(new string('0', 10)); 724await context.HttpContext.Response.WriteAsync(new string('0', 10)); 745await context.HttpContext.Response.WriteAsync(new string('0', 10)); 772await context.HttpContext.Response.WriteAsync(new string('0', 101)); 876c.Response.Cookies.Append("a", "b"); 877c.Response.Write("Hello" + responseCounter); 885context1.HttpContext.Response.Body = memoryStream1; 890context2.HttpContext.Response.Body = memoryStream2; 943c.Response.Write("Hello" + responseCounter); 972context.HttpContext.Response.ContentLength = 5; 976await context.HttpContext.Response.WriteAsync("Hello"); 1025await c.Response.WriteAsync(Guid.NewGuid().ToString()); 1046requestContext.HttpContext.Response.Body = responseStream;
OutputCachePolicyProviderTests.cs (17)
145context.HttpContext.Response.Headers.CacheControl = new CacheControlHeaderValue() 163context.HttpContext.Response.Headers.CacheControl = new CacheControlHeaderValue() 181context.HttpContext.Response.Headers.CacheControl = new CacheControlHeaderValue() 199context.HttpContext.Response.Headers.SetCookie = "cookieName=cookieValue"; 213context.HttpContext.Response.Headers.Vary = "*"; 227context.HttpContext.Response.Headers.CacheControl = new CacheControlHeaderValue() 246context.HttpContext.Response.StatusCode = statusCode; 322context.HttpContext.Response.StatusCode = statusCode; 336context.HttpContext.Response.StatusCode = StatusCodes.Status200OK; 339context.HttpContext.Response.Headers.Date = HeaderUtilities.FormatDate(utcNow); 356context.HttpContext.Response.StatusCode = StatusCodes.Status200OK; 357context.HttpContext.Response.Headers.CacheControl = new CacheControlHeaderValue() 361context.HttpContext.Response.Headers.Expires = HeaderUtilities.FormatDate(utcNow); 362context.HttpContext.Response.Headers.Date = HeaderUtilities.FormatDate(utcNow); 379context.HttpContext.Response.StatusCode = StatusCodes.Status200OK; 380context.HttpContext.Response.Headers.CacheControl = new CacheControlHeaderValue() 385context.HttpContext.Response.Headers.Date = HeaderUtilities.FormatDate(utcNow);
OutputCacheTests.cs (12)
307var builders = TestUtils.CreateBuildersWithOutputCaching(contextAction: context => context.Response.Headers.Vary = HeaderNames.From); 606var builders = TestUtils.CreateBuildersWithOutputCaching(contextAction: context => context.Response.Headers.SetCookie = "cookieName=cookieValue"); 674var builders = TestUtils.CreateBuildersWithOutputCaching(contextAction: context => context.Response.Headers.CacheControl = CacheControlHeaderValue.NoStoreString); 697context.Response.GetTypedHeaders().ETag = new EntityTagHeaderValue("\"E1\""); 698context.Response.Headers.ContentLocation = "/"; 699context.Response.Headers.Vary = HeaderNames.From; 746context.Response.GetTypedHeaders().ETag = new EntityTagHeaderValue("\"E1\""); 747context.Response.Headers.ContentLocation = "/"; 748context.Response.Headers.Vary = HeaderNames.From; 772var builders = TestUtils.CreateBuildersWithOutputCaching(contextAction: context => context.Response.GetTypedHeaders().ETag = new EntityTagHeaderValue("\"E1\"")); 865var builders = TestUtils.CreateBuildersWithOutputCaching(contextAction: context => context.Response.Headers.Vary = HeaderNames.From); 889var builders = TestUtils.CreateBuildersWithOutputCaching(contextAction: context => context.Response.Headers.Vary = context.Request.Headers.Pragma);
TestUtils.cs (7)
35var headers = context.Response.GetTypedHeaders(); 51await context.Response.WriteAsync(uniqueId); 61await context.Response.SendFileAsync(path, 0, null); 62await context.Response.WriteAsync(uniqueId); 76context.Response.Write(uniqueId); 86Encoding.UTF8.GetBytes(uniqueId, context.Response.BodyWriter); 87await context.Response.BodyWriter.FlushAsync();
Microsoft.AspNetCore.Owin (1)
OwinEnvironment.cs (1)
66{ OwinConstants.ResponseBody, new FeatureMap<IHttpResponseBodyFeature>(feature => feature.Stream, () => Stream.Null, (feature, value) => context.Response.Body = (Stream)value) }, // DefaultHttpResponse.Body.Set has built in logic to handle replacing the feature.
Microsoft.AspNetCore.Owin.Tests (6)
OwinEnvironmentTests.cs (6)
31context.Response.Body = Stream.Null; 32context.Response.Headers["CustomResponseHeader"] = "CustomResponseValue"; 33context.Response.StatusCode = 201; 93Assert.Same(Stream.Null, context.Response.Body); 94Assert.Equal("CustomResponseValue", context.Response.Headers["CustomResponseHeader"]); 95Assert.Equal(201, context.Response.StatusCode);
Microsoft.AspNetCore.RateLimiting (1)
RateLimitingMiddleware.cs (1)
123context.Response.StatusCode = _rejectionStatusCode;
Microsoft.AspNetCore.RateLimiting.Tests (14)
RateLimitingMiddlewareTests.cs (13)
119context.HttpContext.Response.StatusCode = 429; 198context.HttpContext.Response.StatusCode = 429; 234context.HttpContext.Response.StatusCode = 429; 265context.HttpContext.Response.StatusCode = 429; 297context.HttpContext.Response.StatusCode = 429; 329context.HttpContext.Response.StatusCode = 429; 361context.HttpContext.Response.StatusCode = 429; 392context.HttpContext.Response.StatusCode = 429; 438context.HttpContext.Response.StatusCode = 429; 490context.HttpContext.Response.StatusCode = 429; 528context.HttpContext.Response.StatusCode = 429; 564context.HttpContext.Response.StatusCode = 429; 598context.HttpContext.Response.StatusCode = 429;
TestRateLimiterPolicy.cs (1)
21context.HttpContext.Response.StatusCode = statusCode;
Microsoft.AspNetCore.ResponseCaching (16)
ResponseCachingContext.cs (4)
65if (HeaderUtilities.TryParseDate(HttpContext.Response.Headers.Date.ToString(), out date)) 92if (HeaderUtilities.TryParseDate(HttpContext.Response.Headers.Expires.ToString(), out expires)) 112HeaderUtilities.TryParseSeconds(HttpContext.Response.Headers.CacheControl, CacheControlHeaderValue.SharedMaxAgeString, out _responseSharedMaxAge); 125HeaderUtilities.TryParseSeconds(HttpContext.Response.Headers.CacheControl, CacheControlHeaderValue.MaxAgeString, out _responseMaxAge);
ResponseCachingMiddleware.cs (10)
155context.HttpContext.Response.StatusCode = StatusCodes.Status304NotModified; 163context.HttpContext.Response.Headers[key] = values; 170var response = context.HttpContext.Response; 233context.HttpContext.Response.StatusCode = StatusCodes.Status504GatewayTimeout; 254var response = context.HttpContext.Response; 339var contentLength = context.HttpContext.Response.ContentLength; 345var response = context.HttpContext.Response; 404context.OriginalResponseStream = context.HttpContext.Response.Body; 410context.HttpContext.Response.Body = context.ResponseCachingStream; 422context.HttpContext.Response.Body = context.OriginalResponseStream;
ResponseCachingPolicyProvider.cs (2)
68var responseCacheControlHeader = context.HttpContext.Response.Headers.CacheControl; 91var response = context.HttpContext.Response;
Microsoft.AspNetCore.ResponseCaching.Microbenchmarks (2)
ResponseCachingBenchmark.cs (2)
36context.Response.Headers.CacheControl = _cacheControl; 37await context.Response.BodyWriter.WriteAsync(new ReadOnlyMemory<byte>(_data, 0, Size));
Microsoft.AspNetCore.ResponseCaching.Tests (19)
ResponseCachingTests.cs (14)
269var builders = TestUtils.CreateBuildersWithResponseCaching(contextAction: context => context.Response.Headers.Vary = HeaderNames.From); 292var builders = TestUtils.CreateBuildersWithResponseCaching(contextAction: context => context.Response.Headers.Vary = HeaderNames.From); 545var builders = TestUtils.CreateBuildersWithResponseCaching(contextAction: context => context.Response.Headers.SetCookie = "cookieName=cookieValue"); 619var builders = TestUtils.CreateBuildersWithResponseCaching(contextAction: context => context.Response.Headers.CacheControl = CacheControlHeaderValue.NoStoreString); 643context.Response.GetTypedHeaders().ETag = new EntityTagHeaderValue("\"E1\""); 644context.Response.Headers.ContentLocation = "/"; 645context.Response.Headers.Vary = HeaderNames.From; 696context.Response.GetTypedHeaders().ETag = new EntityTagHeaderValue("\"E1\""); 697context.Response.Headers.ContentLocation = "/"; 698context.Response.Headers.Vary = HeaderNames.From; 724var builders = TestUtils.CreateBuildersWithResponseCaching(contextAction: context => context.Response.GetTypedHeaders().ETag = new EntityTagHeaderValue("\"E1\"")); 822var builders = TestUtils.CreateBuildersWithResponseCaching(contextAction: context => context.Response.Headers.Vary = HeaderNames.From); 848var builders = TestUtils.CreateBuildersWithResponseCaching(contextAction: context => context.Response.Headers.Vary = context.Request.Headers.Pragma); 883var builders = TestUtils.CreateBuildersWithResponseCaching(contextAction: context => context.Response.Headers.Vary = context.Request.Headers.Pragma);
TestUtils.cs (5)
34var headers = context.Response.GetTypedHeaders(); 76await context.Response.WriteAsync(uniqueId); 86await context.Response.SendFileAsync(path, 0, null); 87await context.Response.WriteAsync(uniqueId); 101context.Response.Write(uniqueId);
Microsoft.AspNetCore.ResponseCompression (4)
ResponseCompressionBody.cs (1)
206var headers = _context.Response.Headers;
ResponseCompressionProvider.cs (3)
176if (context.Response.Headers.ContainsKey(HeaderNames.ContentRange)) 182if (context.Response.Headers.ContainsKey(HeaderNames.ContentEncoding)) 188var mimeType = context.Response.ContentType;
Microsoft.AspNetCore.ResponseCompression.Tests (62)
ResponseCompressionMiddlewareTest.cs (62)
165context.Response.Headers.ContentMD5 = "MD5"; 166context.Response.ContentType = TextPlain; 167return context.Response.WriteAsync(new string('a', 100)); 323context.Response.Headers.ContentMD5 = "MD5"; 324context.Response.ContentType = contentType; 461context.Response.ContentType = TextPlain; 462return context.Response.WriteAsync(new string('a', 100)); 524context.Response.ContentType = TextPlain; 525return context.Response.WriteAsync(new string('a', 100)); 587context.Response.ContentType = TextPlain; 588return context.Response.WriteAsync(new string('a', 100)); 638context.Response.Headers.ContentMD5 = "MD5"; 639context.Response.ContentType = TextPlain; 640context.Response.Body.Flush(); 642await context.Response.WriteAsync(new string('a', 100)); 684context.Response.Headers.ContentMD5 = "MD5"; 685context.Response.ContentType = TextPlain; 686await context.Response.Body.FlushAsync(); 688await context.Response.WriteAsync(new string('a', 100)); 735context.Response.Headers.ContentMD5 = "MD5"; 736context.Response.ContentType = TextPlain; 737context.Response.Body.Write(new byte[10], 0, 10); 738context.Response.Body.Flush(); 740context.Response.Body.Write(new byte[90], 0, 90); 788context.Response.Headers.ContentMD5 = "MD5"; 789context.Response.ContentType = TextPlain; 790await context.Response.WriteAsync(new string('a', 10)); 791await context.Response.Body.FlushAsync(); 793await context.Response.WriteAsync(new string('a', 90)); 848context.Response.Headers.ContentMD5 = "MD5"; 849context.Response.ContentType = TextPlain; 860context.Response.Body.Write(new byte[1], 0, 1); 861context.Response.Body.Flush(); 918context.Response.Headers.ContentMD5 = "MD5"; 919context.Response.ContentType = TextPlain; 924await context.Response.WriteAsync("a"); 925await context.Response.Body.FlushAsync(); 982context.Response.Headers.ContentMD5 = "MD5"; 983context.Response.ContentType = "Un/compressed"; 988await context.Response.WriteAsync("a"); 989await context.Response.Body.FlushAsync(); 1047context.Response.Headers.ContentMD5 = "MD5"; 1048context.Response.ContentType = "custom/type"; 1049context.Response.ContentLength = 1024; 1097context.Response.Headers.ContentMD5 = "MD5"; 1098context.Response.ContentType = TextPlain; 1099context.Response.ContentLength = 1024; 1147context.Response.Headers.ContentMD5 = "MD5"; 1148context.Response.ContentType = TextPlain; 1151await context.Response.WriteAsync(new string('a', 100)); 1191context.Response.Body = new NoSyncWrapperStream(context.Response.Body); 1197context.Response.Headers.ContentMD5 = "MD5"; 1198context.Response.ContentType = TextPlain; 1199await context.Response.WriteAsync(new string('a', 10)); 1200await context.Response.Body.FlushAsync(); 1202await context.Response.WriteAsync(new string('a', 90)); 1258context.Response.Headers.ContentMD5 = "MD5"; 1259context.Response.ContentType = responseType; 1263context.Response.ContentLength = uncompressedBodyLength; 1267addResponseAction?.Invoke(context.Response); 1268return context.Response.WriteAsync(new string('a', uncompressedBodyLength));
Microsoft.AspNetCore.Rewrite (10)
RedirectRule.cs (1)
46var response = context.HttpContext.Response;
RedirectToHttpsRule.cs (1)
34var response = context.HttpContext.Response;
RedirectToWwwHelper.cs (1)
45var response = context.HttpContext.Response;
RewriteMiddleware.cs (2)
104httpContext.Response.Headers.Location.ToString(), 105httpContext.Response.StatusCode);
UrlActions\ChangeCookieAction.cs (1)
38context.HttpContext.Response.Cookies.Append(Name, Value ?? string.Empty, options);
UrlActions\CustomResponseAction.cs (1)
24var response = context.HttpContext.Response;
UrlActions\ForbiddenAction.cs (1)
12context.HttpContext.Response.StatusCode = StatusCodes.Status403Forbidden;
UrlActions\GoneAction.cs (1)
12context.HttpContext.Response.StatusCode = StatusCodes.Status410Gone;
UrlActions\RedirectAction.cs (1)
32var response = context.HttpContext.Response;
Microsoft.AspNetCore.Rewrite.Tests (56)
ApacheModRewrite\ModRewriteMiddlewareTest.cs (17)
27app.Run(context => context.Response.WriteAsync(context.Request.Path)); 53app.Run(context => context.Response.WriteAsync(context.Request.Path)); 79app.Run(context => context.Response.WriteAsync(context.Request.Path)); 104app.Run(context => context.Response.WriteAsync(context.Request.Path)); 129app.Run(context => context.Response.WriteAsync(context.Request.Path)); 154app.Run(context => context.Response.WriteAsync(context.Request.Path)); 179app.Run(context => context.Response.WriteAsync(context.Request.Path)); 206app.Run(context => context.Response.WriteAsync(context.Request.Path)); 237app.Run(context => context.Response.WriteAsync(context.Request.Path)); 263app.Run(context => context.Response.WriteAsync(context.Request.Path)); 289app.Run(context => context.Response.WriteAsync(context.Request.Scheme + "://" + context.Request.Host.Host + context.Request.Path + context.Request.QueryString)); 315app.Run(context => context.Response.WriteAsync(context.Request.Scheme + "://" + context.Request.Host.Host + context.Request.Path + context.Request.QueryString)); 342app.Run(context => context.Response.WriteAsync(context.Request.Scheme + "://" + context.Request.Host.Host + context.Request.Path + context.Request.QueryString)); 370app.Run(context => context.Response.WriteAsync(context.Request.Scheme + "://" + context.Request.Host.Host + context.Request.Path + context.Request.QueryString)); 398app.Run(context => context.Response.WriteAsync(context.Request.Path + context.Request.QueryString)); 422app.Run(context => context.Response.WriteAsync( 452app.Run(context => context.Response.WriteAsync(
IISUrlRewrite\MiddleWareTests.cs (14)
37app.Run(context => context.Response.WriteAsync(context.Response.Headers.Location)); 69app.Run(context => context.Response.WriteAsync(context.Request.Path + context.Request.QueryString)); 105app.Run(context => context.Response.WriteAsync(context.Request.Path + context.Request.QueryString)); 137app.Run(context => context.Response.WriteAsync(context.Response.Headers.Location)); 276app.Run(context => context.Response.WriteAsync( 313app.Run(context => context.Response.WriteAsync( 350app.Run(context => context.Response.WriteAsync( 387app.Run(context => context.Response.WriteAsync( 421app.Run(context => context.Response.WriteAsync( 608app.Run(context => context.Response.WriteAsync(context.Request.GetEncodedUrl())); 653app.Run(context => context.Response.WriteAsync(context.Request.GetEncodedUrl())); 740app.Run(context => context.Response.WriteAsync(context.Request.GetEncodedUrl()));
MiddlewareTests.cs (20)
28app.Run(context => context.Response.WriteAsync( 58app.Run(context => context.Response.WriteAsync( 90app.Run(context => context.Response.WriteAsync( 122app.Run(context => context.Response.WriteAsync( 659endpoints.MapGet("/foos", context => context.Response.WriteAsync("bad")); 660endpoints.MapGet("/foo", context => context.Response.WriteAsync($"{context.GetEndpoint()?.DisplayName} from {context.Request.Path}")); 686app.Run(context => context.Response.WriteAsync( 713app.Run(context => context.Response.WriteAsync( 857endpoints.MapGet("/foo", context => context.Response.WriteAsync( 860endpoints.MapGet("/g", context => context.Response.WriteAsync( 895endpoints.MapGet("/foo", context => context.Response.WriteAsync( 898endpoints.MapGet("/g", context => context.Response.WriteAsync( 931endpoints.MapGet("/foo", context => context.Response.WriteAsync( 934endpoints.MapGet("/g", context => context.Response.WriteAsync( 968endpoints.MapGet("/foo", context => context.Response.WriteAsync( 971endpoints.MapGet("/g/h", context => context.Response.WriteAsync( 1005endpoints.MapGet("/foo", context => context.Response.WriteAsync( 1008endpoints.MapGet("/g", context => context.Response.WriteAsync( 1038app.MapGet("/foo", context => context.Response.WriteAsync( 1041app.MapGet("/g", context => context.Response.WriteAsync(
UrlActions\ChangeCookieActionTests.cs (3)
29var cookieHeaders = context.HttpContext.Response.Headers.SetCookie; 45var cookieHeaders = context.HttpContext.Response.Headers.SetCookie; 58var cookieHeaders = context.HttpContext.Response.Headers.SetCookie;
UrlActions\ForbiddenActionTests.cs (1)
21Assert.Equal(StatusCodes.Status403Forbidden, context.HttpContext.Response.StatusCode);
UrlActions\GoneActionTests.cs (1)
20Assert.Equal(StatusCodes.Status410Gone, context.HttpContext.Response.StatusCode);
Microsoft.AspNetCore.Routing (10)
EndpointRoutingMiddleware.cs (1)
183httpContext.Response.StatusCode = shortCircuitMetadata.StatusCode.Value;
Matching\AcceptsMatcherPolicy.cs (1)
253context.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType;
Matching\HttpMethodMatcherPolicy.cs (2)
388context.Response.Headers.Allow = allow; 389context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed;
Matching\NegotiationMatcherPolicy.cs (1)
323context.Response.StatusCode = StatusCodes.Status406NotAcceptable;
RequestDelegateFilterPipelineBuilder.cs (1)
34if (context.HttpContext.Response.StatusCode < 400)
RequestDelegateRouteBuilderExtensions.cs (1)
239return handler(httpContext.Request, httpContext.Response, httpContext.GetRouteData());
src\Shared\RouteHandlers\ExecuteHandlerHelper.cs (3)
22return httpContext.Response.WriteAsync(stringValue); 27return WriteJsonResponseAsync(httpContext.Response, obj, jsonTypeInfo); 33httpContext.Response.ContentType ??= "text/plain; charset=utf-8";
Microsoft.AspNetCore.Routing.FunctionalTests (7)
MinimalFormTests.cs (4)
94await context.Response.WriteAsJsonAsync(todo); 356await context.Response.WriteAsJsonAsync(todo); 370await context.Response.WriteAsJsonAsync(todo); 384await context.Response.WriteAsJsonAsync(todo);
ShortCircuitTests.cs (3)
27context.Response.Headers["NotSet"] = "No!"; 34context.Response.Headers["Set"] = "Yes!"; 70context.Response.Headers["NotSet"] = "No!";
Microsoft.AspNetCore.Routing.Tests (8)
Builder\RequestDelegateEndpointRouteBuilderExtensionsTest.cs (2)
90await context.Response.WriteAsync("Response string text"); 197httpContext.Response.StatusCode = 400;
Matching\HttpMethodMatcherPolicyIntegrationTestBase.cs (6)
203Assert.Equal(405, httpContext.Response.StatusCode); 204Assert.Equal("DELETE, GET, PUT", httpContext.Response.Headers["Allow"]); 313Assert.Equal(405, httpContext.Response.StatusCode); 314Assert.Equal("DELETE, GET, PUT", httpContext.Response.Headers["Allow"]); 318Assert.Equal(405, httpContext.Response.StatusCode); 319Assert.Equal("DELETE, GET, PUT", httpContext.Response.Headers["Allow"]);
Microsoft.AspNetCore.Security.Microbenchmarks (2)
ChunkingCookieManagerBenchmark.cs (2)
55_httpContext.Response.Headers[HeaderNames.SetCookie] = StringValues.Empty; 62_httpContext.Response.Headers[HeaderNames.SetCookie] = StringValues.Empty;
Microsoft.AspNetCore.Server.HttpSys.FunctionalTests (341)
AuthenticationTests.cs (4)
74httpContext.Response.StatusCode = 401; 100httpContext.Response.StatusCode = 401; 126httpContext.Response.StatusCode = 401; 178httpContext.Response.OnCompleted(() =>
DelegateTests.cs (9)
42await httpContext.Response.WriteAsync(_expectedResponseString); 73httpContext.Response.StatusCode = StatusCodes.Status418ImATeapot; 85await httpContext.Response.WriteAsync(_expectedResponseString); 106await httpContext.Response.WriteAsync(_expectedResponseString); 120httpContext.Response.WriteAsync(_expectedResponseString); 139httpContext.Response.StatusCode = StatusCodes.Status418ImATeapot; 191await httpContext.Response.WriteAsync(_expectedResponseString); 225await httpContext.Response.WriteAsync(_expectedResponseString); 252await httpContext.Response.WriteAsync(_expectedResponseString);
Http2Tests.cs (15)
172return httpContext.Request.Body.CopyToAsync(httpContext.Response.Body); 237return httpContext.Request.Body.CopyToAsync(httpContext.Response.Body); 289return httpContext.Response.WriteAsync("Hello World"); 324httpContext.Response.Headers.Connection = "close"; 368httpContext.Response.Headers.Connection = "close"; 446httpContext.Response.Headers.Connection = "close"; 553await httpContext.Response.Body.FlushAsync(); 585await httpContext.Response.Body.FlushAsync(); 619return httpContext.Response.WriteAsync("Hello World"); 641return httpContext.Response.WriteAsync("Hello World"); 706await httpContext.Response.Body.FlushAsync(); 753await httpContext.Response.WriteAsync("Hello World"); 803await httpContext.Response.WriteAsync("Hello World"); 804await httpContext.Response.CompleteAsync(); 955await httpContext.Response.CompleteAsync();
Http3Tests.cs (15)
31await httpContext.Response.WriteAsync(httpContext.Request.Protocol); 35await httpContext.Response.WriteAsync(ex.ToString()); 58httpContext.Response.Headers.AltSvc = altsvc; 59await httpContext.Response.WriteAsync(httpContext.Request.Protocol); 63await httpContext.Response.WriteAsync(ex.ToString()); 98httpContext.Response.Headers.AltSvc = altsvc; 99await httpContext.Response.WriteAsync(httpContext.Request.Protocol); 103await httpContext.Response.WriteAsync(ex.ToString()); 134await httpContext.Response.WriteAsync(httpContext.Request.Protocol); 135httpContext.Response.AppendTrailer("custom", "value"); 139await httpContext.Response.WriteAsync(ex.ToString()); 167await httpContext.Response.WriteAsync(ex.ToString()); 191await httpContext.Response.Body.FlushAsync(); 197await httpContext.Response.WriteAsync(ex.ToString()); 221await httpContext.Response.Body.FlushAsync();
HttpsTests.cs (8)
43httpContext.Response.ContentLength = body.Length; 44return httpContext.Response.Body.WriteAsync(body, 0, body.Length); 60httpContext.Response.ContentLength = body.Length; 61await httpContext.Response.Body.WriteAsync(body, 0, body.Length); 141await httpContext.Response.WriteAsync(ex.ToString()); 158return httpContext.Response.WriteAsJsonAsync(tlsFeature); 225await httpContext.Response.WriteAsync(ex.ToString()); 255await httpContext.Response.WriteAsync(ex.ToString());
OpaqueUpgradeTests.cs (13)
34return httpContext.Response.WriteAsync(ex.ToString()); 61httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; 62return httpContext.Response.WriteAsync(ex.ToString()); 83await httpContext.Response.WriteAsync("Hello World"); 84await httpContext.Response.Body.FlushAsync(); 112httpContext.Response.Headers["Upgrade"] = "websocket"; // Win8.1 blocks anything but WebSockets 139httpContext.Response.Headers["Upgrade"] = "websocket"; // Win8.1 blocks anything but WebSockets 167httpContext.Response.OnStarting(_ => 172httpContext.Response.Headers["Upgrade"] = "websocket"; // Win8.1 blocks anything but WebSockets 219httpContext.Response.Headers["Upgrade"] = "websocket"; // Win8.1 blocks anything but WebSockets 232await httpContext.Response.WriteAsync(ex.ToString()); 268await httpContext.Response.WriteAsync(ex.ToString()); 291await httpContext.Response.WriteAsync(ex.ToString());
RequestBodyLimitTests.cs (18)
32httpContext.Response.ContentLength = read; 33httpContext.Response.Body.Write(input, 0, read); 55httpContext.Response.ContentLength = read; 56await httpContext.Response.Body.WriteAsync(input, 0, read); 76httpContext.Response.ContentLength = read; 77httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(input, 0, read, null, null)); 99httpContext.Response.ContentLength = read; 100httpContext.Response.Body.Write(input, 0, read); 122httpContext.Response.ContentLength = read; 123await httpContext.Response.Body.WriteAsync(input, 0, read); 143httpContext.Response.ContentLength = read; 144httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(input, 0, read, null, null)); 372httpContext.Response.ContentLength = read; 373await httpContext.Response.Body.WriteAsync(input, 0, read); 396httpContext.Response.ContentLength = read; 397await httpContext.Response.Body.WriteAsync(input, 0, read);
RequestBodyTests.cs (16)
33httpContext.Response.ContentLength = read; 34httpContext.Response.Body.Write(input, 0, read); 55httpContext.Response.ContentLength = read; 56httpContext.Response.Body.Write(input, 0, read); 74httpContext.Response.ContentLength = read; 75await httpContext.Response.Body.WriteAsync(input, 0, read); 94httpContext.Response.ContentLength = read; 95await httpContext.Response.Body.WriteAsync(input, 0, read); 111httpContext.Response.ContentLength = read; 112httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(input, 0, read, null, null)); 196httpContext.Response.ContentLength = 10; 197await httpContext.Response.Body.WriteAsync(input, 0, 10); 230httpContext.Response.ContentLength = read; 231await httpContext.Response.Body.WriteAsync(input, 0, read); 284httpContext.Response.StatusCode = 200;
RequestTests.cs (5)
59httpContext.Response.Body.Write(body, 0, body.Length); 123httpContext.Response.Body.Write(body, 0, body.Length); 186httpContext.Response.Body.Write(body, 0, body.Length); 230httpContext.Response.Body.Write(body, 0, body.Length); 327httpContext.Response.Body.Write(body, 0, body.Length);
ResponseBodyTests.cs (41)
20httpContext.Response.OnStarting(() => 25await httpContext.Response.StartAsync(); 26Assert.True(httpContext.Response.HasStarted); 27Assert.True(httpContext.Response.Headers.IsReadOnly); 29await httpContext.Response.WriteAsync("Hello World"); 49httpContext.Response.OnStarting(() => 54await httpContext.Response.CompleteAsync(); 55Assert.True(httpContext.Response.HasStarted); 56Assert.True(httpContext.Response.Headers.IsReadOnly); 75var writer = httpContext.Response.BodyWriter; 78await httpContext.Response.CompleteAsync(); 95var writer = httpContext.Response.BodyWriter; 115httpContext.Response.Body.Write(new byte[10], 0, 10); 116return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 146httpContext.Response.Body.Write(new byte[WriteSize], 0, WriteSize); 148await httpContext.Response.Body.WriteAsync(new byte[WriteSize], 0, WriteSize); 171httpContext.Response.Body.Write(new byte[10], 0, 10); 172await httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 173await httpContext.Response.Body.FlushAsync(); 192httpContext.Response.Headers["transfeR-Encoding"] = "CHunked"; 193Stream stream = httpContext.Response.Body; 215httpContext.Response.Headers["Content-lenGth"] = " 30 "; 216Stream stream = httpContext.Response.Body; 239httpContext.Response.Headers["Content-lenGth"] = " 20 "; 253httpContext.Response.Headers["Content-lenGth"] = " 20 "; 254return httpContext.Response.Body.WriteAsync(new byte[5], 0, 5); 268httpContext.Response.Headers["Content-lenGth"] = " 10 "; 269await httpContext.Response.Body.WriteAsync(new byte[5], 0, 5); 271httpContext.Response.Body.WriteAsync(new byte[6], 0, 6)); 289httpContext.Response.Headers["Content-lenGth"] = " 10 "; 290httpContext.Response.Body.Write(new byte[10], 0, 10); 291httpContext.Response.Body.Write(new byte[9], 0, 9); 323httpContext.Response.OnStarting(state => 329httpContext.Response.Body.Write(new byte[10], 0, 10); 351httpContext.Response.OnStarting(state => 357httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(new byte[10], 0, 10, null, null)); 379httpContext.Response.OnStarting(state => 385return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 411httpContext.Response.ContentLength = data.Length; 413var body = httpContext.Response.Body;
ResponseCachingTests.cs (99)
51httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 52httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 53httpContext.Response.ContentLength = 10; 54return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 70httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 71httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 72httpContext.Response.Headers["Cache-Control"] = "public"; 73httpContext.Response.ContentLength = 10; 74return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 92httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 93httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 94httpContext.Response.ContentLength = 10; 95return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 111httpContext.Response.StatusCode = StatusCodes.Status304NotModified; 112httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 113httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 114httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 115httpContext.Response.ContentLength = 10; 116return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 138httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 139httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 140httpContext.Response.ContentLength = 10; 141return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 157httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 158httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 159httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 160httpContext.Response.ContentLength = 10; 161return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 177httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 178httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 179httpContext.Response.Headers["Cache-Control"] = "public, max-age=" + int.MaxValue.ToString(CultureInfo.InvariantCulture); 180httpContext.Response.ContentLength = 10; 181return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 197httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 198httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 199httpContext.Response.Headers["Cache-Control"] = "public, s-maxage=10"; 200httpContext.Response.ContentLength = 10; 201return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 217httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 218httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 219httpContext.Response.Headers["Cache-Control"] = "public, max-age=0, s-maxage=10"; 220httpContext.Response.ContentLength = 10; 221return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 237httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 238httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 239httpContext.Response.Headers["Cache-Control"] = "public"; 240httpContext.Response.Headers["Expires"] = (DateTime.UtcNow + TimeSpan.FromSeconds(10)).ToString("r"); 241httpContext.Response.ContentLength = 10; 242return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 261httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 262httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 263httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 264httpContext.Response.Headers[headerName] = "headerValue"; 265httpContext.Response.ContentLength = 10; 266return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 284httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 285httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 286httpContext.Response.Headers["Cache-Control"] = "public"; 287httpContext.Response.Headers["Expires"] = expiresValue; 288httpContext.Response.ContentLength = 10; 289return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 305httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 306httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 307httpContext.Response.Headers["Expires"] = (DateTime.UtcNow + TimeSpan.FromSeconds(10)).ToString("r"); 308httpContext.Response.ContentLength = 10; 309return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 325httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 326httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 327httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 328httpContext.Response.Headers["Expires"] = (DateTime.UtcNow - TimeSpan.FromSeconds(10)).ToString("r"); // In the past 329httpContext.Response.ContentLength = 10; 330return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 346httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 347httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 348httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 349httpContext.Response.ContentLength = 10; 350httpContext.Response.Body.FlushAsync(); 351return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 367httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 368httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 369httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 370httpContext.Response.ContentLength = 10; 371await httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); 373Assert.Null(httpContext.Response.ContentLength); 389httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 390httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 391httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 392await httpContext.Response.SendFileAsync(_absoluteFilePath, 0, null, CancellationToken.None); 408httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 409httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 410httpContext.Response.Headers["Cache-Control"] = "public, max-age=30"; 411httpContext.Response.ContentLength = _fileLength; 412await httpContext.Response.SendFileAsync(_absoluteFilePath, 0, null, CancellationToken.None); 428httpContext.Response.ContentType = "some/thing"; // Http.Sys requires content-type for caching 429httpContext.Response.Headers["x-request-count"] = (requestCount++).ToString(CultureInfo.InvariantCulture); 430httpContext.Response.Headers["Cache-Control"] = "public, max-age=10"; 432httpContext.Response.StatusCode = status; 433httpContext.Response.ContentLength = 10; 434return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10);
ResponseHeaderTests.cs (5)
146return httpContext.Response.Body.FlushAsync(); // Http.Sys adds the Content-Length: header for us if we don't flush 190var response = httpContext.Response; 220var response = httpContext.Response; 251var response = httpContext.Response; 281var responseHeaders = httpContext.Response.Headers;
ResponseSendFileTests.cs (24)
221httpContext.Response.Headers["Content-lenGth"] = FileLength.ToString(CultureInfo.InvariantCulture); 242httpContext.Response.Headers["Content-lenGth"] = "10"; 263httpContext.Response.Headers["Content-lenGth"] = "0"; 284httpContext.Response.OnStarting(state => 315await httpContext.Response.SendFileAsync(emptyFilePath, 0, null, CancellationToken.None); 316Assert.True(httpContext.Response.HasStarted); 317await httpContext.Response.Body.WriteAsync(new byte[10], 0, 10, CancellationToken.None); 340await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 341await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 358await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 359await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 379var writeTask = httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 407var writeTask = httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 434await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 436var writeTask = httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 461await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 463var writeTask = httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 502await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 507httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token)); 549await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null); 589await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 600await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, cts.Token); 641await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null); 650await httpContext.Response.SendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None);
ResponseTests.cs (18)
28Assert.Equal(200, httpContext.Response.StatusCode); 29Assert.False(httpContext.Response.HasStarted); 47httpContext.Response.StatusCode = 201; 66httpContext.Response.StatusCode = 201; 86httpContext.Response.StatusCode = 901; 103httpContext.Response.StatusCode = 100; 118httpContext.Response.StatusCode = 0; 135httpContext.Response.OnStarting(state => 141httpContext.Response.OnCompleted(state => 165httpContext.Response.OnStarting(state => 170httpContext.Response.OnCompleted(state => 194httpContext.Response.OnStarting(state => 199httpContext.Response.OnCompleted(state => 205Assert.Throws<InvalidTimeZoneException>(() => httpContext.Response.Body.Write(new byte[10], 0, 10)); 240Assert.False(httpContext.Response.HasStarted); 241httpContext.Response.StatusCode = 400; 242httpContext.Response.ContentType = "text/plain"; 243await httpContext.Response.WriteAsync("Body");
ResponseTrailersTests.cs (30)
28Assert.False(httpContext.Response.SupportsTrailers()); 46Assert.True(httpContext.Response.SupportsTrailers()); 63Assert.True(httpContext.Response.SupportsTrailers()); 66Assert.Throws<InvalidOperationException>(() => httpContext.Response.AppendTrailer(header, "value")); 84httpContext.Response.DeclareTrailer("trailername"); 85httpContext.Response.AppendTrailer("trailername", "TrailerValue"); 103await httpContext.Response.WriteAsync("Hello World"); 104httpContext.Response.AppendTrailer("TrailerName", "Trailer Value"); 124httpContext.Response.ContentLength = body.Length; 125await httpContext.Response.WriteAsync(body); 128Assert.Throws<InvalidOperationException>(() => httpContext.Response.AppendTrailer("TrailerName", "Trailer Value")); 154httpContext.Response.ContentLength = body.Length * 2; 155await httpContext.Response.WriteAsync(body); 156httpContext.Response.AppendTrailer("TrailerName", "Trailer Value"); 157await httpContext.Response.WriteAsync(body); 179httpContext.Response.ContentLength = body.Length; 180httpContext.Response.DeclareTrailer("TrailerName"); 181await httpContext.Response.WriteAsync(body); 182httpContext.Response.AppendTrailer("TrailerName", "Trailer Value"); 205httpContext.Response.ContentLength = body.Length; 206httpContext.Response.DeclareTrailer("TrailerName"); 207await httpContext.Response.WriteAsync(body); 230httpContext.Response.AppendTrailer("trailername", "TrailerValue"); 231await httpContext.Response.CompleteAsync(); 251await httpContext.Response.WriteAsync("Hello World"); 252httpContext.Response.AppendTrailer("TrailerName", "Trailer Value"); 253await httpContext.Response.CompleteAsync(); 273httpContext.Response.AppendTrailer("trailername", new StringValues(new[] { "TrailerValue0", "TrailerValue1" })); 301httpContext.Response.AppendTrailer("ThisIsALongerHeaderNameThatStillWorksForReals", new StringValues(values)); 321httpContext.Response.AppendTrailer(headerName, headerValue);
ServerTests.cs (21)
119httpContext.Response.ContentLength = 11; 120return httpContext.Response.WriteAsync("Hello World"); 135httpContext.Response.ContentLength = 11; 136await httpContext.Response.WriteAsync("Hello World"); 152httpContext.Response.ContentLength = 11; 153return httpContext.Response.WriteAsync("Hello World"); 174httpContext.Response.ContentLength = 11; 175await httpContext.Response.WriteAsync("Hello World"); 195httpContext.Response.ContentLength = 11; 196await httpContext.Response.WriteAsync("Hello World"); 424httpContext.Response.ContentLength = 11; 425await httpContext.Response.WriteAsync("Hello World"); 458httpContext.Response.ContentLength = 11; 459await httpContext.Response.WriteAsync("Hello World"); 495httpContext.Response.ContentLength = 11; 496await httpContext.Response.WriteAsync("Hello World"); 532httpContext.Response.ContentLength = 11; 533await httpContext.Response.WriteAsync("Hello World"); 571httpContext.Response.ContentLength = 11; 572await httpContext.Response.WriteAsync("Hello World"); 626return httpContext.Response.WriteAsync("Hello World");
Microsoft.AspNetCore.Server.IIS (4)
Core\IISServerAuthenticationHandlerInternal.cs (2)
44_context.Response.StatusCode = 401; 53_context.Response.StatusCode = 403;
IISServerOptions.cs (1)
16/// Gets or sets a value that controls whether synchronous IO is allowed for the <see cref="HttpContext.Request"/> and <see cref="HttpContext.Response"/>
src\Shared\RazorViews\BaseView.cs (1)
84Response = Context.Response;
Microsoft.AspNetCore.Server.IISIntegration (6)
AuthenticationHandler.cs (2)
36_context.Response.StatusCode = 401; 44_context.Response.StatusCode = 403;
IISMiddleware.cs (4)
106httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; 117httpContext.Response.StatusCode = StatusCodes.Status202Accepted; 184context.Response.OnCompleted(ClearUserDelegate, context); 185context.Response.RegisterForDispose(winIdentity);
Microsoft.AspNetCore.Server.Kestrel.Core (1)
KestrelServerOptions.cs (1)
113/// Gets or sets a value that controls whether synchronous IO is allowed for the <see cref="HttpContext.Request"/> and <see cref="HttpContext.Response"/>
Microsoft.AspNetCore.Server.Kestrel.Core.Tests (5)
Http1\Http1ConnectionTests.cs (1)
958await context.Response.Body.WriteAsync(buffer, 0, 10);
src\Servers\Kestrel\shared\test\TestApp.cs (4)
17var response = httpContext.Response; 30var response = httpContext.Response; 47var response = httpContext.Response; 64var response = httpContext.Response;
Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks (5)
Http2\Http2ConnectionEmptyBenchmark.cs (1)
26return ResponseDataLength == 0 ? Task.CompletedTask : httpContext.Response.WriteAsync(_responseData);
Http2\Http2ConnectionHeadersBenchmark.cs (1)
38httpContext.Response.Headers[headerName] = "The quick brown fox jumps over the lazy dog.";
Http3\Http3ConnectionEmptyBenchmark.cs (1)
26return ResponseDataLength == 0 ? Task.CompletedTask : httpContext.Response.WriteAsync(_responseData);
InMemoryTransportBenchmark.cs (1)
253return WriteResponse(httpContext.Response);
NamedPipesTransportBenchmark.cs (1)
151return WriteResponse(httpContext.Response);
Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Tests (7)
WebHostTests.cs (7)
68await context.Response.WriteAsync("hello, world"); 124await context.Response.WriteAsync("hello, world"); 159await context.Response.WriteAsync("hello, world"); 196await context.Response.WriteAsync("hello, world"); 234await context.Response.WriteAsync("hello, world"); 305await context.Response.WriteAsync("hello, world"); 400await context.Response.WriteAsync("hello, world");
Microsoft.AspNetCore.Session (3)
SessionMiddleware.cs (3)
126context.Response.OnStarting(OnStartingCallback, state: this); 143var response = _context.Response; 155return (_shouldEstablishSession |= !_context.Response.HasStarted);
Microsoft.AspNetCore.Session.Tests (5)
SessionTests.cs (5)
183return context.Response.WriteAsync(value.Value.ToString(CultureInfo.InvariantCulture)); 242return context.Response.WriteAsync(value.Value.ToString(CultureInfo.InvariantCulture)); 301return context.Response.WriteAsync(value.Value.ToString(CultureInfo.InvariantCulture)); 404return context.Response.WriteAsync(value.Value.ToString(CultureInfo.InvariantCulture)); 473return context.Response.WriteAsync(responseData);
Microsoft.AspNetCore.SignalR.Client.FunctionalTests (3)
Startup.cs (3)
88context.Response.Cookies.Append("fromNegotiate", "a value"); 119return context.Response.WriteAsync(GenerateJwtToken(name ?? "testuser")); 124return context.Response.WriteAsync(JsonConvert.SerializeObject(new
Microsoft.AspNetCore.SignalR.Tests (1)
Startup.cs (1)
100return context.Response.WriteAsync(GenerateToken(context));
Microsoft.AspNetCore.SpaProxy (4)
SpaProxyMiddleware.cs (4)
55context.Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate, max-age=0"; 60context.Response.ContentType = "text/html"; 62await using var writer = new StreamWriter(context.Response.Body, Encoding.UTF8); 71context.Response.Redirect(_options.Value.GetRedirectUrl());
Microsoft.AspNetCore.SpaServices.Extensions (6)
Proxying\SpaProxy.cs (6)
167context.Response.StatusCode = (int)responseMessage.StatusCode; 175context.Response.Headers[header.Key] = header.Value.ToArray(); 180context.Response.Headers[header.Key] = header.Value.ToArray(); 184context.Response.Headers.Remove("transfer-encoding"); 188await responseStream.CopyToAsync(context.Response.Body, StreamCopyBufferSize, cancellationToken); 256context.Response.StatusCode = 400;
Microsoft.AspNetCore.StaticAssets (15)
Development\StaticAssetDevelopmentRuntimeHandler.cs (11)
98_context.Response.Headers.ETag = ""; 114_context.Response.Headers.ContentLength = stream.Length; 120_context.Response.Headers.ETag = new StringValues([$"\"{eTag}\"", weakETag]); 123return stream.CopyToAsync(_context.Response.Body, cancellationToken); 128_context.Response.Headers.ETag = ""; 130_context.Response.Headers.ETag = GetETag(fileInfo); 131_context.Response.Headers.ContentLength = fileInfo.Length; 132_context.Response.Headers.LastModified = fileInfo.LastModified.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture); 204ctx.Response.OnStarting((context) => 207if (ctx.Response.StatusCode == StatusCodes.Status200OK) 213ctx.Response.GetTypedHeaders().ETag = new EntityTagHeaderValue(GetETag(fileInfo));
StaticAssetsInvoker.cs (4)
155context.Response.ContentLength = _length; 171context.Response.Clear(); 271ResponseHeaders = context.Response.GetTypedHeaders(); 273Response = context.Response;
Microsoft.AspNetCore.StaticAssets.Tests (2)
StaticAssetsIntegrationTests.cs (2)
215context.Response.StatusCode = 400; 272context.Response.StatusCode = 400;
Microsoft.AspNetCore.StaticFiles (9)
Helpers.cs (2)
43context.Response.StatusCode = StatusCodes.Status301MovedPermanently; 46context.Response.Headers.Location = redirect;
HtmlDirectoryFormatter.cs (3)
40context.Response.ContentType = TextHtmlUtf8; 205context.Response.ContentLength = bytes.Length; 206return context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
StaticFileContext.cs (4)
54_response = context.Response; 331context.Response.Clear(); 356await _context.Response.SendFileAsync(_fileInfo, 0, _length, _context.RequestAborted); 389await _context.Response.SendFileAsync(_fileInfo, start, length, _context.RequestAborted);
Microsoft.AspNetCore.StaticFiles.FunctionalTests (3)
FallbackStaticFileTest.cs (2)
43return context.Response.WriteAsync("Hello, world!"); 95return context.Response.WriteAsync("Hello, world!");
StaticFileMiddlewareTests.cs (1)
65return context.Response.WriteAsync("Hi from endpoint.");
Microsoft.AspNetCore.StaticFiles.Tests (11)
DefaultFilesMiddlewareTests.cs (5)
70app.Run(context => context.Response.WriteAsync(context.Request.Path.Value)); 95return context.Response.WriteAsync(context.Request.Path.Value); 112app.Run(context => context.Response.WriteAsync(context.Request.Path.Value)); 152app.Run(context => context.Response.WriteAsync(context.Request.Path.Value)); 218app.Run(context => context.Response.WriteAsync(context.Request.Path.Value));
DirectoryBrowserMiddlewareTests.cs (2)
112c.Response.StatusCode = (int)HttpStatusCode.NotAcceptable; 113return c.Response.WriteAsync("Hi from endpoint.");
StaticFileMiddlewareTests.cs (4)
384ctx.Response.ContentType = "text/customfortest+plain"; 385await ctx.Response.WriteAsync(responseText); 424context.Response.StatusCode = StatusCodes.Status200OK; 450context.Response.StatusCode = (int)errorCode;
Microsoft.AspNetCore.TestHost (10)
ClientHandler.cs (3)
212response.StatusCode = (HttpStatusCode)httpContext.Response.StatusCode; 217response.Content = new StreamContent(httpContext.Response.Body); 219foreach (var header in httpContext.Response.Headers)
TestServer.cs (1)
132/// Gets or sets a value that controls whether synchronous IO is allowed for the <see cref="HttpContext.Request"/> and <see cref="HttpContext.Response"/>. The default value is <see langword="false" />.
TestServerOptions.cs (1)
14/// Gets or sets a value that controls whether synchronous IO is allowed for the <see cref="HttpContext.Request"/> and <see cref="HttpContext.Response"/>. The default value is <see langword="false" />.
WebSocketClient.cs (5)
99if (httpContext.Response.StatusCode != StatusCodes.Status101SwitchingProtocols) 101throw new InvalidOperationException("Incomplete handshake, status code: " + httpContext.Response.StatusCode); 138if (_httpContext.Response.HasStarted) 143_httpContext.Response.StatusCode = StatusCodes.Status101SwitchingProtocols; 146await _httpContext.Response.Body.FlushAsync(_httpContext.RequestAborted); // Send headers to the client
Microsoft.AspNetCore.TestHost.Tests (135)
ClientHandlerTests.cs (32)
58Assert.NotNull(context.Response.Headers); 59Assert.NotNull(context.Response.Body); 60Assert.Equal(200, context.Response.StatusCode); 204context.Response.AppendTrailer("StartTrailer", "Value!"); 206await context.Response.WriteAsync("Hello World"); 207await context.Response.Body.FlushAsync(); 212await context.Response.WriteAsync("Bye World"); 213await context.Response.Body.FlushAsync(); 215context.Response.AppendTrailer("EndTrailer", "Value!"); 302preHasStarted = context.Response.HasStarted; 304await context.Response.StartAsync(); 306postHasStarted = context.Response.HasStarted; 356context.Response.Headers["TestHeader"] = "TestValue:" + requestCount++; 375context.Response.Headers["TestHeader"] = "TestValue"; 408context.Response.Headers["TestHeader"] = "TestValue"; 409await context.Response.WriteAsync("BodyStarted,"); 411await context.Response.WriteAsync("BodyFinished"); 427context.Response.Headers["TestHeader"] = "TestValue"; 428await context.Response.Body.FlushAsync(); 430await context.Response.WriteAsync("BodyFinished"); 446context.Response.Headers["TestHeader"] = "TestValue"; 447await context.Response.Body.FlushAsync(); 468context.Response.Headers["TestHeader"] = "TestValue"; 469await context.Response.Body.FlushAsync(); 526context.Response.Headers["TestHeader"] = "TestValue"; 527await context.Response.WriteAsync("BodyStarted"); 545context.Response.OnStarting(() => 549return context.Response.WriteAsync("Hello World"); 561context.Response.OnStarting(() => 577context.Response.OnStarting(() => 583await context.Response.WriteAsync("Hello World"); 589await context.Response.WriteAsync(ex.ToString());
HttpContextBuilderTests.cs (35)
41Assert.NotNull(context.Response.Headers); 42Assert.NotNull(context.Response.Body); 43Assert.Equal(404, context.Response.StatusCode); 84c.Response.Headers["TestHeader"] = "TestValue"; 91Assert.Equal("TestValue", context.Response.Headers["TestHeader"]); 125c.Response.Headers["TestHeader"] = "TestValue"; 128c.Response.Body.Write(bytes, 0, bytes.Length); 131c.Response.Body.Write(bytes, 0, bytes.Length); 137Assert.Equal("TestValue", context.Response.Headers["TestHeader"]); 138var reader = new StreamReader(context.Response.Body); 152c.Response.Headers["TestHeader"] = "TestValue"; 153await c.Response.WriteAsync("BodyStarted" + Environment.NewLine); 155await c.Response.WriteAsync("BodyFinished"); 161Assert.Equal("TestValue", context.Response.Headers["TestHeader"]); 162var reader = new StreamReader(context.Response.Body); 176c.Response.Headers["TestHeader"] = "TestValue"; 177await c.Response.Body.FlushAsync(); 179await c.Response.WriteAsync("BodyFinished"); 185Assert.Equal("TestValue", context.Response.Headers["TestHeader"]); 187Assert.Equal("BodyFinished", new StreamReader(context.Response.Body).ReadToEnd()); 198c.Response.Headers["TestHeader"] = "TestValue"; 199await c.Response.Body.FlushAsync(); 201await c.Response.WriteAsync("BodyFinished"); 207Assert.Equal("TestValue", context.Response.Headers["TestHeader"]); 208var responseStream = context.Response.Body; 247c.Response.Headers["TestHeader"] = "TestValue"; 248await c.Response.Body.FlushAsync(); 250await c.Response.WriteAsync("BodyFinished"); 256Assert.Equal("TestValue", context.Response.Headers["TestHeader"]); 257var responseStream = context.Response.Body; 288c.Response.Headers["TestHeader"] = "TestValue"; 289await c.Response.WriteAsync("BodyStarted"); 297Assert.Equal("TestValue", context.Response.Headers["TestHeader"]); 298Assert.Equal(11, context.Response.Body.Read(new byte[100], 0, 100)); 300var ex = Assert.Throws<IOException>(() => context.Response.Body.Read(new byte[100], 0, 100));
RequestLifetimeTests.cs (2)
56await httpContext.Response.Body.FlushAsync(); 79await httpContext.Response.WriteAsync("Hello World");
ResponseBodyTests.cs (19)
21var writer = httpContext.Response.BodyWriter; 38await httpContext.Response.StartAsync(); 39var writer = httpContext.Response.BodyWriter; 55await httpContext.Response.StartAsync(); 56httpContext.Response.Body.Write(contentBytes, 0, contentBytes.Length); 57await httpContext.Response.CompleteAsync(); 71await httpContext.Response.StartAsync(); 72httpContext.Response.Body.Write(contentBytes, 0, contentBytes.Length); 73await httpContext.Response.CompleteAsync(); 90await httpContext.Response.StartAsync(); 91await httpContext.Response.Body.WriteAsync(contentBytes, 0, contentBytes.Length); 92httpContext.Response.Body.Flush(); 93await httpContext.Response.CompleteAsync(); 109await httpContext.Response.StartAsync(); 110await httpContext.Response.Body.WriteAsync(contentBytes, 0, contentBytes.Length); 111httpContext.Response.Body.Flush(); 112await httpContext.Response.CompleteAsync(); 131await httpContext.Response.Body.WriteAsync(contentBytes); 133await httpContext.Response.Body.WriteAsync(contentBytes);
ResponseResetTests.cs (2)
113await httpContext.Response.Body.FlushAsync(); 139await httpContext.Response.WriteAsync("Hello World");
TestClientTests.cs (24)
28ctx.Response.WriteAsync(expected); 49return ctx.Response.WriteAsync(expected); 71return ctx.Response.WriteAsync(expected); 91await ctx.Response.WriteAsync(content + " PUT Response"); 110await ctx.Response.WriteAsync(await new StreamReader(ctx.Request.Body).ReadToEndAsync() + " POST Response"); 139ctx.Response.RegisterForDispose(disposable); 140await ctx.Response.Body.WriteAsync(data, 0, 1024); 144await ctx.Response.Body.WriteAsync(data, 1024, 1024); 176await ctx.Response.BodyWriter.FlushAsync(); 181await ctx.Response.WriteAsync("STARTED"); 185await ctx.Response.WriteAsync(requestString + " POST Response"); 274await ctx.Response.BodyWriter.FlushAsync(); 351await ctx.Response.WriteAsync("POST Response"); 413ctx.Response.Headers["test-header"] = "true"; 414await ctx.Response.Body.FlushAsync(); 460ctx.Response.Headers["test-header"] = "true"; 509await ctx.Response.BodyWriter.FlushAsync(); 833await ctx.Response.Body.FlushAsync(); 899return context.Response.WriteAsync("Done"); 924return context.Response.WriteAsync("Done"); 947await ctx.Response.WriteAsync(expected); 973await ctx.Response.WriteAsync(expected); 1000await ctx.Response.WriteAsync(expected); 1037await c.Response.WriteAsync("test");
TestServerTests.cs (21)
146app.Run(ctx => ctx.Response.WriteAsync( 198return context.Response.WriteAsync("RequestServices:" + (context.RequestServices != null)); 216await context.Response.WriteAsync(await sr.ReadToEndAsync()); 244await context.Response.WriteAsync("ApplicationServicesEqual:" + (applicationServices == Services)); 431return context.Response.WriteAsync("Found:" + (service != null)); 457return context.Response.WriteAsync("Success"); 501return context.Response.WriteAsync("Success"); 542return context.Response.WriteAsync("Success"); 563return context.Response.WriteAsync("FoundLogger:" + (logger != null)); 580return context.Response.WriteAsync("HasContext:" + (accessor.HttpContext != null)); 611return context.Response.WriteAsync("HasContext:" + (accessor.Accessor.HttpContext != null)); 632return context.Response.WriteAsync("CreateInvokesApp"); 648await context.Response.WriteAsync("Response"); 649context.Response.Body.Dispose(); 666await context.Response.WriteAsync("Response"); 667context.Response.Body.Dispose(); 731return context.Response.WriteAsync("Hello World"); 784ctx.Response.WriteAsync(ctx.Request.Headers.Host); 877builder.Run(ctx => ctx.Response.WriteAsync("Startup")); 906return context.Response.WriteAsync("FoundService:" + (service != null)); 915return context.Response.WriteAsync("FoundFoo:" + (service != null));
Microsoft.AspNetCore.Tests (10)
WebApplicationTests.cs (10)
1695await c.Response.WriteAsync("Hello World"); 1731await c.Response.WriteAsync("Hello World"); 1929await c.Response.WriteAsync("Hello World"); 1962await c.Response.WriteAsync("Hello World"); 1976await c.Response.WriteAsync("Hello World"); 1981await c.Response.WriteAsync("Hi New"); 2404return context => context.Response.WriteAsync("Hello World"); 3149context.Response.StatusCode = 418; // I'm a teapot 3168c.Response.StatusCode = 203; 3169await c.Response.WriteAsync("Hello Filter");
Microsoft.AspNetCore.WebSockets (3)
WebSocketMiddleware.cs (3)
79context.Response.StatusCode = StatusCodes.Status403Forbidden; 165HandshakeHelpers.GenerateResponseHeaders(!_isH2WebSocket, _context.Request.Headers, subProtocol, _context.Response.Headers); 184_context.Response.Headers.SecWebSocketExtensions = response;
Microsoft.AspNetCore.WebSockets.Tests (4)
KestrelWebSocketHelpers.cs (4)
36if (ct.Response.HasStarted) 41ct.Response.StatusCode = 500; 42ct.Response.Headers.Clear(); 43await ct.Response.WriteAsync(ex.ToString());
MiddlewareAnalysisSample (8)
Startup.cs (8)
38return context.Response.WriteAsync("Hello World"); 62context.Response.ContentType = "text/html"; 63await context.Response.WriteAsync("<html><body>Welcome to the sample<br><br>\r\n"); 64await context.Response.WriteAsync("Click here to take a side branch: <a href=\"/map/foo\">Map</a><br>\r\n"); 65await context.Response.WriteAsync("Click here to throw an exception: <a href=\"/throw\">Throw</a><br>\r\n"); 66await context.Response.WriteAsync("Click here to for a 404: <a href=\"/404\">404</a><br>\r\n"); 67await context.Response.WriteAsync("</body></html>\r\n"); 115Console.WriteLine($"MiddlewareFinished: {name}; {httpContext.Response.StatusCode}");
Mvc.RoutingWebSite (6)
Startup.cs (1)
98return c.Response.WriteAsync("Hello from middleware after routing");
StartupForDynamic.cs (1)
42return c.Response.WriteAsync("Hello from middleware after routing");
StartupForDynamicOrder.cs (1)
76return c.Response.WriteAsync("Hello from middleware after routing");
StartupForFallback.cs (1)
39return c.Response.WriteAsync("Hello from middleware after routing");
StartupRoutingDifferentBranches.cs (1)
73return c.Response.WriteAsync("Hello from middleware after routing");
StartupWithoutEndpointRouting.cs (1)
60return c.Response.WriteAsync("Hello from middleware after routing");
NativeIISSample (45)
Startup.cs (45)
34context.Response.ContentType = "text/plain"; 36await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine); 37await context.Response.WriteAsync(Environment.NewLine); 39await context.Response.WriteAsync("Address:" + Environment.NewLine); 40await context.Response.WriteAsync("Scheme: " + context.Request.Scheme + Environment.NewLine); 41await context.Response.WriteAsync("Host: " + context.Request.Headers["Host"] + Environment.NewLine); 42await context.Response.WriteAsync("PathBase: " + context.Request.PathBase.Value + Environment.NewLine); 43await context.Response.WriteAsync("Path: " + context.Request.Path.Value + Environment.NewLine); 44await context.Response.WriteAsync("Query: " + context.Request.QueryString.Value + Environment.NewLine); 45await context.Response.WriteAsync(Environment.NewLine); 47await context.Response.WriteAsync("Connection:" + Environment.NewLine); 48await context.Response.WriteAsync("RemoteIp: " + context.Connection.RemoteIpAddress + Environment.NewLine); 49await context.Response.WriteAsync("RemotePort: " + context.Connection.RemotePort + Environment.NewLine); 50await context.Response.WriteAsync("LocalIp: " + context.Connection.LocalIpAddress + Environment.NewLine); 51await context.Response.WriteAsync("LocalPort: " + context.Connection.LocalPort + Environment.NewLine); 52await context.Response.WriteAsync("ClientCert: " + context.Connection.ClientCertificate + Environment.NewLine); 53await context.Response.WriteAsync(Environment.NewLine); 55await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine); 59await context.Response.WriteAsync("DisplayName: " + scheme?.DisplayName + Environment.NewLine); 62await context.Response.WriteAsync(Environment.NewLine); 64await context.Response.WriteAsync("Headers:" + Environment.NewLine); 67await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine); 69await context.Response.WriteAsync(Environment.NewLine); 71await context.Response.WriteAsync("Environment Variables:" + Environment.NewLine); 76await context.Response.WriteAsync(key + ": " + value + Environment.NewLine); 78await context.Response.WriteAsync(Environment.NewLine); 81await context.Response.WriteAsync("Server Variables:" + Environment.NewLine); 85await context.Response.WriteAsync(varName + ": " + context.GetServerVariable(varName) + Environment.NewLine); 88await context.Response.WriteAsync(Environment.NewLine); 91await context.Response.WriteAsync("Websocket feature is enabled."); 95await context.Response.WriteAsync("Websocket feature is disabled."); 98await context.Response.WriteAsync(Environment.NewLine); 104await context.Response.WriteAsync(key + Environment.NewLine); 109await context.Response.WriteAsync(Environment.NewLine); 110await context.Response.WriteAsync("IIS Environment Information:" + Environment.NewLine); 111await context.Response.WriteAsync("IIS Version: " + envFeature.IISVersion + Environment.NewLine); 112await context.Response.WriteAsync("ApplicationId: " + envFeature.ApplicationId + Environment.NewLine); 113await context.Response.WriteAsync("Application Path: " + envFeature.ApplicationPhysicalPath + Environment.NewLine); 114await context.Response.WriteAsync("Application Virtual Path: " + envFeature.ApplicationVirtualPath + Environment.NewLine); 115await context.Response.WriteAsync("Application Config Path: " + envFeature.AppConfigPath + Environment.NewLine); 116await context.Response.WriteAsync("AppPool ID: " + envFeature.AppPoolId + Environment.NewLine); 117await context.Response.WriteAsync("AppPool Config File: " + envFeature.AppPoolConfigFile + Environment.NewLine); 118await context.Response.WriteAsync("Site ID: " + envFeature.SiteId + Environment.NewLine); 119await context.Response.WriteAsync("Site Name: " + envFeature.SiteName + Environment.NewLine); 123await context.Response.WriteAsync($"No {nameof(IIISEnvironmentFeature)} available." + Environment.NewLine);
NegotiateAuthSample (1)
Startup.cs (1)
58await context.Response.WriteAsync($"Authenticated? {user.IsAuthenticated}, Name: {user.Name}, Protocol: {context.Request.Protocol}");
OpenIdConnectSample (1)
Startup.cs (1)
149var response = context.Response;
OutputCachingSample (6)
Gravatar.cs (4)
12context.Response.StatusCode = 200; 13context.Response.ContentType = "text/html"; 14await context.Response.WriteAsync($"<img src=\"https://www.gravatar.com/avatar/{hash}?s={size}&d={type}\"/>"); 15await context.Response.WriteAsync($"<pre>Generated at {DateTime.Now:hh:mm:ss.ff}</pre>");
Startup.cs (2)
54await context.Response.WriteAsync($"<pre>{requests++}</pre>"); 64context.Response.Headers.ETag = etag;
PlaintextApp (1)
Startup.cs (1)
26var response = httpContext.Response;
QueueSharing (3)
Program.cs (3)
61context.Response.ContentType = "text/plain"; 66context.Response.Headers["Connection"] = "close"; 67await context.Response.WriteAsync("Hello world from " + context.Request.Host + " at " + DateTime.Now);
RateLimitingSample (1)
SampleRateLimiterPolicy.cs (1)
17context.HttpContext.Response.StatusCode = 429;
RazorPagesWebSite (4)
CustomActionResult.cs (2)
12context.HttpContext.Response.StatusCode = 200; 13return context.HttpContext.Response.WriteAsync(nameof(CustomActionResult));
Pages\Filters\TestPageFilter.cs (1)
16context.HttpContext.Response.Headers["PageFilterKey"] = "PageFilterValue";
Pages\Filters\TestPageModelFilter.cs (1)
16context.HttpContext.Response.Headers["PageModelFilterKey"] = "PageModelFilterValue";
RequestDecompressionSample (1)
Startup.cs (1)
26await context.Response.WriteAsync(decompressedBody, context.RequestAborted);
ResponseCachingSample (3)
Startup.cs (3)
20context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue() 25context.Response.Headers.Vary = new string[] { "Accept-Encoding" }; 27await context.Response.WriteAsync("Hello World! " + DateTime.UtcNow);
ResponseCompressionSample (7)
Startup.cs (7)
37context.Response.ContentType = "text/plain"; 38return context.Response.SendFileAsync("testfile1kb.txt"); 46context.Response.ContentType = "text/plain"; 52await context.Response.WriteAsync("a"); 53await context.Response.Body.FlushAsync(); 61context.Response.ContentType = "text/plain"; 62await context.Response.WriteAsync(LoremIpsum.Text);
RewriteSample (1)
Startup.cs (1)
36return context.Response.WriteAsync($"Rewritten Url: {context.Request.Path + context.Request.QueryString}");
RoutingSandbox (11)
HelloExtension\HelloMiddleware.cs (1)
32var response = context.Response;
UseEndpointRoutingStartup.cs (8)
48var response = httpContext.Response; 57var response = httpContext.Response; 68using (var writer = new StreamWriter(httpContext.Response.Body, Encoding.UTF8, 1024, leaveOpen: true)) 87frameworkBuilder.AddHubMethod("TestHub", "TestMethod", context => context.Response.WriteAsync("TestMethod!")); 88frameworkBuilder.AddHubMethod("Login", "Authenticate", context => context.Response.WriteAsync("Authenticate!")); 89frameworkBuilder.AddHubMethod("Login", "Logout", context => context.Response.WriteAsync("Logout!")); 98return context.Response.WriteAsync("I have ann authorize attribute"); 104return context.Response.WriteAsync("I have a method metadata attribute");
UseRouterStartup.cs (2)
25return httpContext.Response.WriteAsync($"Verb = {request.Method.ToUpperInvariant()} - Path = {request.Path} - Route values - {string.Join(", ", httpContext.GetRouteData().Values)}"); 29.MapMiddlewareRoute("api/middleware", (appBuilder) => appBuilder.Run(httpContext => httpContext.Response.WriteAsync("Middleware!")))
RoutingWebSite (14)
HelloExtension\HelloMiddleware.cs (1)
32var response = context.Response;
MapFallbackStartup.cs (2)
20return context.Response.WriteAsync("FallbackCustomPattern"); 25return context.Response.WriteAsync("FallbackDefaultPattern");
UseEndpointRoutingStartup.cs (9)
50var response = httpContext.Response; 59var response = httpContext.Response; 71return httpContext.Response.WriteAsync((endpoint.Metadata.GetMetadata<CustomMetadata>() != null) ? "Has metadata" : "No metadata"); 80var response = httpContext.Response; 89var response = httpContext.Response; 100var response = httpContext.Response; 112var response = httpContext.Response; 141var response = httpContext.Response; 161endpoints.MapGet("api/get/{id}", (context) => context.Response.WriteAsync($"{name} - API Get {context.Request.RouteValues["id"]}"));
UseRouterStartup.cs (2)
25return httpContext.Response.WriteAsync($"Verb = {request.Method.ToUpperInvariant()} - Path = {request.Path} - Route values - {string.Join(", ", httpContext.GetRouteData().Values)}"); 29.MapMiddlewareRoute("api/middleware", (appBuilder) => appBuilder.Run(httpContext => httpContext.Response.WriteAsync("Middleware!")))
SampleStartups (6)
StartupBlockingOnStart.cs (1)
28await context.Response.WriteAsync("Hello World!");
StartupConfigureAddresses.cs (1)
21await context.Response.WriteAsync("Hello World!");
StartupExternallyControlled.cs (1)
23await context.Response.WriteAsync("Hello World!");
StartupHelloWorld.cs (1)
20await context.Response.WriteAsync("Hello World!");
StartupInjection.cs (2)
54await context.Response.WriteAsync("Hello World!"); 71await context.Response.WriteAsync("Hello World!");
SelfHostServer (2)
Startup.cs (2)
30context.Response.ContentType = "text/plain"; 31await context.Response.WriteAsync("Hello world from " + context.Request.Host + " at " + DateTime.Now);
ServerComparison.TestSites (30)
Startup.cs (1)
25return ctx.Response.WriteAsync("Hello World " + RuntimeInformation.ProcessArchitecture);
StartupNtlmAuthentication.cs (7)
37if (context.Response.HasStarted) 41context.Response.Clear(); 42context.Response.StatusCode = 500; 43await context.Response.WriteAsync(ex.ToString()); 52return context.Response.WriteAsync("Anonymous?" + !context.User.Identity.IsAuthenticated); 59return context.Response.WriteAsync("Authenticated"); 72return context.Response.WriteAsync("Hello World");
StartupResponseCompression.cs (9)
28context.Response.ContentType = "text/plain"; 29context.Response.ContentLength = helloWorldBody.Length; 30return context.Response.WriteAsync(helloWorldBody); 39context.Response.ContentType = "text/plain"; 40context.Response.ContentLength = helloWorldBody.Length; 41return context.Response.WriteAsync(helloWorldBody); 46context.Response.ContentType = "text/plain"; 57context.Response.ContentLength = body.Length; 58return context.Response.WriteAsync(body);
StartupResponses.cs (13)
19context.Response.ContentLength = 14; 20return context.Response.WriteAsync("Content Length"); 28context.Response.Headers.Connection = "close"; 29await context.Response.WriteAsync("Connnection Close"); 30await context.Response.Body.FlushAsync(); // Bypass IIS write-behind buffering 38await context.Response.WriteAsync("Chunked"); 39await context.Response.Body.FlushAsync(); // Bypass IIS write-behind buffering 47context.Response.Headers.TransferEncoding = "chunked"; 48return context.Response.WriteAsync("10\r\nManually Chunked\r\n0\r\n\r\n"); 56context.Response.Headers.Connection = "close"; 57context.Response.Headers.TransferEncoding = "chunked"; 58return context.Response.WriteAsync("1A\r\nManually Chunked and Close\r\n0\r\n\r\n"); 64return context.Response.WriteAsync("Running");
SessionSample (7)
Startup.cs (7)
53await context.Response.WriteAsync("Counting: You have visited our page this many times: " + visits); 61await context.Response.WriteAsync("<html><body>"); 64await context.Response.WriteAsync("Your session has not been established.<br>"); 65await context.Response.WriteAsync(DateTime.Now + "<br>"); 66await context.Response.WriteAsync("<a href=\"/session\">Establish session</a>.<br>"); 71await context.Response.WriteAsync("Your session was located, you've visited the site this many times: " + visits); 73await context.Response.WriteAsync("</body></html>");
SignalR.Client.FunctionalTestApp (15)
Startup.cs (15)
126context.Response.Headers.AccessControlAllowOrigin = originHeader; 127context.Response.Headers.AccessControlAllowCredentials = "true"; 132context.Response.Headers.AccessControlAllowMethods = requestMethod; 138context.Response.Headers.AccessControlAllowHeaders = requestHeaders; 145context.Response.StatusCode = StatusCodes.Status204NoContent; 159context.Response.Redirect(url, false, true); 171return context.Response.WriteAsync($"{{ \"url\": \"{newUrl}\" }}"); 193context.Response.Cookies.Append("testCookie", "testValue", cookieOptions); 194context.Response.Cookies.Append("testCookie2", "testValue2", cookieOptions); 197context.Response.Cookies.Append("expiredCookie", "doesntmatter", expiredCookieOptions); 207context.Response.StatusCode = 400; 208return context.Response.WriteAsync("Some response from server"); 243return context.Response.WriteAsync(GenerateJwtToken()); 263context.Response.ContentType = "application/json"; 264using (var textWriter = new StreamWriter(context.Response.Body))
SignalRSamples (2)
Startup.cs (2)
54context.Response.ContentType = "application/json"; 55await using (var writer = new Utf8JsonWriter(context.Response.BodyWriter, _jsonWriterOptions))
SocialSample (5)
Startup.cs (5)
259var response = context.Response; 277var response = context.Response; 398var response = context.Response; 413var response = context.Response; 447var response = context.Response;
Sockets.BindTests (3)
SocketTransportOptionsTests.cs (1)
120app => app.Run(ctx => ctx.Response.WriteAsync("Hello World"))
src\Servers\Kestrel\test\BindTests\AddressRegistrationTests.cs (2)
251return context.Response.WriteAsync(serverAddresses.Addresses.First()); 1189return context.Response.WriteAsync(context.Request.GetDisplayUrl());
Sockets.FunctionalTests (36)
src\Servers\Kestrel\shared\test\TestApp.cs (4)
17var response = httpContext.Response; 30var response = httpContext.Response; 47var response = httpContext.Response; 64var response = httpContext.Response;
src\Servers\Kestrel\test\FunctionalTests\Http2\HandshakeTests.cs (2)
76return context.Response.WriteAsync("hello world " + context.Request.Protocol); 104return context.Response.WriteAsync("hello world " + context.Request.Protocol);
src\Servers\Kestrel\test\FunctionalTests\Http2\ShutdownTests.cs (3)
73return context.Response.WriteAsync("hello world " + context.Request.Protocol); 130await context.Response.WriteAsync("hello world " + context.Request.Protocol); 181await context.Response.WriteAsync("hello world " + context.Request.Protocol);
src\Servers\Kestrel\test\FunctionalTests\MaxRequestBufferSizeTests.cs (3)
357context.Response.StatusCode = StatusCodes.Status500InternalServerError; 358await context.Response.WriteAsync("Client sent more bytes than expectedBody.Length"); 362await context.Response.WriteAsync($"bytesRead: {bytesRead}");
src\Servers\Kestrel\test\FunctionalTests\RequestTests.cs (4)
106await context.Response.WriteAsync($"bytesRead: {total}"); 173await context.Response.WriteAsync("hello, world"); 859var response = httpContext.Response; 1106await context.Response.WriteAsync(JsonConvert.SerializeObject(new
src\Servers\Kestrel\test\FunctionalTests\ResponseTests.cs (19)
61context.Response.ContentLength = bytes.Length * 1024; 65await context.Response.BodyWriter.WriteAsync(new Memory<byte>(bytes, 0, bytes.Length)); 113context.Response.Headers.Add(headerName, headerValue); 115await context.Response.WriteAsync(""); 160httpContext.Response.ContentLength = 12; 161await httpContext.Response.WriteAsync("hello, world"); 212var response = httpContext.Response; 309await context.Response.BodyWriter.WriteAsync(new Memory<byte>(scratchBuffer, 0, scratchBuffer.Length), context.RequestAborted); 372await context.Response.Body.WriteAsync(scratchBuffer, 0, scratchBuffer.Length); 527context.Response.ContentLength = responseSize; 535await context.Response.BodyWriter.WriteAsync(new Memory<byte>(chunkData, 0, chunkData.Length), context.RequestAborted); 667context.Response.ContentLength = chunks * chunkSize; 673await context.Response.BodyWriter.WriteAsync(new Memory<byte>(chunkData, 0, chunkData.Length), context.RequestAborted); 786await context.Request.Body.CopyToAsync(context.Response.Body); 888await context.Response.BodyWriter.WriteAsync(new Memory<byte>(chunkData, 0, chunkData.Length), context.RequestAborted); 963context.Response.Headers[$"X-Custom-Header"] = headerStringValues; 964context.Response.ContentLength = 0; 966await context.Response.BodyWriter.FlushAsync(); 1052await context.Response.BodyWriter.WriteAsync(new Memory<byte>(chunkData, 0, chunkData.Length), context.RequestAborted);
src\Servers\Kestrel\test\FunctionalTests\UnixDomainSocketsTests.cs (1)
153await context.Response.WriteAsync("Hello World");
StartRequestDelegateUrlApp (1)
Program.cs (1)
24await context.Response.WriteAsync(env.ApplicationName);
StartWithIApplicationBuilderUrlApp (1)
Program.cs (1)
27await context.Response.WriteAsync(env.ApplicationName);
StatusCodePagesSample (5)
Startup.cs (5)
38context.Response.StatusCode = int.Parse(requestedStatusCode, CultureInfo.InvariantCulture); 74context.Response.ContentType = "text/html"; 75await context.Response.WriteAsync(builder.ToString()); 102context.Response.ContentType = "text/html"; 103await context.Response.WriteAsync(builder.ToString());
SystemdTestApp (3)
Startup.cs (3)
33context.Response.ContentLength = response.Length; 34context.Response.ContentType = "text/plain"; 35await context.Response.WriteAsync(response);
Wasm.Performance.Driver (1)
BenchmarkResultsStartup.cs (1)
26await context.Response.WriteAsync("OK");
WebPubSubWeb (4)
Program.cs (4)
54context.Response.Headers["WebHook-Allowed-Origin"] = "*"; 57context.Response.StatusCode = 200; 63context.Response.StatusCode = 400; 66context.Response.StatusCode = 200;
WebTransportInteractiveSampleApp (2)
Program.cs (2)
49context.Response.ContentType = "application/javascript"; 50await context.Response.WriteAsync($"var CERTIFICATE = '{certStr}';");
WsFedSample (8)
Startup.cs (8)
48await WriteHtmlAsync(context.Response, async res => 59await WriteHtmlAsync(context.Response, async res => 61await context.Response.WriteAsync($"<h1>Signed out {HtmlEncode(context.User.Identity.Name)}</h1>"); 62await context.Response.WriteAsync("<a class=\"btn btn-link\" href=\"/\">Sign In</a>"); 80await WriteHtmlAsync(context.Response, async res => 82await context.Response.WriteAsync($"<h1>Access Denied for user {HtmlEncode(context.User.Identity.Name)} to resource '{HtmlEncode(context.Request.Query["ReturnUrl"])}'</h1>"); 83await context.Response.WriteAsync("<a class=\"btn btn-link\" href=\"/signout\">Sign Out</a>"); 116await WriteHtmlAsync(context.Response, async response =>