
响应式攻击性是一个非侵入性的框架,用于拦截应用程序和服务器之间的任何传出请求以及用于调试目的的响应。
响应式攻击性用Swift 5.3编写,并支持iOS 9.0+ , MACOS 10.10+和TVOS 9.0+ 。
在您的项目中纳入响应性探测性非常简单 - 这一切都归结为两个步骤:
为了进行响应的工作,需要在您的(NS)URLSession和Internet之间作为中间人添加它。您可以通过在会话的(NS)URLSessionConfiguration.protocolClasses中注册提供的URLProtocol类,或使用快捷方式方法来做到这一点:
// Objective-C
NSURLSessionConfiguration *configuration = [ NSURLSessionConfiguration defaultSessionConfiguration ];
[RDTResponseDetective enableInConfiguration: configuration];// Swift
let configuration = URLSessionConfiguration . default
ResponseDetective . enable ( inConfiguration : configuration )然后,您应该将该配置与(NS)URLSession一起使用:
// Objective-C
NSURLSession *session = [[ NSURLSession alloc ] initWithConfiguration: configuration];// Swift
let session = URLSession ( configuration : configuration )或者,如果您将afnetworking / alamofire用作网络框架,则集成响应性探索性归结为仅将您的AFURLSessionManager / Manager与上述(NS)URLSessionConfiguration初始化:
// Objective-C (AFNetworking)
AFURLSessionManager *manager = [[AFURLSessionManager alloc ] initWithSessionConfiguration: configuration];// Swift (Alamofire)
let manager = Alamofire . SessionManager ( configuration : configuration )仅此而已!
现在是时候执行实际请求了:
// Objective-C
NSURLRequest *request = [[ NSURLRequest alloc ] initWithURL: [ NSURL URLWithString: @" http://httpbin.org/get " ]];
[[session dataTaskWithRequest: request] resume ];// Swift
let request = URLRequest ( URL : URL ( string : " http://httpbin.org/get " ) ! )
session . dataTask ( with : request ) . resume ( )瞧! ?查看您的控制台输出:
<0x000000000badf00d> [REQUEST] GET https://httpbin.org/get
├─ Headers
├─ Body
│ <none>
<0x000000000badf00d> [RESPONSE] 200 (NO ERROR) https://httpbin.org/get
├─ Headers
│ Server: nginx
│ Date: Thu, 01 Jan 1970 00:00:00 GMT
│ Content-Type: application/json
├─ Body
│ {
│ "args" : {
│ },
│ "headers" : {
│ "User-Agent" : "ResponseDetective/1 CFNetwork/758.3.15 Darwin/15.4.0",
│ "Accept-Encoding" : "gzip, deflate",
│ "Host" : "httpbin.org",
│ "Accept-Language" : "en-us",
│ "Accept" : "*/*"
│ },
│ "url" : "https://httpbin.org/get"
│ }
如果您使用的是迦太基,请将以下依赖性添加到您的Cartfile :
github "netguru/ResponseDetective" ~> {version}
如果您使用的是Cocoapods,请将以下依赖性添加到您的Podfile :
use_frameworks!
pod 'ResponseDetective', '~> {version}'
如果您使用的是Swift软件包管理器,请将此存储库添加到项目设置中的Swift软件包中。
要安装测试依赖项或构建反应性探测性本身,请不要直接运行carthage 。它无法处理Xcode 12中引入的Apple Silicon架构。相反,将其运行carthage.sh脚本:
$ ./carthage.sh bootstrap另外,您可以使用以下命令使用Swift软件包管理器在本地运行测试:
$ swift test 该项目是由Netguru由Netguru制成的。
从1.0.0版本开始,Responsedective的发行版本以夏洛克·福尔摩斯(Sherlock Holmes)的佳能故事命名,按时间顺序排列。如果我们达到60个发行版,没有更多的故事会发生什么?我们不知道,也许我们会在猫之类的东西之后开始命名它们。
该项目已根据MIT许可获得许可。有关更多信息,请参见License.MD。