[Mono-bugs] [Bug 341443] New: HttpListener - Bad Request (Invalid Url)

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Nov 13 14:22:47 EST 2007


https://bugzilla.novell.com/show_bug.cgi?id=341443

           Summary: HttpListener - Bad Request (Invalid Url)
           Product: Mono: Class Libraries
           Version: unspecified
          Platform: i686
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at ximian.com
        ReportedBy: brinn at crowdus.com
         QAContact: mono-bugs at ximian.com
          Found By: Other


Description of Problem:


Steps to reproduce the problem:
1. Create a console application that uses the HttpListener on any port.
2. Start the application.
3. Configure either IE 7, Firefox (2.0.0.9), or Opera 9.23 (happens from all)
to use a proxy that the HttpListener is on.
4. Access any website. I use http://www.google.com The result is a 400 Bad
Request with a body of Bad Request (Invalid url).
5. If you remove the proxy settings in either of the browsers and access the
the machine and port the HttpListener is on you get the results in the Response
Stream.
6. Run the application under Microsoft's .NET Framework and you get the
different results when access the application as a Proxy.

Actual Results:
400 Bad Request

Expected Results:
Output from HttpListener / HttpListenerResponse (As a Proxy)

How often does this happen? 
Always.

Additional Information:

All three browser request a url with a relative url in the initial request
line.when not using a proxy. All three request a url with an absolute url in
the initial request line when using a Proxy Server.

*** No Proxy ***
GET / HTTP/1.1
Host: www.google.com

*** Proxy ***
GET http://www.google.com HTTP/1.1
Host: www.google.com

The HttpListener instance never gets the Context when this error happens, so
this leads one to believe that this is happending building the
HttpListenerRequest object. It looks as though the Relative vs Absolute Url
Request is not handled.

Again as stated above this works under the .NET 2.0 implementation. I have
attached a very simple console application that I used to reproduce the bug.

**********************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;


namespace ConsoleApplication
{    
    internal class Program
    {
        static void Main ( string[] args )
        {
            Server http = new Server();
            Proxy proxy = new Proxy();

            new Thread( http.Run ).Start();
            new Thread( proxy.Run ).Start();
            Console.Read();
            http.Stop();
            proxy.Stop();
        }
    }

    internal class Proxy
    {
        private TcpListener Listener = new TcpListener( IPAddress.Loopback,
8081 );

        public Proxy ( )
        {
            Listener.Start();
        }
        public void Stop ( )
        {

            Listener.Stop();
        }
        public void Run ( )
        {
            Socket client;
            try
            {
                while ( true )
                {
                    client = Listener.AcceptSocket();
                    byte[] buffer = new byte[4096];

                    client.Receive( buffer );
                    Console.WriteLine( Encoding.UTF8.GetString( buffer ) );

                    StringBuilder response = new StringBuilder();
                    response.AppendLine( "HTTP/1.1 200 OK" );
                    response.AppendLine( "Content-Type: text/html;
charset=UTF-8" );
                    response.AppendLine( "Content-Length: 6" );
                    response.AppendLine( "Connection: close" );
                    response.AppendLine( "" );
                    response.AppendLine( "NoPage" );

                    buffer = Encoding.UTF8.GetBytes( response.ToString() );
                    client.Send( buffer );
                    client.Shutdown( SocketShutdown.Both );
                    client.Close();
                }
            }
            catch ( SocketException )
            { }

        }
    }
    internal class Server
    {
        private HttpListener Listener = new HttpListener();
        public Server ( )
        {
            Listener.Prefixes.Add( @"http://*:8080/" );
            Listener.Start();
        }
        public void Stop ( )
        {
            Listener.Stop();
        }
        public void Run ( )
        {
            while ( Listener.IsListening )
            {
                try
                {
                    HttpListenerContext context = Listener.GetContext();

                    using ( StreamWriter writer = new StreamWriter(
context.Response.OutputStream ) )
                    {
                        writer.WriteLine( "<html>" );
                        writer.WriteLine( "<head>" );
                        writer.WriteLine( "<title>This is a webpage</title>" );
                        writer.WriteLine( "</head>" );
                        writer.WriteLine( "<body><h1>This is the
body!</h1></body>" );
                        writer.WriteLine( "</html>" );
                    }
                    context.Response.Close();
                }
                catch ( HttpListenerException )
                {

                }                
            }
        }
    }


}


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list