Example #1
0
        public static RequestInformation Create(HttpRequest request)
        {
            var info = new RequestInformation();
            info.Method = request.HttpMethod;
            info.Url = request.RawUrl;
            info.Headers = request.Headers;

            var cookies = new NameValueCollection();
            CookieCollection cookieCollection = RequestHelper.GetRequestCookies(request);
            foreach (Cookie cookie in cookieCollection)
            {
                cookies.Add(cookie.Name, cookie.Value);
            }
            info.Cookies = cookies;

            Stream stream = request.GetBufferedInputStream();
            using (var reader = new StreamReader(stream))
            {
                string body = reader.ReadToEnd();
                info.BodyContent = body;
                info.BodyLength = body.Length;
            }

            info.SecureConnection = request.IsSecureConnection;

            var cs = request.ClientCertificate;
            info.ClientCertificatePresent = cs.IsPresent;
            if (cs.IsPresent)
            {
                info.ClientCertificate = request.ClientCertificate;
            }

            return info;
        }
Example #2
0
        public static void RegisterHandler(HttpRequest request, String path)
        {
            Guid id = BuildGuid(request);
            if (id == Guid.Empty)
                return; // can't report progress without id; exit.

            if (_Requests.ContainsKey(id))
                return; // a file upload operation with the Guid value already exists; exit.

            _Requests.Add(new KeyValuePair<Guid, int>(id, 0));

            //using (Stream stream = request.GetBufferlessInputStream())
            using (Stream stream = request.GetBufferedInputStream())
            {
                long size;
                if (!long.TryParse(request.Headers["Content-Length"], out size))
                    return;
                FileHandler handler = new FileHandler(path, id);
                handler.SaveFile(size, stream, i => _Requests[id] = i);
            }
        }
Example #3
0
 public override Stream GetBufferedInputStream()
 {
     return(_httpRequest.GetBufferedInputStream());
 }
Example #4
0
 public override Stream GetBufferedInputStream()
 {
     return(w.GetBufferedInputStream());
 }
        private IAsyncResult OnEnter(Object sender, EventArgs e, AsyncCallback cb, Object state)
        {
            Debug.Assert(_inputStream == null);
            _app = (HttpApplication)sender;
            HttpContext           context          = _app.Context;
            HttpRequest           request          = context.Request;
            HttpWorkerRequest     wr               = context.WorkerRequest;
            HttpAsyncResult       httpAsyncResult  = new HttpAsyncResult(cb, state);
            AsyncPreloadModeFlags asyncPreloadMode = context.AsyncPreloadMode;
            int  contentLength;
            bool isForm          = false;
            bool isFormMultiPart = false;

            if (asyncPreloadMode == AsyncPreloadModeFlags.None ||
                request.ReadEntityBodyMode != ReadEntityBodyMode.None ||
                wr == null ||
                !wr.SupportsAsyncRead ||
                !wr.HasEntityBody() ||
                wr.IsEntireEntityBodyIsPreloaded() ||
                context.Handler == null ||
                context.Handler is TransferRequestHandler ||
                context.Handler is DefaultHttpHandler ||
                (contentLength = request.ContentLength) > RuntimeConfig.GetConfig(context).HttpRuntime.MaxRequestLengthBytes ||
                ((isForm = StringUtil.StringStartsWithIgnoreCase(request.ContentType, "application/x-www-form-urlencoded")) &&
                 (asyncPreloadMode & AsyncPreloadModeFlags.Form) != AsyncPreloadModeFlags.Form) ||
                ((isFormMultiPart = StringUtil.StringStartsWithIgnoreCase(request.ContentType, "multipart/form-data")) &&
                 (asyncPreloadMode & AsyncPreloadModeFlags.FormMultiPart) != AsyncPreloadModeFlags.FormMultiPart) ||
                !isForm && !isFormMultiPart && (asyncPreloadMode & AsyncPreloadModeFlags.NonForm) != AsyncPreloadModeFlags.NonForm
                )
            {
                Debug.Trace("AsyncPreload", " *** AsyncPreload skipped *** ");
                httpAsyncResult.Complete(true, null, null);
                return(httpAsyncResult);
            }

            Debug.Trace("AsyncPreload", " *** AsyncPreload started *** ");
            try {
                if (_callback == null)
                {
                    _callback = new AsyncCallback(OnAsyncCompletion);
                }
                _inputStream = request.GetBufferedInputStream();
                byte[] buffer    = _app.EntityBuffer;
                int    bytesRead = 0;
                // loop to prevent recursive calls and potential stack overflow if/when it completes synchronously
                do
                {
                    IAsyncResult readAsyncResult = _inputStream.BeginRead(buffer, 0, buffer.Length, _callback, httpAsyncResult);
                    if (!readAsyncResult.CompletedSynchronously)
                    {
                        return(httpAsyncResult);
                    }
                    bytesRead = _inputStream.EndRead(readAsyncResult);
                } while (bytesRead != 0);
            }
            catch {
                Reset();
                throw;
            }
            httpAsyncResult.Complete(true, null, null);
            return(httpAsyncResult);
        }