本文整理汇总了C#中IResponse.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.Add方法的具体用法?C# IResponse.Add怎么用?C# IResponse.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IResponse
的用法示例。
在下文中一共展示了IResponse.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateChallenge
/// <summary>
/// Create a challenge header (WWW-authenticate)
/// </summary>
/// <param name="response">Response that the authentication header should be added to</param>
/// <param name="realm">Realm that the user should authenticate in</param>
/// <returns>WWW-Authenticate header.</returns>
/// <remarks>
/// <para>
/// Scheme can currently be <c>basic</c> or <c>digest</c>. Basic is not very safe, but easier to use.
/// Digest is quite safe.
/// </para><para>
/// </para>
/// </remarks>
/// <exception cref="NotSupportedException">Requested scheme is not supported.</exception>
public void CreateChallenge(IResponse response, string realm)
{
foreach (var authenticator in _authenticators.Values)
{
var header= authenticator.CreateChallenge(realm);
response.Add(header.Name, header);
}
}
示例2: WriteResponseHeaders
private void WriteResponseHeaders(IResponse originalResponse, HttpWebResponse response)
{
foreach(string headerName in response.Headers.AllKeys)
{
if(IsNotSettableHeader(headerName))
continue;
/*IHeader header = originalResponse.Headers[headerName];
if(header != null)
header.HeaderValue = ProcessResponseValue(response.Headers[headerName]);
else*/
originalResponse.Add(new StringHeader(headerName, ProcessResponseValue(response.Headers[headerName])));
}
}
示例3: OnRequest
/// <summary>
/// 消息解析器解析出一个请求消息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnRequest(object sender, FactoryRequestEventArgs e)
{
_context = this;
// 根据请求消息内容生成响应消息
Response = HttpFactory.Current.Get<IResponse>(this, e.Request);
Logger.Debug("Received '" + e.Request.Method + " " + e.Request.Uri.PathAndQuery + "' from " + Socket.RemoteEndPoint);
// 如果请求连接中设置了保活
if (e.Request.Connection != null && e.Request.Connection.Type == ConnectionType.KeepAlive)
{
Response.Add(new StringHeader("Keep-Alive", "timeout=5, max=100"));
// 刷新计时器
if (_keepAlive != null)
_keepAlive.Change(_keepAliveTimeout, _keepAliveTimeout);
}
// 记录请求消息
Request = e.Request;
// 通知处理请求
CurrentRequestReceived(this, new RequestEventArgs(this, e.Request, Response));
RequestReceived(this, new RequestEventArgs(this, e.Request, Response));
// 如果请求连接中设置了保活,记录请求处理的超时时间
if (Response.Connection.Type == ConnectionType.KeepAlive)
{
if (_keepAlive == null)
_keepAlive = new Timer(OnKeepAliveTimeout, null, _keepAliveTimeout, _keepAliveTimeout);
}
// 通知请求处理完毕
RequestCompleted(this, new RequestEventArgs(this, e.Request, Response));
CurrentRequestCompleted(this, new RequestEventArgs(this, e.Request, Response));
}