本文整理汇总了C#中IRequestContext.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IRequestContext.Write方法的具体用法?C# IRequestContext.Write怎么用?C# IRequestContext.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRequestContext
的用法示例。
在下文中一共展示了IRequestContext.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnHandleRequest
//.........这里部分代码省略.........
{
var e = new HttpAfterRequestEventArgs(request, response, skipped, error);
e.Handled = true;
this.RaiseEventHandler(this.AfterRequest, e);
if (!e.Handled)
{
if (e.Error != null)
{
throw e.Error;
}
}
}
var encoder = this.GetResponseEncoder(request, response) ?? Encoding.ASCII;
var newLine = StringHelper.AsString(this.GetNewLine(request, response)) ?? "\r\n";
var statusDescription = (response.Status ?? string.Empty).Trim();
if (statusDescription != "")
{
statusDescription = " " + statusDescription;
}
var code = response.Code;
var contentLength = response.ContentLength;
var headers = response.Headers;
var version = response.Version;
int? bufferReadSize = null;
var updateHeaders = true;
Action<string, object> sendHeader = (headerName, headerValue) =>
{
context.Write(encoder.GetBytes(string.Format("{0}: {1}{2}",
headerName, headerValue,
newLine)));
};
Action unsetOutputStream = () =>
{
outputStream = null;
//TODO dispose
};
Action sendOutputStream = () =>
{
if (outputStream == null)
{
return;
}
long? oldPosition = null;
try
{
if (outputStream.CanSeek)
{
oldPosition = outputStream.Position;
outputStream.Position = 0;
}
var buffer = new byte[response.ReadBufferSize ?? 10240];
int bytesRead;
while ((bytesRead = outputStream.Read(buffer, 0, buffer.Length)) > 0)