src/Foundation/Net/Gimela.Net.Http/Messages/ResponseWriter.cs
/// <summary>
/// Send all headers to the client
/// </summary>
/// <param name="response">Response containing call headers.</param>
/// <param name="context">Content used to send headers.</param>
Send all headers to the client
Send all headers to the client
public void SendHeaders(IHttpContext context, IResponse response)
    {
      var sb = new StringBuilder();
      sb.AppendFormat("{0} {1} {2}\r\n", response.HttpVersion, (int)response.Status, response.Reason);
      sb.AppendFormat("{0}: {1}\r\n", response.ContentType.Name, response.ContentType);
      sb.AppendFormat("{0}: {1}\r\n", response.ContentLength.Name, response.ContentLength);
      sb.AppendFormat("{0}: {1}\r\n", response.Connection.Name, response.Connection);
      if (response.Cookies != null && response.Cookies.Count > 0)
      {
        foreach (ResponseCookie cookie in response.Cookies)
        {
          sb.Append("Set-Cookie: ");
          sb.Append(cookie.Name);
          sb.Append("=");
          sb.Append(cookie.Value ?? string.Empty);
          if (cookie.Expires > DateTime.MinValue)
            sb.Append(";expires=" + cookie.Expires.ToString("R"));
          if (!string.IsNullOrEmpty(cookie.Path))
            sb.AppendFormat(";path={0}", cookie.Path);
          sb.Append("\r\n");
        }
      }
      foreach (IHeader header in response)
        sb.AppendFormat("{0}: {1}\r\n", header.Name, header);
      sb.Append("\r\n");
      Send(context, sb.ToString(), response.Encoding);
      HeadersSent(this, EventArgs.Empty);
    }
public void SendHeaders ( IHttpContext context , IResponse response ) { var sb = new StringBuilder ( ) ; sb . AppendFormat ( " \r \n " , response . HttpVersion , ( int ) response . Status , response . Reason ) ; sb . AppendFormat ( " \r \n " , response . ContentType . Name , response . ContentType ) ; sb . AppendFormat ( " \r \n " , response . ContentLength . Name , response . ContentLength ) ; sb . AppendFormat ( " \r \n " , response . Connection . Name , response . Connection ) ; if ( response . Cookies != null && response . Cookies . Count > 0 ) { foreach ( ResponseCookie cookie in response . Cookies ) { sb . Append ( " " ) ; sb . Append ( cookie . Name ) ; sb . Append ( " " ) ; sb . Append ( cookie . Value ?? string . Empty ) ; if ( cookie . Expires > DateTime . MinValue ) sb . Append ( " " + cookie . Expires . ToString ( " " ) ) ; if ( ! string . IsNullOrEmpty ( cookie . Path ) ) sb . AppendFormat ( " " , cookie . Path ) ; sb . Append ( " \r \n " ) ; } } foreach ( IHeader header in response ) sb . AppendFormat ( " \r \n " , header . Name , header ) ; sb . Append ( " \r \n " ) ; Send ( context , sb . ToString ( ) , response . Encoding ) ; HeadersSent ( this , EventArgs . Empty ) ; }
Send all headers to the client
Send all headers to the client
// replace content-type name with the actual one used. //response.ContentType.Parameters["charset"] = response.Encoding.WebName; // go through all property headers. //Set-Cookie: <name>=<value>[; <name>=<value>][; expires=<date>][; domain=<domain_name>][; path=<some_path>][; secure][; httponly]
context
IHttpContext
Content used to send headers.
Content used to send headers .
response
IResponse
Response containing call headers.
Response containing call headers .