/// <summary> /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /// />interface. /// </summary> /// <remarks> ebrown, 2/10/2011. </remarks> /// <exception cref="ObjectDisposedException"> Thrown when a supplied object has been disposed. </exception> /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception> /// <param name="context"> An <see cref="T:System.Web.HttpContext" /> object that provides references to the intrinsic server objects /// (for example, Request, Response, Session, and Server) used to service HTTP requests. </param> public override void ProcessRequest(HttpContextBase context) { if (_disposed) { throw new ObjectDisposedException("this"); } stopwatch.Start(); //TODO: 5-1-09 -- Response.Redirect doesn't make any sense... maybe we should just give them an 'unauthorized' empty file thing if (null == context) { throw new ArgumentNullException("context"); } this._context = context; //assign to local fields for micro-perf since these are virtuals this._request = context.Request; this._response = context.Response; try { var method = this._request.HttpMethod; //we only accept GET or HEAD - don't log these if ((HttpMethodNames.Get.ToEnumValueString() != method) && (HttpMethodNames.Header.ToEnumValueString() != method)) { this._response.StatusCode = (int)HttpStatusCode.NotImplemented; this._response.Redirect(_configuration.UnauthorizedErrorRedirectUrl, false); return; } _statusLogger.Log(context, StreamWriteStatus.ApplicationRestarted); //now pass the HttpRequestBase to our class responsible for examining specific state and loading the Stream using (StreamLoaderResult fileDetails = _streamLoader.ParseRequest(this._request)) { if (fileDetails.Status != StreamLoadStatus.Success) { RedirectOnFailedStatus(fileDetails); return; } IEnumerable <RangeRequest> rangeRequests; if (!HeadersValidate(fileDetails, out rangeRequests)) { return; } HttpResponseType responseStreamType = method == HttpMethodNames.Header.ToEnumValueString() ? HttpResponseType.HeadOnly : HttpResponseType.Complete; //we've passed our credential checking and we're ready to send out our response StreamWriteStatus streamWriteStatus = new ResponseStreamWriter(this._response, this._configuration.FileTransferBufferSizeInKBytes) .StreamFile(responseStreamType, fileDetails, rangeRequests, this._request.RetrieveHeader(HttpHeaderFields.IfRange), true); HandleStreamWriteStatus(streamWriteStatus); } } catch (HttpException hex) { //remote host closed the connection if (HttpExceptionErrorCodes.ConnectionAborted == hex.ErrorCode) { //log.Warn(String.Format("Remote Host Closed Transfer - Identity [{0}] - FileId [{1}] - User Id [{2}] / Name [{3}] / Email [{4}]{5}{5}{6}", WindowsIdentity.GetCurrent().Name, FileId, context.OnyxUser().Identity.OCPUser.Individual.OnyxId, context.OnyxUser().Identity.OCPUser.Individual.UserName, context.OnyxUser().Identity.OCPUser.Individual.UserEmailAddress, Environment.NewLine, this._request.ToLogString()), ex); } } //eat it -- nothing we can do catch (ThreadAbortException) { } //log.Error(String.Format("Unexpected Download Exception Occurred - Identity [{0}] - FileId [{1}] - User Id [{2}] / Name [{3}] / Email [{4}]{5}{5}{6}", WindowsIdentity.GetCurrent().Name, FileId, context.OnyxUser().Identity.OCPUser.Individual.OnyxId, context.OnyxUser().Identity.OCPUser.Individual.UserName, context.OnyxUser().Identity.OCPUser.Individual.UserEmailAddress, Environment.NewLine, this._request.ToLogString()), ex); //SafeInternalServerError(context); }
/// <summary> /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /// />interface. /// </summary> /// <remarks> ebrown, 2/10/2011. </remarks> /// <exception cref="ObjectDisposedException"> Thrown when a supplied object has been disposed. </exception> /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception> /// <param name="context"> An <see cref="T:System.Web.HttpContext" /> object that provides references to the intrinsic server objects /// (for example, Request, Response, Session, and Server) used to service HTTP requests. </param> public override void ProcessRequest(HttpContextBase context) { if (_disposed) { throw new ObjectDisposedException("this"); } stopwatch.Start(); //TODO: 5-1-09 -- Response.Redirect doesn't make any sense... maybe we should just give them an 'unauthorized' empty file thing if (null == context) { throw new ArgumentNullException("context"); } this._context = context; //assign to local fields for micro-perf since these are virtuals this._request = context.Request; this._response = context.Response; try { var method = this._request.HttpMethod; //we only accept GET or HEAD - don't log these if ((HttpMethodNames.Get.ToEnumValueString() != method) && (HttpMethodNames.Header.ToEnumValueString() != method)) { this._response.StatusCode = (int)HttpStatusCode.NotImplemented; this._response.Redirect(_configuration.UnauthorizedErrorRedirectUrl, false); return; } _statusLogger.Log(context, StreamWriteStatus.ApplicationRestarted); //now pass the HttpRequestBase to our class responsible for examining specific state and loading the Stream using (StreamLoaderResult fileDetails = _streamLoader.ParseRequest(this._request)) { if (fileDetails.Status != StreamLoadStatus.Success) { RedirectOnFailedStatus(fileDetails); return; } IEnumerable<RangeRequest> rangeRequests; if (!HeadersValidate(fileDetails, out rangeRequests)) { return; } HttpResponseType responseStreamType = method == HttpMethodNames.Header.ToEnumValueString() ? HttpResponseType.HeadOnly : HttpResponseType.Complete; //we've passed our credential checking and we're ready to send out our response StreamWriteStatus streamWriteStatus = new ResponseStreamWriter(this._response, this._configuration.FileTransferBufferSizeInKBytes) .StreamFile(responseStreamType, fileDetails, rangeRequests, this._request.RetrieveHeader(HttpHeaderFields.IfRange), true); HandleStreamWriteStatus(streamWriteStatus); } } catch (HttpException hex) { //remote host closed the connection if (HttpExceptionErrorCodes.ConnectionAborted == hex.ErrorCode) { //log.Warn(String.Format("Remote Host Closed Transfer - Identity [{0}] - FileId [{1}] - User Id [{2}] / Name [{3}] / Email [{4}]{5}{5}{6}", WindowsIdentity.GetCurrent().Name, FileId, context.OnyxUser().Identity.OCPUser.Individual.OnyxId, context.OnyxUser().Identity.OCPUser.Individual.UserName, context.OnyxUser().Identity.OCPUser.Individual.UserEmailAddress, Environment.NewLine, this._request.ToLogString()), ex); } } //eat it -- nothing we can do catch (ThreadAbortException) { } //log.Error(String.Format("Unexpected Download Exception Occurred - Identity [{0}] - FileId [{1}] - User Id [{2}] / Name [{3}] / Email [{4}]{5}{5}{6}", WindowsIdentity.GetCurrent().Name, FileId, context.OnyxUser().Identity.OCPUser.Individual.OnyxId, context.OnyxUser().Identity.OCPUser.Individual.UserName, context.OnyxUser().Identity.OCPUser.Individual.UserEmailAddress, Environment.NewLine, this._request.ToLogString()), ex); //SafeInternalServerError(context); }