public ControllerContext(Page page) { Session = new SessionWrapper(page.Session); Application = new ApplicationWrapper(page.Application); Request = new RequestWrapper(page.Request); Response = new ResponseWrapper(page.Response); }
public void ApplyTo(IResponseWrapper responseWrapper) { ResponseContext context = new ResponseContext(); context.AddHeader(statusCode); representation.UpdateContext(context); context.ApplyTo(responseWrapper); }
public ControllerContext(UserControl control) { Session = new SessionWrapper(control.Session); Application = new ApplicationWrapper(control.Application); Request = new RequestWrapper(control.Request); Response = new ResponseWrapper(control.Response); }
/// <summary> /// Writes out a status code, cache response and response (binary or text) for the /// localpath file request. /// </summary> /// <param name="localPath">The request's local path, which is a url such as /Attachments/foo.jpg</param> /// <param name="applicationPath">The application path e.g. /wiki/, if the app is running under one. /// If the app is running from the root then this will be "/".</param> /// <param name="url">The url for the request</param> /// <param name="modifiedSinceHeader">The modified since header (or null if there isn't one) - this is a date in ISO format.</param> /// <param name="responseWrapper">A wrapper for the HttpResponse object, to cater for ASP.NET being untestable.</param> public void WriteResponse(string localPath, string applicationPath, string modifiedSinceHeader, IResponseWrapper responseWrapper, HttpContext context) { _fileService.WriteResponse( localPath, applicationPath, modifiedSinceHeader, responseWrapper, context); }
public void AddToResponse(IResponseWrapper response) { if (!sendChunked) { throw new InvalidOperationException("Cannot write chunked response while sendChunked is false. Use ContentLength instead."); } response.WriteIsChunked(true); }
public void ApplyTo(IResponseWrapper response) { foreach (IHeader header in headers.Values) { header.AddToResponse(response); } IEntityBodyTransformationStrategy strategy = entityBodyTransformationStrategyFactoryMethod(entityBodyStreamAccessMethod.Invoke()); response.WriteEntityBody(strategy); }
public ControllerContext( ISessionWrapper session, IApplicationWrapper application, IRequestWrapper request, IResponseWrapper response) { Session = session; Application = application; Request = request; Response = response; }
public LambdaService(IEnvironmentWrapper env, IResponseWrapper responseWrapper, IDynamoDbContextWrapper dynamoDbContext, IAmazonApiGatewayManagementApi apiGatewayManagementApi, IAmazonIotData amazonIotData) { _env = env; _responseWrapper = responseWrapper; _dynamoDbContext = dynamoDbContext; _apiGatewayManagementApi = apiGatewayManagementApi; _amazonIotData = amazonIotData; }
/// <summary> /// Writes out a status code, cache response and response (binary or text) for the /// localpath file request. /// </summary> /// <param name="localPath">The request's local path, which is a url such as /Attachments/foo.jpg</param> /// <param name="applicationPath">The application path e.g. /wiki/, if the app is running under one. /// If the app is running from the root then this will be "/".</param> /// <param name="url">The url for the request</param> /// <param name="modifiedSinceHeader">The modified since header (or null if there isn't one) - this is a date in ISO format.</param> /// <param name="responseWrapper">A wrapper for the HttpResponse object, to cater for ASP.NET being untestable.</param> public void WriteResponse(string localPath, string applicationPath, string modifiedSinceHeader, IResponseWrapper responseWrapper) { // Get the mimetype from the IIS settings (configurable in the mimetypes.xml file in the site) // n.b. debug mode skips using IIS to avoid complications with testing. string fileExtension = Path.GetExtension(localPath); string mimeType = MimeTypes.GetMimeType(fileExtension); try { string fullPath = TranslateUrlPathToFilePath(localPath, applicationPath); if (File.Exists(fullPath)) { responseWrapper.AddStatusCodeForCache(fullPath, modifiedSinceHeader); if (responseWrapper.StatusCode != 304) { // Serve the file in the body byte[] buffer = File.ReadAllBytes(fullPath); responseWrapper.ContentType = mimeType; responseWrapper.BinaryWrite(buffer); } responseWrapper.End(); } else { // 404 Log.Warn("The url {0} (translated to {1}) does not exist on the server.", localPath, fullPath); // Throw so the web.config catches it throw new HttpException(404, string.Format("{0} does not exist on the server.", localPath)); } } catch (IOException ex) { // 500 Log.Error(ex, "There was a problem opening the file {0}.", localPath); // Throw so the web.config catches it throw new HttpException(500, "There was a problem opening the file (see the error logs)"); } }
public void AddToResponse(IResponseWrapper response) { response.WriteETag(value); }
public static IResponseWrapper <TResponse> WrapErrors <TResponse>(this IResponseWrapper response) { return(Response.GenerateTypedErrorResponse <IResponseWrapper <TResponse> >(response.Failures)); }
/// <summary> /// Writes out a status code, cache response and response (binary or text) for the /// localpath file request. /// </summary> /// <param name="localPath">The request's local path, which is a url such as /Attachments/foo.jpg</param> /// <param name="applicationPath">The application path e.g. /wiki/, if the app is running under one. /// If the app is running from the root then this will be "/".</param> /// <param name="url">The url for the request</param> /// <param name="modifiedSinceHeader">The modified since header (or null if there isn't one) - this is a date in ISO format.</param> /// <param name="responseWrapper">A wrapper for the HttpResponse object, to cater for ASP.NET being untestable.</param> public void WriteResponse(string localPath, string applicationPath, string modifiedSinceHeader, IResponseWrapper responseWrapper, HttpContext context) { _fileService.WriteResponse(localPath, applicationPath, modifiedSinceHeader, responseWrapper, context); }
public void AddToResponse(IResponseWrapper response) { response.WriteContentType(value); }
public static void Throw(this IResponseWrapper response) { throw new Exception(); }
public void AddToResponse(IResponseWrapper response) { response.WriteLastModified(value.ToString("R")); }
public void WriteResponse(string localPath, string applicationPath, string modifiedSinceHeader, IResponseWrapper responseWrapper, HttpContext context) { if (CustomException != null) { throw CustomException; } }
public void AddToResponse(IResponseWrapper response) { response.WriteIsChunked(false); response.WriteContentLength(value); }
public void WriteResponse(string localPath, string applicationPath, string modifiedSinceHeader, IResponseWrapper responseWrapper, HttpContext context) { if (CustomException != null) throw CustomException; }
public void WriteResponse(string localPath, string applicationPath, string modifiedSinceHeader, IResponseWrapper responseWrapper, HttpContext context) { try { int bufferSize; if (!Int32.TryParse(context.Request["bufferSize"], out bufferSize)) { bufferSize = 100 * 1024; } CloudBlobContainer container = GetCloudBlobContainer(); string blobPath = CleanPath(localPath.Replace(_applicationSettings.AttachmentsRoutePath, String.Empty)); // Add leading slash if necessary if (blobPath.Contains("/") && !blobPath.StartsWith("/")) { blobPath = blobPath.Insert(0, "/"); } CloudBlockBlob blob = container.GetBlockBlobReference(blobPath); if (blob.Exists()) { Exception downloadException = null; bool isDataComplete = false; var dataQueue = new BlockingCollection<Tuple<int, byte[]>>(); var bufferQueue = new BlockingCollection<byte[]>(); ThreadPool.QueueUserWorkItem(new WaitCallback(o => { try { Stream blobStream = blob.OpenRead(); int blockLength = 0; do { byte[] blockBuffer = null; if (bufferQueue.Count > 0) { blockBuffer = bufferQueue.Take(); } else { blockBuffer = new byte[bufferSize]; } blockLength = blobStream.Read(blockBuffer, 0, blockBuffer.Length); if (blockLength > 0) { dataQueue.Add(new Tuple<int, byte[]>(blockLength, blockBuffer)); } } while (blockLength > 0); } catch (StorageException exception) { downloadException = exception; } finally { isDataComplete = true; } })); blob.FetchAttributes(); context.Response.ContentType = blob.Properties.ContentType; context.Response.Buffer = false; context.Response.AddHeader("content-disposition", "attachment; filename=" + Path.GetFileName(blobPath)); while (context.Response.IsClientConnected && (!isDataComplete || dataQueue.Count > 0)) { if (downloadException != null) { throw new FileException("The internal blob download failed.", downloadException); } var data = dataQueue.Take(); context.Response.OutputStream.Write(data.Item2, 0, data.Item1); context.Response.Flush(); // Put the processed buffer back into the queue so as to minimize memory consumption bufferQueue.Add(data.Item2); } } else { // 404 Log.Warn("The url {0} (translated to {1}) does not exist on the server.", localPath, blobPath); // Throw so the web.config catches it throw new HttpException(404, string.Format("{0} does not exist on the server.", localPath)); } } catch (FileException ex) { // 500 Log.Error(ex, "There was a problem opening the file {0}.", localPath); // Throw so the web.config catches it throw new HttpException(500, "There was a problem opening the file (see the error logs)"); } }
public void WriteResponse(string localPath, string applicationPath, string modifiedSinceHeader, IResponseWrapper responseWrapper, HttpContext context) { try { int bufferSize; if (!Int32.TryParse(context.Request["bufferSize"], out bufferSize)) { bufferSize = 100 * 1024; } CloudBlobContainer container = GetCloudBlobContainer(); string blobPath = CleanPath(localPath.Replace(_applicationSettings.AttachmentsRoutePath, String.Empty)); // Add leading slash if necessary if (blobPath.Contains("/") && !blobPath.StartsWith("/")) { blobPath = blobPath.Insert(0, "/"); } CloudBlockBlob blob = container.GetBlockBlobReference(blobPath); if (blob.Exists()) { Exception downloadException = null; bool isDataComplete = false; var dataQueue = new BlockingCollection <Tuple <int, byte[]> >(); var bufferQueue = new BlockingCollection <byte[]>(); ThreadPool.QueueUserWorkItem(new WaitCallback(o => { try { Stream blobStream = blob.OpenRead(); int blockLength = 0; do { byte[] blockBuffer = null; if (bufferQueue.Count > 0) { blockBuffer = bufferQueue.Take(); } else { blockBuffer = new byte[bufferSize]; } blockLength = blobStream.Read(blockBuffer, 0, blockBuffer.Length); if (blockLength > 0) { dataQueue.Add(new Tuple <int, byte[]>(blockLength, blockBuffer)); } } while (blockLength > 0); } catch (StorageException exception) { downloadException = exception; } finally { isDataComplete = true; } })); blob.FetchAttributes(); context.Response.ContentType = blob.Properties.ContentType; context.Response.Buffer = false; context.Response.AddHeader("content-disposition", "attachment; filename=" + Path.GetFileName(blobPath)); while (context.Response.IsClientConnected && (!isDataComplete || dataQueue.Count > 0)) { if (downloadException != null) { throw new FileException("The internal blob download failed.", downloadException); } var data = dataQueue.Take(); context.Response.OutputStream.Write(data.Item2, 0, data.Item1); context.Response.Flush(); // Put the processed buffer back into the queue so as to minimize memory consumption bufferQueue.Add(data.Item2); } } else { // 404 Log.Warn("The url {0} (translated to {1}) does not exist on the server.", localPath, blobPath); // Throw so the web.config catches it throw new HttpException(404, string.Format("{0} does not exist on the server.", localPath)); } } catch (FileException ex) { // 500 Log.Error(ex, "There was a problem opening the file {0}.", localPath); // Throw so the web.config catches it throw new HttpException(500, "There was a problem opening the file (see the error logs)"); } }
public LambdaService(IEnvironmentWrapper env, IResponseWrapper responseWrapper) { _env = env; _responseWrapper = responseWrapper; }
public void AddToResponse(IResponseWrapper response) { response.WriteStatusCode(code); response.WriteStatusDescription(description); }
public bool chooseResponse(IResponseWrapper response) => false;