protected override void ConfigureConventions(NancyConventions conventions) { base.ConfigureConventions(conventions); conventions.StaticContentsConventions.Add((ctx, root) => { string fileName; if (ctx.Request.Path == "/vendor.js") { //return compressed version of vendor.js (as vendor.js.gz) fileName = Path.GetFullPath(Path.Combine(root, "Content", "vendor.js.gz")); if (File.Exists(fileName)) { var response = new GenericFileResponse(fileName, ctx); response.Headers.Add("Content-Encoding", "gzip"); response.Headers.Add("Content-Type", "application/javascript"); return response; } } fileName = Path.GetFullPath(Path.Combine(root, "Content", (ctx.Request.Path == "/")?"index.html": ctx.Request.Path.Substring(1))); if (File.Exists(fileName)) { return new GenericFileResponse(fileName, ctx); } return null; }); }
public void Should_set_status_code_to_not_found_when_file_name_is_empty() { // Given, When var response = new GenericFileResponse(string.Empty, imageContentType); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_status_code_to_ok() { // Given, When var response = new GenericFileResponse(this.imagePath, imageContentType); // Then response.StatusCode.ShouldEqual(HttpStatusCode.OK); }
public void Handle(HttpStatusCode statusCode, NancyContext context) { // loading file instead of using RenderView because views are specific // to the service and i do not want to replciate the 404 page in each service DLL var response = new GenericFileResponse("content/404.html", "text/html"); response.StatusCode = statusCode; context.Response = response; }
public void Should_set_status_code_to_not_found_when_file_name_is_null() { // Given, When var response = new GenericFileResponse(null, this.fileContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_filename_property_to_filename() { // Given, When var response = new GenericFileResponse(this.imagePath, imageContentType); // Then response.Filename.ShouldEqual("zip.png"); }
public void Should_set_status_code_to_not_found_when_file_does_not_exist() { // Given // When var response = new GenericFileResponse("nancy", this.fileContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_contain_etag_in_response_header() { // Given, when var response = new GenericFileResponse(this.imagePath, imageContentType); // Then response.Headers["ETag"].ShouldStartWith("\""); response.Headers["ETag"].ShouldEndWith("\""); }
public void Should_set_status_code_to_not_found_when_file_name_does_not_contain_extension() { // Given var path = Path.Combine("Resources", "zip"); // When var response = new GenericFileResponse(path, imageContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_status_code_to_not_found_when_file_name_does_not_contain_extension() { // Given var fileNameWithoutExtensions = Path.GetFileNameWithoutExtension(this.filePath); // When var response = new GenericFileResponse(fileNameWithoutExtensions, this.fileContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_status_code_to_not_found_when_file_does_not_exist() { // Given var path = Path.Combine("Resources", "thatsnotit.jpg"); // When var response = new GenericFileResponse(path, imageContentType); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_status_code_to_not_found_when_file_is_above_root_path() { // Given var path = Path.Combine(this.imagePath, "..", ".."); // When var response = new GenericFileResponse(path, imageContentType); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_return_file_unchanged() { // Given var expected = File.ReadAllBytes(this.imagePath); var response = new GenericFileResponse(this.imagePath, imageContentType); // When var result = GetResponseContents(response); // Then result.ShouldEqualSequence(expected); }
public PublicModule(Authentication auth) { Get["/"] = _ => { var response = new GenericFileResponse("Content\\index.html"); response.ContentType = "text/html"; return response; }; Get["/{name*}"] = _ => { return HttpStatusCode.Forbidden; }; }
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden() { // Given var environment = new DefaultNancyEnvironment(); environment.StaticContent(safepaths:this.GetLocation()); var filename = this.GetFilePath(); var response = new GenericFileResponse(filename, "foo/bar", new NancyContext() {Environment = environment}); // When var result = response.AsAttachment(); // Then result.Headers["Content-Disposition"].ShouldContain(Path.GetFileName(filename)); result.ContentType.ShouldEqual("foo/bar"); }
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden() { // Given var assemblyPath = Path.GetDirectoryName(this.GetType().Assembly.Location); GenericFileResponse.SafePaths = new List<string> {assemblyPath}; var filename = Path.GetFileName(this.GetType().Assembly.Location); var response = new GenericFileResponse(filename, "image/png"); // When var result = response.AsAttachment(); // Then result.Headers["Content-Disposition"].ShouldContain(filename); result.ContentType.ShouldEqual("image/png"); }
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden() { // Given var assemblyPath = Path.GetDirectoryName(this.GetType().Assembly.Location); var environment = new DefaultNancyEnvironment(); environment.StaticContent(safepaths:assemblyPath); var filename = Path.GetFileName(this.GetType().Assembly.Location); var response = new GenericFileResponse(filename, "image/png", new NancyContext() {Environment = environment}); // When var result = response.AsAttachment(); // Then result.Headers["Content-Disposition"].ShouldContain(filename); result.ContentType.ShouldEqual("image/png"); }
public void Should_set_content_length_in_response_header() { // Given, when var expected = new FileInfo(imagePath).Length.ToString(); var response = new GenericFileResponse(this.imagePath, imageContentType); // Then response.Headers["Content-Length"].ShouldEqual(expected); }
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden() { var filename = Path.Combine(@"..", @"..", "Resources", "zip.png"); var response = new GenericFileResponse(filename, "image/png"); var result = response.AsAttachment(); result.Headers["Content-Disposition"].ShouldContain("zip.png"); result.ContentType.ShouldEqual("image/png"); }
public void Handle(HttpStatusCode statusCode, NancyContext context) { var response = new GenericFileResponse("views/404.html", "text/html"); response.StatusCode = statusCode; context.Response = response; }
public void Should_set_content_length_in_response_header() { // Given, when var path = Path.Combine(this.GetLocation(), this.filePath); var expected = new FileInfo(path).Length.ToString(); var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context); // Then response.Headers["Content-Length"].ShouldEqual(expected); }
public void Should_set_filename_property_to_filename() { // Given // When var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context); // Then response.Filename.ShouldEqual(Path.GetFileName(this.filePath)); }
public void Should_return_file_unchanged() { // Given var path = Path.Combine(this.GetLocation(), this.filePath); var expected = File.ReadAllBytes(path); var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context); // When var result = GetResponseContents(response); // Then result.ShouldEqualSequence(expected); }
public void Should_set_status_code_to_ok() { // Given // When var response = new GenericFileResponse(this.filePath, "text/plain", this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.OK); }
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden() { // Given var assemblyPath = Path.GetDirectoryName(this.GetType().Assembly.Location); GenericFileResponse.RootPath = Path.GetFullPath(Path.Combine(assemblyPath, @"..", @"..")); var filename = Path.Combine("Resources", "zip.png"); var response = new GenericFileResponse(filename, "image/png"); // When var result = response.AsAttachment(); // Then result.Headers["Content-Disposition"].ShouldContain("zip.png"); result.ContentType.ShouldEqual("image/png"); }