コード例 #1
0
        public async Task CopyFrom_AllValues_ReturnsClone()
        {
            using (HttpListenerResponse response1 = await GetResponse())
                using (HttpListenerResponse response2 = await new HttpListenerResponseTests().GetResponse())
                {
                    // CopyFrom overrides old headers.
                    response2.Headers.Add("Name2", "Value2");

                    response1.Headers.Add("Name", "Value");
                    response1.SendChunked       = false;
                    response1.ContentLength64   = 10;
                    response1.StatusCode        = 404;
                    response1.ProtocolVersion   = new Version(1, 0);
                    response1.StatusDescription = "Description";
                    response1.KeepAlive         = true;

                    response2.CopyFrom(response1);
                    Assert.Equal(response1.Headers, response2.Headers);
                    Assert.Equal(response1.SendChunked, response2.SendChunked);
                    Assert.Equal(response1.ContentLength64, response2.ContentLength64);
                    Assert.Equal(response1.StatusCode, response2.StatusCode);
                    Assert.Equal(response1.ProtocolVersion, response2.ProtocolVersion);
                    Assert.Equal(response1.KeepAlive, response2.KeepAlive);

                    try
                    {
                        response1.OutputStream.Write(new byte[10], 0, 10);
                        response2.OutputStream.Write(new byte[10], 0, 10);
                    }
                    catch (HttpListenerException)
                    {
                        // This test sometimes fails with: "An operation was attempted on a nonexistent network connection".
                    }
                }
        }
コード例 #2
0
 public async Task CopyFrom_NullTemplateResponse_ThrowsNullReferenceException()
 {
     using (HttpListenerResponse response = await GetResponse())
     {
         Assert.Throws <NullReferenceException>(() => response.CopyFrom(null));
     }
 }
コード例 #3
0
ファイル: sample.cs プロジェクト: mairaw/dotnet-api-docs
    static void SendBadCertificateResponse(HttpListenerResponse response)
    {
        if (preMade403Response == null)
        {
            // Set up an authentication error response template.
            response.StatusCode        = (int)HttpStatusCode.Forbidden;
            response.StatusDescription = "403 Forbidden";
            response.ProtocolVersion   = new Version("1.1");
            response.SendChunked       = false;

            preMade403Response = response;
        }
        else
        {
            response.CopyFrom(preMade403Response);
        }

        // The response body cannot be saved in the template.

        StringBuilder message = new StringBuilder();

        message.Append("<HTML><BODY>");
        message.Append("<p> Error message 403: Access is denied due to a missing or invalid client certificate.</p>");
        message.Append("</BODY></HTML>");
        message403 = message.ToString();

        // Turn the error message into a byte array using the
        // encoding from the response when present.
        System.Text.Encoding encoding = response.ContentEncoding;
        if (encoding == null)
        {
            encoding = System.Text.Encoding.UTF8;
            response.ContentEncoding = encoding;
        }

        byte[] buffer = encoding.GetBytes(message403);
        response.ContentLength64 = buffer.Length;
        // Write the error message.
        System.IO.Stream stream = response.OutputStream;
        stream.Write(buffer, 0, buffer.Length);
        // Send the response.
        response.Close();
    }
コード例 #4
0
 public void CopyFrom(HttpListenerResponse templateResponse) => inner.CopyFrom(templateResponse);
コード例 #5
0
ファイル: HttpResponse.cs プロジェクト: aautar/Grapevine
 public void CopyFrom(HttpResponse templateResponse)
 {
     Response.CopyFrom(templateResponse.Response);
 }
コード例 #6
0
 //
 // Summary:
 //     Copies properties from the specified System.Net.HttpListenerResponse to this
 //     response.
 //
 // Parameters:
 //   templateResponse:
 //     The System.Net.HttpListenerResponse instance to copy.
 public void CopyFrom(HttpListenerResponse templateResponse)
 {
     response.CopyFrom(templateResponse);
 }