Пример #1
0
        public void Process(HttpApplication application)
        {
            HttpContext context = application.Context;

            if (Utility.GetEnableMemoryOptimizationIdentifier(context) == null && this.IsUploadRequest(application))
            {
                HttpWorkerRequest workerRequest = this.GetWorkerRequest(context);
                if (workerRequest != null)
                {
                    Type knownWorkerRequestType = this.GetKnownWorkerRequestType(workerRequest);
                    if (knownWorkerRequestType != null)
                    {
                        int requestLength = (int)RequestStream.GetRequestLength(workerRequest);
                        if (requestLength > this.GetMaxRequestLength(context))
                        {
                            this.ThrowMaximumRequestLengthExceeded(application.Response);
                        }
                        UploadContext uploadContext = this.CreateUploadContext(context, requestLength);
                        RequestParser parser        = new RequestParser(this.GetBoundary(application.Request), application.Request.ContentEncoding, uploadContext);
                        parser.ProcessRequest(new RequestStream(workerRequest));
                        uploadContext.UploadedFiles = parser.UploadedFiles;
                        this.SetTextContent(knownWorkerRequestType, workerRequest, parser.TextContent);
                    }
                }
            }
        }
Пример #2
0
        private UploadContext CreateUploadContext(HttpContext context, int requestLength)
        {
            UploadContext uploadContext = new UploadContext(requestLength);

            UploadContext.SetUploadContext(context, uploadContext);
            return(uploadContext);
        }
Пример #3
0
        private void DisposeUploadContext(HttpContext context)
        {
            UploadContext uploadContext = UploadContext.GetUploadContext(context);

            if (uploadContext != null)
            {
                foreach (UploadedFile file in uploadContext.UploadedFiles)
                {
                    file.Delete();
                }
                UploadContext.RemoveUploadContext(context);
            }
        }
Пример #4
0
 public RequestParser(byte[] boundary, Encoding encoding, UploadContext uploadContext)
 {
     this._boundary           = boundary;
     this._encoding           = encoding;
     this._headerEndDelimiter = encoding.GetBytes("\r\n\r\n");
     this._uploadContext      = uploadContext;
     if (Configuration.IsDefaultChunkSize)
     {
         this.CHUNK_SIZE = Math.Max(Configuration.ChunkSize, Math.Min(Configuration.MAX_CHUNK_SIZE * 100, uploadContext.RequestLength) / 100);
     }
     else
     {
         this.CHUNK_SIZE = Configuration.ChunkSize;
     }
     this._buffer = new byte[this.CHUNK_SIZE + this.HelperBlockSize];
 }
Пример #5
0
 internal static void SetUploadContext(HttpContext context, UploadContext uploadContext)
 {
     context.Items[_contextKey] = uploadContext;
 }