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); } } } }
private UploadContext CreateUploadContext(HttpContext context, int requestLength) { UploadContext uploadContext = new UploadContext(requestLength); UploadContext.SetUploadContext(context, uploadContext); return(uploadContext); }
private void DisposeUploadContext(HttpContext context) { UploadContext uploadContext = UploadContext.GetUploadContext(context); if (uploadContext != null) { foreach (UploadedFile file in uploadContext.UploadedFiles) { file.Delete(); } UploadContext.RemoveUploadContext(context); } }
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]; }
internal static void SetUploadContext(HttpContext context, UploadContext uploadContext) { context.Items[_contextKey] = uploadContext; }