Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit cce016c

Browse files
committed
Merge pull request #18 from txtr/txtr-s5-mime-types
Txtr s5 mime types
2 parents 3d151f9 + 88c8ec3 commit cce016c

File tree

8 files changed

+110
-35
lines changed

8 files changed

+110
-35
lines changed

Classes/PackageDataResponse.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// PackageDataResponse.h
3+
// SDKLauncher-iOS
4+
//
5+
// Created by Oliver Eikemeier on 04.04.14.
6+
// Copyright (c) 2014 txtr GmbH.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
//
26+
27+
#import "HTTPDataResponse.h"
28+
29+
@interface PackageDataResponse : HTTPDataResponse
30+
31+
@property (nonatomic, copy) NSString *contentType;
32+
33+
@end

Classes/PackageDataResponse.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// PackageDataResponse.m
3+
// SDKLauncher-iOS
4+
//
5+
// Created by Oliver Eikemeier on 04.04.14.
6+
// Copyright (c) 2014 txtr GmbH.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
//
26+
27+
#import "PackageDataResponse.h"
28+
29+
@implementation PackageDataResponse
30+
31+
- (NSDictionary *)httpHeaders {
32+
if (self.contentType) {
33+
return @{@"Content-Type": self.contentType};
34+
}
35+
else {
36+
return @{};
37+
}
38+
}
39+
40+
@end

Classes/PackageResourceConnection.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88

99
#import "PackageResourceConnection.h"
10-
#import "HTTPDataResponse.h"
10+
#import "PackageDataResponse.h"
1111
#import "PackageResourceResponse.h"
1212
#import "PackageResourceServer.h"
1313
#import "RDPackage.h"
@@ -34,6 +34,8 @@ @implementation PackageResourceConnection
3434
path = [path substringFromIndex:1];
3535
}
3636

37+
NSObject <HTTPResponse> *response = nil;
38+
3739
// Synchronize using a process-level lock to guard against multiple threads accessing a
3840
// resource byte stream, which may lead to instability.
3941

@@ -51,15 +53,20 @@ @implementation PackageResourceConnection
5153
NSData *data = resource.data;
5254

5355
if (data != nil) {
54-
return [[HTTPDataResponse alloc] initWithData:data];
56+
PackageDataResponse *dataResponse = [[PackageDataResponse alloc] initWithData:data];
57+
if (resource.mimeType) {
58+
dataResponse.contentType = resource.mimeType;
59+
}
60+
response = dataResponse;
5561
}
5662
}
5763
else {
58-
return [[PackageResourceResponse alloc] initWithResource:resource];
64+
PackageResourceResponse *resourceResponse = [[PackageResourceResponse alloc] initWithResource:resource];
65+
response = resourceResponse;
5966
}
6067
}
6168

62-
return nil;
69+
return response;
6370
}
6471

6572

Classes/PackageResourceResponse.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,15 @@ - (void)setOffset:(UInt64)offset {
6666
}
6767

6868

69+
- (NSDictionary *)httpHeaders {
70+
NSString *contentType = self->m_resource.mimeType;
71+
if (contentType) {
72+
return @{@"Content-Type": contentType};
73+
}
74+
else {
75+
return @{};
76+
}
77+
}
78+
79+
6980
@end

