All pastes #388473 Raw Edit

Someone

public text v1 · immutable
·published 2007-03-10 02:37 UTC
rendered paste body
        HttpListenerRequest request = context.Request;
                        HttpListenerResponse response = context.Response;

                        response.SendChunked=false;

                        System.IO.Stream body = request.InputStream;
                        System.Text.Encoding encoding = request.ContentEncoding;
                        System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);

                        string requestBody = reader.ReadToEnd();
                        body.Close();
                        reader.Close();

                        string responseString="";
                        switch(request.ContentType) {
                                case "text/xml":
                                        // must be XML-RPC, so pass to the XML-RPC parser

                                        responseString=ParseXMLRPC(requestBody);
                                        response.AddHeader("Content-type","text/xml");
                                break;

                                case null:
                                        // must be REST or invalid crap, so pass to the REST parser
                                        responseString=ParseREST(request.Url.OriginalString,requestBody);
                                break;
                        }


                        byte[] buffer = System.Text.Encoding.Unicode.GetBytes(responseString);
                        System.IO.Stream output = response.OutputStream;
                        response.SendChunked=false;
                        encoding = System.Text.Encoding.Unicode;
                        response.ContentEncoding = encoding;
                        output.Write(buffer,0,buffer.Length);
                        output.Close();