// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-#if NET_2_0
+
+#if NET_2_0 && SECURITY_DEP
+
using System.Globalization;
using System.IO;
using System.Text;
public Stream OutputStream {
get {
- if (disposed)
- throw new ObjectDisposedException (GetType ().ToString ());
-
if (output_stream == null)
output_stream = context.Connection.GetResponseStream ();
return output_stream;
if (cookie == null)
throw new ArgumentNullException ("cookie");
- cookies.Add (cookie);
+ Cookies.Add (cookie);
}
public void AppendHeader (string name, string value)
return false;
}
- internal void SendHeaders (bool closing)
+ internal void SendHeaders (bool closing, MemoryStream ms)
{
//TODO: When do we send KeepAlive?
- //TODO: send cookies
- MemoryStream ms = new MemoryStream ();
Encoding encoding = content_encoding;
if (encoding == null)
encoding = Encoding.Default;
status_code == 413 || status_code == 414 || status_code == 500 ||
status_code == 503);
- if (conn_close == false)
+ if (conn_close == false) {
conn_close = (context.Request.Headers ["connection"] == "close");
+ conn_close |= (v <= HttpVersion.Version10);
+ }
// They sent both KeepAlive: true and Connection: close!?
- if (!chunked || conn_close)
+ if (!keep_alive || conn_close)
headers.SetInternal ("Connection", "close");
if (chunked)
if (location != null)
headers.SetInternal ("Location", location);
+ if (cookies != null) {
+ bool firstDone = false;
+ StringBuilder cookieSB = new StringBuilder ();
+ foreach (Cookie cookie in cookies) {
+ if (firstDone)
+ cookieSB.Append (",");
+ firstDone = true;
+ cookieSB.Append (cookie.ToClientString ());
+ }
+ headers.SetInternal("Set-Cookie2", cookieSB.ToString ());
+ }
+
StreamWriter writer = new StreamWriter (ms, encoding);
writer.Write ("HTTP/{0} {1} {2}\r\n", version, status_code, status_description);
string headers_str = headers.ToString ();
writer.Write (headers_str);
writer.Flush ();
- // Perf.: use TCP_CORK if we're writing more?
int preamble = encoding.GetPreamble ().Length;
if (output_stream == null)
output_stream = context.Connection.GetResponseStream ();
- output_stream.InternalWrite (ms.GetBuffer (), 0 + preamble, (int) ms.Length - preamble);
+ /* Assumes that the ms was at position 0 */
+ ms.Position = preamble;
HeadersSent = true;
}