Classes/RDPackage.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ - (RDPackageResource *)resourceAtRelativePath:(NSString *)relativePath {
270270

271271
if (resource != nil) {
272272
m_byteStreamVector.push_back(std::move(byteStream));
273+
274+
ePub3::ConstManifestItemPtr item = m_package->ManifestItemAtRelativePath(s);
275+
276+
if (item) {
277+
const ePub3::ManifestItem::MimeType &mediaType = item->MediaType();
278+
resource.mimeType = [NSString stringWithUTF8String:mediaType.c_str()];
279+
}
273280
}
274281

275282
return resource;

Classes/RDPackageResource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
// The relative path associated with this resource.
3434
@property (nonatomic, readonly) NSString *relativePath;
3535

36+
@property (nonatomic, copy) NSString *mimeType;
37+
3638
- (id)
3739
initWithDelegate:(id <RDPackageResourceDelegate>)delegate
3840
byteStream:(void *)byteStream

SDKLauncher-iOS-Prefix.pch

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,4 @@
1818

1919
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
2020
#define SCREEN_SIZE ([UIScreen mainScreen].bounds.size)
21-
22-
// -----------------------------------------
23-
// SimpleHTTPServer requires the following
24-
25-
#define DEBUGLOG false
26-
27-
# define USING_MRR (!__has_feature(objc_arc))
28-
29-
# if defined(OS_OBJECT_USE_OBJC) && OS_OBJECT_USE_OBJC
30-
# define DISPATCH_USES_ARC !USING_MRR
31-
# else
32-
# define DISPATCH_USES_ARC 0
33-
# endif
34-
35-
#if __has_feature(objc_arc) && defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
36-
# define __maybe_weak __weak
37-
# define __block_weak __weak
38-
# define property_weak weak
39-
#elif __has_feature(objc_arc) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
40-
# define __maybe_weak __weak
41-
# define __block_weak __weak
42-
# define property_weak weak
43-
#else
44-
# define __maybe_weak __unsafe_unretained
45-
# define __block_weak __block
46-
# define property_weak assign
47-
#endif
48-
49-
// (end SimpleHTTPServer)
50-
// -----------------------------------------
51-
5221
#endif

SDKLauncher-iOS.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
2DC070A8190AB6070018A6F9 /* PackageDataResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DC070A7190AB6070018A6F9 /* PackageDataResponse.m */; };
1011
3403516516CE93F2009E3B88 /* reader.css in Resources */ = {isa = PBXBuildFile; fileRef = 3403516116CE93F2009E3B88 /* reader.css */; };
1112
3403516616CE93F2009E3B88 /* reader.html in Resources */ = {isa = PBXBuildFile; fileRef = 3403516216CE93F2009E3B88 /* reader.html */; };
1213
340535AA16BC5DD100D4A802 /* BaseViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340535A916BC5DD100D4A802 /* BaseViewController.m */; };
@@ -137,6 +138,8 @@
137138
/* End PBXContainerItemProxy section */
138139

139140
/* Begin PBXFileReference section */
141+
2DC070A6190AB6070018A6F9 /* PackageDataResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PackageDataResponse.h; sourceTree = "<group>"; };
142+
2DC070A7190AB6070018A6F9 /* PackageDataResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PackageDataResponse.m; sourceTree = "<group>"; };
140143
3403516116CE93F2009E3B88 /* reader.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = reader.css; sourceTree = "<group>"; };
141144
3403516216CE93F2009E3B88 /* reader.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = reader.html; sourceTree = "<group>"; };
142145
340535A816BC5DD100D4A802 /* BaseViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseViewController.h; sourceTree = "<group>"; };
@@ -523,6 +526,8 @@
523526
children = (
524527
3499B0C318413C68002D8AEA /* PackageResourceConnection.h */,
525528
3499B0C418413C68002D8AEA /* PackageResourceConnection.m */,
529+
2DC070A6190AB6070018A6F9 /* PackageDataResponse.h */,
530+
2DC070A7190AB6070018A6F9 /* PackageDataResponse.m */,
526531
3434215618D4E826001D4279 /* PackageResourceResponse.h */,
527532
3434215718D4E826001D4279 /* PackageResourceResponse.m */,
528533
34C5534216E15D32003A7C23 /* PackageResourceServer.h */,
@@ -806,6 +811,7 @@
806811
34DAC6EB18D4BB96004F926A /* DispatchQueueLogFormatter.m in Sources */,
807812
34C4064817A451D100354C33 /* EPubSettings.m in Sources */,
808813
34C4064317A43A1700354C33 /* EPubSettingsController.m in Sources */,
814+
2DC070A8190AB6070018A6F9 /* PackageDataResponse.m in Sources */,
809815
3411DF03175FACC000FCE6D9 /* EPubViewController.m in Sources */,
810816
340535B216BC608900D4A802 /* LocStr.m in Sources */,
811817
340535B316BC608900D4A802 /* LocStrError.m in Sources */,

0 commit comments

Comments
 (0)