Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.travis.yml
  • Loading branch information
Kofktu committed Sep 26, 2018
2 parents 961e0d3 + df017a5 commit 9ad3704
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,10 +1,10 @@
os: osx
osx_image: xcode9
osx_image: xcode10
sudo: false
language: objective-c

env:
- SDK="iphoneos11.0"
- SDK="iphoneos12.0"

script:
- xcodebuild clean build -sdk $SDK -configuration Debug CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -12,7 +12,8 @@

## Requirements
- iOS 8.0+, macOS 10.9+, watchOS 2.0+, tvOS 9.0+
- Swift 4.0
- Swift 4.2
- Swift 4.0 ([1.5.0](https://github.com/Kofktu/Sniffer/tree/1.5.0))
- Swift 3.0 ([1.0.6](https://github.com/Kofktu/Sniffer/tree/1.0.6))

## Example
Expand Down
2 changes: 1 addition & 1 deletion Sniffer.podspec
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "Sniffer"
s.version = "1.5.0"
s.version = "1.6.0"
s.summary = "Automatic network activity logger for Swift"
s.homepage = "https://github.com/Kofktu/Sniffer"
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
Expand Down
28 changes: 4 additions & 24 deletions Sniffer.xcodeproj/project.pbxproj
Expand Up @@ -28,9 +28,7 @@

/* Begin PBXFileReference section */
43AA4FCCCB0E2B40D520FA8B /* Pods_Sniffer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Sniffer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5E1E01E2A4D9DEF0685763FD /* Pods-SnifferTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnifferTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SnifferTests/Pods-SnifferTests.release.xcconfig"; sourceTree = "<group>"; };
987FCBEDD9BE7C35A2C04184 /* Pods_SnifferTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SnifferTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9AB14D53DD03F2910C49A54B /* Pods-Sniffer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Sniffer.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Sniffer/Pods-Sniffer.debug.xcconfig"; sourceTree = "<group>"; };
C30E56F11E541B9200B4C345 /* Sniffer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Sniffer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C30E56F41E541B9200B4C345 /* Sniffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Sniffer.h; sourceTree = "<group>"; };
C30E56F51E541B9200B4C345 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -39,8 +37,6 @@
C30E57011E541B9200B4C345 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C30E570C1E541BC900B4C345 /* Sniffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sniffer.swift; sourceTree = "<group>"; };
C356DDE41E555D6E00DF7467 /* BodyDeserializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BodyDeserializer.swift; sourceTree = "<group>"; };
EA2941A3518BBB1366BA61EB /* Pods-SnifferTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnifferTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SnifferTests/Pods-SnifferTests.debug.xcconfig"; sourceTree = "<group>"; };
F72D47C694CC1641E6C47660 /* Pods-Sniffer.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Sniffer.release.xcconfig"; path = "Pods/Target Support Files/Pods-Sniffer/Pods-Sniffer.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -62,17 +58,6 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
A80270559E75AB6E23C869D1 /* Pods */ = {
isa = PBXGroup;
children = (
9AB14D53DD03F2910C49A54B /* Pods-Sniffer.debug.xcconfig */,
F72D47C694CC1641E6C47660 /* Pods-Sniffer.release.xcconfig */,
EA2941A3518BBB1366BA61EB /* Pods-SnifferTests.debug.xcconfig */,
5E1E01E2A4D9DEF0685763FD /* Pods-SnifferTests.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
BBC338B95C0E4433B5615C77 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand All @@ -88,7 +73,6 @@
C30E56F31E541B9200B4C345 /* Sniffer */,
C30E56FE1E541B9200B4C345 /* SnifferTests */,
C30E56F21E541B9200B4C345 /* Products */,
A80270559E75AB6E23C869D1 /* Pods */,
BBC338B95C0E4433B5615C77 /* Frameworks */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -368,7 +352,6 @@
};
C30E57061E541B9200B4C345 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 9AB14D53DD03F2910C49A54B /* Pods-Sniffer.debug.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
Expand All @@ -384,13 +367,12 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
C30E57071E541B9200B4C345 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = F72D47C694CC1641E6C47660 /* Pods-Sniffer.release.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
Expand All @@ -405,33 +387,31 @@
PRODUCT_BUNDLE_IDENTIFIER = com.kofktu.Sniffer;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
C30E57091E541B9200B4C345 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = EA2941A3518BBB1366BA61EB /* Pods-SnifferTests.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
INFOPLIST_FILE = SnifferTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.kofktu.SnifferTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
C30E570A1E541B9200B4C345 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5E1E01E2A4D9DEF0685763FD /* Pods-SnifferTests.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
INFOPLIST_FILE = SnifferTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.kofktu.SnifferTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
35 changes: 18 additions & 17 deletions Sniffer/Classes/Sniffer.swift
Expand Up @@ -8,19 +8,21 @@

import Foundation

open class Sniffer: URLProtocol {
enum Keys {
public class Sniffer: URLProtocol {

private enum Keys {
static let request = "Sniffer.request"
static let duration = "Sniffer.duration"
}

static public var onLogger: ((String) -> Void)? // If the handler is registered, the log inside the Sniffer will not be output.

fileprivate var session: URLSession!
fileprivate var urlTask: URLSessionDataTask?
fileprivate var urlRequest: NSMutableURLRequest?
fileprivate var urlResponse: HTTPURLResponse?
fileprivate var data: Data?
private lazy var session: URLSession = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil)
private var urlTask: URLSessionDataTask?
private var urlRequest: NSMutableURLRequest?
private var urlResponse: HTTPURLResponse?
private var data: Data?
private let serialQueue = DispatchQueue(label: "com.kofktu.sniffer.serialQueue")

private static var bodyDeserializers: [String: BodyDeserializer] = [
"application/x-www-form-urlencoded": PlainTextBodyDeserializer(),
Expand Down Expand Up @@ -59,11 +61,6 @@ open class Sniffer: URLProtocol {
return request
}

override init(request: URLRequest, cachedResponse: CachedURLResponse?, client: URLProtocolClient?) {
super.init(request: request, cachedResponse: cachedResponse, client: client)
session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil)
}

open override func startLoading() {
if let _ = urlTask { return }
guard let urlRequest = (request as NSURLRequest).mutableCopy() as? NSMutableURLRequest , self.urlRequest == nil else { return }
Expand All @@ -80,9 +77,11 @@ open class Sniffer: URLProtocol {
}

open override func stopLoading() {
urlTask?.cancel()
urlTask = nil
session.invalidateAndCancel()
serialQueue.sync { [weak self] in
self?.urlTask?.cancel()
self?.urlTask = nil
self?.session.invalidateAndCancel()
}
}

// MARK: - Private
Expand Down Expand Up @@ -140,7 +139,7 @@ open class Sniffer: URLProtocol {
for (pattern, deserializer) in Sniffer.bodyDeserializers {
do {
let regex = try NSRegularExpression(pattern: pattern.replacingOccurrences(of: "*", with: "[a-z]+"))
let results = regex.matches(in: contentType, range: NSRange(location: 0, length: contentType.characters.count))
let results = regex.matches(in: contentType, range: NSRange(location: 0, length: contentType.count))

if !results.isEmpty {
return deserializer
Expand Down Expand Up @@ -266,7 +265,9 @@ extension Sniffer: URLSessionTaskDelegate, URLSessionDataDelegate {
client?.urlProtocolDidFinishLoading(self)
}

clear()
serialQueue.sync { [weak self] in
self?.clear()
}
session.finishTasksAndInvalidate()
}

Expand Down
2 changes: 1 addition & 1 deletion Sniffer/Info.plist
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.6.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 9ad3704

Please sign in to comment.