Beispiel #1
0
        private void Respond(HttpListenerContext context, byte[] buffer, int returnCode, DateTime reqStartTime, string contentType = "text/plain")
        {
            int len = buffer != null ? buffer.Length : 0;

            try
            {
                context.Response.AddHeader("Cache-Control", "no-cache");
                context.Response.AddHeader("Content-Type", contentType);
                context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                context.Response.ContentEncoding = serverCharSet;
                context.Response.ContentLength64 = len;
                context.Response.StatusCode      = returnCode;
                context.Response.OutputStream.Write(buffer, 0, len);
                context.Response.ContentType = contentType;

                ServerLog.LogHttpRequest(context.Request, returnCode, len, string.Empty, (int)((startTime - DateTime.Now).TotalMilliseconds));
                System.Threading.Interlocked.Add(ref totalBytesOut, buffer.Length);
                System.Threading.Interlocked.Increment(ref total200s);
            }
            catch (HttpListenerException hle)
            {
                ServerLog.LogException(hle, "Exception while returning data to http client");
            }
        }