Exemplo n.º 1
1
        public HttpRequestEventArgs(HttpContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            Context = context;
        }
Exemplo n.º 2
1
        public HttpExceptionEventArgs(HttpContext context, Exception exception)
            : base(context)
        {
            if (exception == null)
                throw new ArgumentNullException("exception");

            Exception = exception;
        }
Exemplo n.º 3
0
        private void ProcessODataRequest(HttpContext context)
        {
            string[] parts = context.Request.RawUrl.Split(new[] { '?' }, 2);

            string path = parts[0];
            string filter = parts.Length == 2 ? parts[1] : null;

            // Remove the /odata part.

            path = path.Substring(6).TrimStart('/');

            ODataRequest request;

            using (var session = _sessionFactroy.OpenSession())
            using (var transaction = session.BeginTransaction())
            {
                session.FlushMode = FlushMode.Never;

                request = _service.Query(session, path, filter);

                session.Flush();
                transaction.Commit();
            }

            using (var writer = new StreamWriter(context.Response.OutputStream))
            {
                writer.Write(request.Response);
            }

            context.Response.ContentType = request.ContentType;
            context.Response.Headers["DataServiceVersion"] = request.DataServiceVersion;
        }
Exemplo n.º 4
0
        private void ProcessStaticRequest(HttpContext context)
        {
            string page = context.Request.Path.TrimStart('/');

            if (ProcessPage(page, context))
                return;

            if (ProcessPage(page.TrimEnd('/') + "/index.html", context))
                return;

            context.Response.Status = "404 Not Found";
        }
Exemplo n.º 5
0
        internal HttpResponse(HttpContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            _context = context;

            CacheControl = "private";
            CharSet = "utf-8";
            ContentType = "text/html";
            ExpiresAbsolute = DateTime.MinValue;
            HeadersEncoding = Encoding.UTF8;
            Headers = new NameValueCollection();
            OutputStream = new HttpOutputStream(new MemoryStream());
            StatusCode = 200;
            StatusDescription = "OK";
            Cookies = new HttpCookieCollection();
        }
Exemplo n.º 6
0
        private void Reset()
        {
            _state = ClientState.ReadingProlog;
            _context = null;

            if (_parser != null)
            {
                _parser.Dispose();
                _parser = null;
            }

            if (_writeStream != null)
            {
                _writeStream.Dispose();
                _writeStream = null;
            }

            if (InputStream != null)
            {
                InputStream.Dispose();
                InputStream = null;
            }

            ReadBuffer.Reset();

            Method = null;
            Protocol = null;
            Request = null;
            Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            PostParameters = new NameValueCollection();

            if (MultiPartItems != null)
            {
                foreach (var item in MultiPartItems)
                {
                    if (item.Stream != null)
                        item.Stream.Dispose();
                }

                MultiPartItems = null;
            }
        }
Exemplo n.º 7
0
        internal bool RaiseUnhandledException(HttpContext context, Exception exception)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            var e = new HttpExceptionEventArgs(context, exception);

            OnUnhandledException(e);

            return e.Handled;
        }
Exemplo n.º 8
0
        internal void RaiseRequest(HttpContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            OnRequestReceived(new HttpRequestEventArgs(context));
        }
Exemplo n.º 9
0
        private void ProcessException(Exception exception)
        {
            if (_disposed)
                return;

            _errored = true;

            // If there is no request available, the error didn't occur as part
            // of a request (e.g. the client closed the connection). Just close
            // the channel in that case.

            if (Request == null)
            {
                Dispose();
                return;
            }

            try
            {
                if (_context == null)
                    _context = new HttpContext(this);

                _context.Response.Status = "500 Internal Server Error";

                bool handled;

                try
                {
                    handled = Server.RaiseUnhandledException(_context, exception);
                }
                catch
                {
                    handled = false;
                }

                if (!handled && _context.Response.OutputStream.CanWrite)
                {
                    string resourceName = GetType().Namespace + ".Resources.InternalServerError.html";

                    using (var stream = GetType().Assembly.GetManifestResourceStream(resourceName))
                    {
                        byte[] buffer = new byte[4096];
                        int read;

                        while ((read = stream.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            _context.Response.OutputStream.Write(buffer, 0, read);
                        }
                    }
                }

                WriteResponseHeaders();
            }
            catch (Exception ex)
            {
                Log.Info("Failed to process internal server error response", ex);

                Dispose();
            }
        }
Exemplo n.º 10
0
        public void ExecuteRequest()
        {
            _context = new HttpContext(this);

            Log.Debug(String.Format("Accepted request '{0}'", _context.Request.RawUrl));

            Server.RaiseRequest(_context);

            WriteResponseHeaders();
        }
Exemplo n.º 11
0
        private bool ProcessPage(string page, HttpContext context)
        {
            string resource = typeof(Program).Namespace + ".Site." + page.TrimStart('/').Replace('/', '.');

            using (var stream = typeof(Program).Assembly.GetManifestResourceStream(resource))
            {
                if (stream != null)
                {
                    stream.CopyTo(context.Response.OutputStream);
                    return true;
                }
            }

            return false;
        }