From eb231cdcfc1b10448316e5601628a503a2f78e00 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Latour Date: Sun, 30 Dec 2012 08:53:44 -0800 Subject: [PATCH] Fixes --- CGDWebServer/GCDWebServerPrivate.h | 3 ++- CGDWebServer/GCDWebServerResponse.h | 4 ++-- CGDWebServer/GCDWebServerResponse.m | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CGDWebServer/GCDWebServerPrivate.h b/CGDWebServer/GCDWebServerPrivate.h index 60a6641..926157d 100644 --- a/CGDWebServer/GCDWebServerPrivate.h +++ b/CGDWebServer/GCDWebServerPrivate.h @@ -29,7 +29,8 @@ #ifdef __LOGGING_HEADER__ -#import __LOGGING_HEADER__ +// Define __GCDWEBSERVER_LOGGING_HEADER__ as a preprocessor constant to redirect GCDWebServer logging to your own system +#import __GCDWEBSERVER_LOGGING_HEADER__ #else diff --git a/CGDWebServer/GCDWebServerResponse.h b/CGDWebServer/GCDWebServerResponse.h index 7536948..8df9a3a 100644 --- a/CGDWebServer/GCDWebServerResponse.h +++ b/CGDWebServer/GCDWebServerResponse.h @@ -72,10 +72,10 @@ @interface GCDWebServerDataResponse (Extensions) + (GCDWebServerDataResponse*) responseWithText:(NSString*)text; + (GCDWebServerDataResponse*) responseWithHTML:(NSString*)html; -+ (GCDWebServerDataResponse*) responseWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables; // Simple template system that replaces all occurences of "%variable%" with corresponding value (encodes using UTF-8) ++ (GCDWebServerDataResponse*) responseWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables; - (id) initWithText:(NSString*)text; // Encodes using UTF-8 - (id) initWithHTML:(NSString*)html; // Encodes using UTF-8 -- (id) initWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables; +- (id) initWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables; // Simple template system that replaces all occurences of "%variable%" with corresponding value (encodes using UTF-8) @end @interface GCDWebServerFileResponse : GCDWebServerResponse { diff --git a/CGDWebServer/GCDWebServerResponse.m b/CGDWebServer/GCDWebServerResponse.m index 4fde312..2860a73 100644 --- a/CGDWebServer/GCDWebServerResponse.m +++ b/CGDWebServer/GCDWebServerResponse.m @@ -245,11 +245,12 @@ if ((self = [super initWithContentType:type contentLength:info.st_size])) { _path = [path copy]; - if (attachment) { - NSData* data = [[path lastPathComponent] dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES]; // ISO 8859-1 - NSString* fileName = data ? [[[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding] autorelease] : nil; + if (attachment) { // TODO: Use http://tools.ietf.org/html/rfc5987 to encode file names with special characters instead of using lossy conversion to ISO 8859-1 + NSData* data = [[path lastPathComponent] dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES]; + NSString* fileName = data ? [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding] : nil; if (fileName) { - [self setValue:[NSString stringWithFormat:@"attachment; filename=\"%@\"", fileName] forAdditionalHeader:@"Content-Disposition"]; // TODO: Use http://tools.ietf.org/html/rfc5987 + [self setValue:[NSString stringWithFormat:@"attachment; filename=\"%@\"", fileName] forAdditionalHeader:@"Content-Disposition"]; + [fileName release]; } else { DNOT_REACHED(); }