From 6019ee59c40e066d93d2ba5c25ddea3fd92c4813 Mon Sep 17 00:00:00 2001 From: Oliver Eikemeier Date: Sun, 27 Apr 2014 19:40:13 +0200 Subject: [PATCH 1/2] Use the correct MIME type for content served by CocoaHTTPServer --- Classes/PackageDataResponse.h | 33 +++++++++++++++++++ Classes/PackageDataResponse.m | 40 +++++++++++++++++++++++ Classes/PackageResourceConnection.m | 15 ++++++--- Classes/PackageResourceResponse.m | 11 +++++++ Classes/RDPackage.mm | 7 ++++ Classes/RDPackageResource.h | 2 ++ SDKLauncher-iOS.xcodeproj/project.pbxproj | 6 ++++ 7 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 Classes/PackageDataResponse.h create mode 100644 Classes/PackageDataResponse.m diff --git a/Classes/PackageDataResponse.h b/Classes/PackageDataResponse.h new file mode 100644 index 0000000..60ac495 --- /dev/null +++ b/Classes/PackageDataResponse.h @@ -0,0 +1,33 @@ +// +// PackageDataResponse.h +// SDKLauncher-iOS +// +// Created by Oliver Eikemeier on 04.04.14. +// Copyright (c) 2014 txtr GmbH. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "HTTPDataResponse.h" + +@interface PackageDataResponse : HTTPDataResponse + +@property (nonatomic, copy) NSString *contentType; + +@end diff --git a/Classes/PackageDataResponse.m b/Classes/PackageDataResponse.m new file mode 100644 index 0000000..49d340b --- /dev/null +++ b/Classes/PackageDataResponse.m @@ -0,0 +1,40 @@ +// +// PackageDataResponse.m +// SDKLauncher-iOS +// +// Created by Oliver Eikemeier on 04.04.14. +// Copyright (c) 2014 txtr GmbH. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#import "PackageDataResponse.h" + +@implementation PackageDataResponse + +- (NSDictionary *)httpHeaders { + if (self.contentType) { + return @{@"Content-Type": self.contentType}; + } + else { + return @{}; + } +} + +@end diff --git a/Classes/PackageResourceConnection.m b/Classes/PackageResourceConnection.m index 9da9e57..3f9899a 100644 --- a/Classes/PackageResourceConnection.m +++ b/Classes/PackageResourceConnection.m @@ -7,7 +7,7 @@ // #import "PackageResourceConnection.h" -#import "HTTPDataResponse.h" +#import "PackageDataResponse.h" #import "PackageResourceResponse.h" #import "PackageResourceServer.h" #import "RDPackage.h" @@ -34,6 +34,8 @@ @implementation PackageResourceConnection path = [path substringFromIndex:1]; } + NSObject *response = nil; + // Synchronize using a process-level lock to guard against multiple threads accessing a // resource byte stream, which may lead to instability. @@ -51,15 +53,20 @@ @implementation PackageResourceConnection NSData *data = resource.data; if (data != nil) { - return [[HTTPDataResponse alloc] initWithData:data]; + PackageDataResponse *dataResponse = [[PackageDataResponse alloc] initWithData:data]; + if (resource.mimeType) { + dataResponse.contentType = resource.mimeType; + } + response = dataResponse; } } else { - return [[PackageResourceResponse alloc] initWithResource:resource]; + PackageResourceResponse *resourceResponse = [[PackageResourceResponse alloc] initWithResource:resource]; + response = resourceResponse; } } - return nil; + return response; } diff --git a/Classes/PackageResourceResponse.m b/Classes/PackageResourceResponse.m index 4cc3351..bd351b2 100644 --- a/Classes/PackageResourceResponse.m +++ b/Classes/PackageResourceResponse.m @@ -66,4 +66,15 @@ - (void)setOffset:(UInt64)offset { } +- (NSDictionary *)httpHeaders { + NSString *contentType = self->m_resource.mimeType; + if (contentType) { + return @{@"Content-Type": contentType}; + } + else { + return @{}; + } +} + + @end diff --git a/Classes/RDPackage.mm b/Classes/RDPackage.mm index 1087000..781ad45 100644 --- a/Classes/RDPackage.mm +++ b/Classes/RDPackage.mm @@ -270,6 +270,13 @@ - (RDPackageResource *)resourceAtRelativePath:(NSString *)relativePath { if (resource != nil) { m_byteStreamVector.push_back(std::move(byteStream)); + + ePub3::ConstManifestItemPtr item = m_package->ManifestItemAtRelativePath(s); + + if (item) { + const ePub3::ManifestItem::MimeType &mediaType = item->MediaType(); + resource.mimeType = [NSString stringWithUTF8String:mediaType.c_str()]; + } } return resource; diff --git a/Classes/RDPackageResource.h b/Classes/RDPackageResource.h index 8a383be..8161ec8 100644 --- a/Classes/RDPackageResource.h +++ b/Classes/RDPackageResource.h @@ -33,6 +33,8 @@ // The relative path associated with this resource. @property (nonatomic, readonly) NSString *relativePath; +@property (nonatomic, copy) NSString *mimeType; + - (id) initWithDelegate:(id )delegate byteStream:(void *)byteStream diff --git a/SDKLauncher-iOS.xcodeproj/project.pbxproj b/SDKLauncher-iOS.xcodeproj/project.pbxproj index 5250681..f22ae3d 100644 --- a/SDKLauncher-iOS.xcodeproj/project.pbxproj +++ b/SDKLauncher-iOS.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 2DC070A8190AB6070018A6F9 /* PackageDataResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DC070A7190AB6070018A6F9 /* PackageDataResponse.m */; }; 3403516516CE93F2009E3B88 /* reader.css in Resources */ = {isa = PBXBuildFile; fileRef = 3403516116CE93F2009E3B88 /* reader.css */; }; 3403516616CE93F2009E3B88 /* reader.html in Resources */ = {isa = PBXBuildFile; fileRef = 3403516216CE93F2009E3B88 /* reader.html */; }; 340535AA16BC5DD100D4A802 /* BaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340535A916BC5DD100D4A802 /* BaseViewController.m */; }; @@ -137,6 +138,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 2DC070A6190AB6070018A6F9 /* PackageDataResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PackageDataResponse.h; sourceTree = ""; }; + 2DC070A7190AB6070018A6F9 /* PackageDataResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PackageDataResponse.m; sourceTree = ""; }; 3403516116CE93F2009E3B88 /* reader.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = reader.css; sourceTree = ""; }; 3403516216CE93F2009E3B88 /* reader.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = reader.html; sourceTree = ""; }; 340535A816BC5DD100D4A802 /* BaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseViewController.h; sourceTree = ""; }; @@ -523,6 +526,8 @@ children = ( 3499B0C318413C68002D8AEA /* PackageResourceConnection.h */, 3499B0C418413C68002D8AEA /* PackageResourceConnection.m */, + 2DC070A6190AB6070018A6F9 /* PackageDataResponse.h */, + 2DC070A7190AB6070018A6F9 /* PackageDataResponse.m */, 3434215618D4E826001D4279 /* PackageResourceResponse.h */, 3434215718D4E826001D4279 /* PackageResourceResponse.m */, 34C5534216E15D32003A7C23 /* PackageResourceServer.h */, @@ -806,6 +811,7 @@ 34DAC6EB18D4BB96004F926A /* DispatchQueueLogFormatter.m in Sources */, 34C4064817A451D100354C33 /* EPubSettings.m in Sources */, 34C4064317A43A1700354C33 /* EPubSettingsController.m in Sources */, + 2DC070A8190AB6070018A6F9 /* PackageDataResponse.m in Sources */, 3411DF03175FACC000FCE6D9 /* EPubViewController.m in Sources */, 340535B216BC608900D4A802 /* LocStr.m in Sources */, 340535B316BC608900D4A802 /* LocStrError.m in Sources */, From 88c8ec3cb924175cec7ab2b8d2e5d36f2647bbd8 Mon Sep 17 00:00:00 2001 From: Oliver Eikemeier Date: Sun, 27 Apr 2014 19:41:01 +0200 Subject: [PATCH 2/2] Eliminate the last traces of SimpleHTTPServer --- SDKLauncher-iOS-Prefix.pch | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/SDKLauncher-iOS-Prefix.pch b/SDKLauncher-iOS-Prefix.pch index 6a848d3..91367ee 100644 --- a/SDKLauncher-iOS-Prefix.pch +++ b/SDKLauncher-iOS-Prefix.pch @@ -18,35 +18,4 @@ #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define SCREEN_SIZE ([UIScreen mainScreen].bounds.size) - - // ----------------------------------------- - // SimpleHTTPServer requires the following - -#define DEBUGLOG false - - # define USING_MRR (!__has_feature(objc_arc)) - - # if defined(OS_OBJECT_USE_OBJC) && OS_OBJECT_USE_OBJC - # define DISPATCH_USES_ARC !USING_MRR - # else - # define DISPATCH_USES_ARC 0 - # endif - - #if __has_feature(objc_arc) && defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0 - # define __maybe_weak __weak - # define __block_weak __weak - # define property_weak weak - #elif __has_feature(objc_arc) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 - # define __maybe_weak __weak - # define __block_weak __weak - # define property_weak weak - #else - # define __maybe_weak __unsafe_unretained - # define __block_weak __block - # define property_weak assign - #endif - - // (end SimpleHTTPServer) - // ----------------------------------------- - #endif