dingalla
dingalla

Reputation: 1239

HttpListener running on Ubuntu/Mono returns 400 bad request

I have a problematic .Net application running on Ubuntu 12.04LTS and Mono (mono-complete-2.10.8.1) that spins up an HttpListener on localhost:8090. Anytime I send a request to the server it immediately kicks back 400-bad request.

I think this may be an Ubuntu thing because: - The exact same application processes requests just fine when running on Windows. In fact, it processes requests whether it is executing within the MSFT CLR or the Mono for Windows CLR. - The bind is successful according to other logging. - I have a logging statement immediately after getting a context, like so:

try {
  var context = httpListener.GetContext();
  Log.Debug("Request received");
  // Send to handlers, etc...
} catch (Exception ex) {
  Log.Error("HttpListener error: {0}", ex.Message);
}

Now on the Ubuntu setup, that logging statement is never reported, but I still manage to get the 400 back, so I can only assume that that HttpListener either never got the request, or generated the response before giving me a change to handle it.

If anything, can someone suggest how to troubleshoot this? I'm juvenile at best in Linux. Although iptables are set to allow all by default, I poked a hole for the port I am listening on.

Thanks

Edit: Furthermore-no exceptions are ever caught in the above snippet either.

Upvotes: 0

Views: 1098

Answers (1)

joelc
joelc

Reputation: 2761

Sorry I'm so late to the party on this, but what IP or hostname are you binding? I've found that with Mono it requires the HOST header in the HTTP header match with the hostname prefix that is aded, i.e.

HttpListener http = new HttpListener();
http.Prefixes.Add("http://hostname.com:80/");
http.Start();

It requires that whatever is in the HTTP request itself (on the wire) have Host: hostname.com present.

While using an IP address, "127.0.0.1", "localhost", "0.0.0.0", "+", and "*" seem to work on Windows, when I deploy on Mono on Ubuntu, I have to specifically add a prefix that uses a hostname or the interface's IP address. Note that when using an IP address it needs to be the one bound to the interface, not whatever public-facing external IP address it may be mapped to.

Upvotes: 1

Related Questions