0
votes

I've wrote a XMPP Server on C#, based on another (OPEN SOURCE) project. That project had a lot of handlers that help me work the XMPP Protocol, but did not have a BOSH Connection manager - so i wrote one.

The idea was to use the standard clients (via TCP Connection) and a Converse.JS on a browser.

The standard clients are working fine, but the Converse.JS had issues. My problem is not handling the bosh requests themselves, but handling the initial OPTIONS request that Converse.JS sends (with an empty body).

According to their forum (where i posted this Issue) the

The OPTIONS request is a so-called preflight request to determine whether the domain being queried supports CORS. IIRC this only happens when making cross-domain requests. If you intend to support CORS, then you'll need to respond appropriately to OPTIONS requests.

And studing that a little, i came up with this solution (that is not working, since Converse.JS keeps sending the OPTIONS request over and over, until it fails to connect):

internal static void SendCORSResponse(HttpListenerContext ctx)
{
    ctx.Response.StatusCode = (int)HttpStatusCode.OK; //200
    ctx.Response.AddHeader("Access-Control-Allow-Origin", "*");
    ctx.Response.AddHeader("Access-Control-Allow-Methods", "GET,POST,HEAD,PUT,DELETE,OPTIONS");
    ctx.Response.AddHeader("Access-Control-Allow-Headers", "content-type");
    ctx.Response.AddHeader("Access-Control-Max-Age", "86400");
    ctx.Response.AddHeader("Accept-Encoding", "gzip");
    ctx.Response.AddHeader("Accept-Charset", "utf-8");
    ctx.Response.AddHeader("Accept-Language", "*");
    ctx.Response.AddHeader("Accept", "*");
    ctx.Response.Close(); //sends the response
}

That function is called on the class handling the connection when the header contains the OPTIONS tag. What do i do, or what did i do wrong?

1

1 Answers

0
votes

Just for future references - the problem was not in this function; the function i used to detect if the request was null that was wrong and returned true every time.

Problem solved.