Remove internal plugins
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
|
|
||||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
|
||||||
* purposes only. Facebook reserves all rights not expressly granted.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* FACEBOOK 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
#import <SonarKitNetworkPlugin/SKNetworkReporter.h>
|
|
||||||
#import "SKTigonObserver.h"
|
|
||||||
|
|
||||||
@interface SKTigonAdapter: NSObject<SKNetworkAdapterDelegate>
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#import "SKTigonAdapter.h"
|
|
||||||
|
|
||||||
#import <FBDataCompress/NSData+Compress.h>
|
|
||||||
#import <FBHttpExecutorSingletons/FBHttpExecutor+Singletons.h>
|
|
||||||
#import <FBNetworker/FBHttpExecutor+Tigon.h>
|
|
||||||
#import <FBNetworker/FBHttpExecutor.h>
|
|
||||||
#import <FBTigonUtils/FBTigonBuffer.h>
|
|
||||||
#import <FBTigonUtils/FBTigonError.h>
|
|
||||||
#import <FBTigonUtils/FBTigonRequest.h>
|
|
||||||
#import <TigonSecretary/TigonDebugObserver.h>
|
|
||||||
#import <TigonSecretary/TigonObserver.h>
|
|
||||||
#import <TigonSecretary/TigonRequestStats.h>
|
|
||||||
|
|
||||||
@implementation SKTigonAdapter
|
|
||||||
{
|
|
||||||
std::unique_ptr<facebook::mobile::xplat::executor::ObserverToken> _observerToken;
|
|
||||||
std::unique_ptr<facebook::mobile::xplat::executor::ObserverToken> _observerDebugToken;
|
|
||||||
}
|
|
||||||
@synthesize delegate = _delegate;
|
|
||||||
|
|
||||||
- (void)setDelegate:(id<SKNetworkReporterDelegate>)delegate {
|
|
||||||
_delegate = delegate;
|
|
||||||
auto listener = std::make_shared<SKTigonObserver>(_delegate);
|
|
||||||
|
|
||||||
_observerToken = [[FBHttpExecutor sharedStack] addObserver:listener];
|
|
||||||
_observerDebugToken = [[FBHttpExecutor sharedStack] addDebugObserver:listener];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)dealloc {
|
|
||||||
if (_observerToken) {
|
|
||||||
_observerToken->remove();
|
|
||||||
_observerToken = nullptr;
|
|
||||||
}
|
|
||||||
if (_observerDebugToken) {
|
|
||||||
_observerDebugToken->remove();
|
|
||||||
_observerDebugToken = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#import <SonarKitNetworkPlugin/SKDispatchQueue.h>
|
|
||||||
|
|
||||||
#import <vector>
|
|
||||||
|
|
||||||
namespace facebook {
|
|
||||||
namespace sonar {
|
|
||||||
class SyncQueue: public DispatchQueue
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SyncQueue()
|
|
||||||
:_isSuspended(NO){}
|
|
||||||
|
|
||||||
void async(dispatch_block_t block) override
|
|
||||||
{
|
|
||||||
if (_isSuspended) {
|
|
||||||
_blockArray.push_back(block);
|
|
||||||
} else {
|
|
||||||
block();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void suspend()
|
|
||||||
{
|
|
||||||
_isSuspended = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
void resume()
|
|
||||||
{
|
|
||||||
_isSuspended = NO;
|
|
||||||
for (const auto &block : _blockArray) {
|
|
||||||
block();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<dispatch_block_t> _blockArray;
|
|
||||||
bool _isSuspended;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
#import <SonarKitNetworkPlugin/SonarKitNetworkPlugin.h>
|
|
||||||
@interface SKTigonNetworkPluginMock : SonarKitNetworkPlugin
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#import "SKTigonNetworkPluginMock.h"
|
|
||||||
|
|
||||||
#import "SKDispatchQueueMock.h"
|
|
||||||
|
|
||||||
@implementation SKTigonNetworkPluginMock
|
|
||||||
|
|
||||||
- (instancetype)initWithNetworkAdapter:(id<SKNetworkAdapterDelegate>)adapter {
|
|
||||||
return [super initWithNetworkAdapter:adapter queue:std::make_shared<facebook::sonar::SyncQueue>()];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#import <XCTest/XCTest.h>
|
|
||||||
|
|
||||||
#import <SonarKitNetworkPlugin/SonarKitNetworkPlugin.h>
|
|
||||||
#import <SonarKitTestUtils/SonarConnectionMock.h>
|
|
||||||
#import <SKTigonNetworkPlugin/SKTigonObserver.h>
|
|
||||||
#import <SKTigonNetworkPluginTestUtils/SKDispatchQueueMock.h>
|
|
||||||
|
|
||||||
static FBMonotonicTimeMilliseconds sendRequestInfoForIdentifier(NSInteger identifier, SKBufferingPlugin *plugin)
|
|
||||||
{
|
|
||||||
FBMonotonicTimeMilliseconds requestTimestamp = FBMonotonicTimeGetCurrentMilliseconds();
|
|
||||||
|
|
||||||
[plugin send:@"newRequest" sonarObject:@{
|
|
||||||
@"id": @(identifier),
|
|
||||||
@"timestamp": @(requestTimestamp),
|
|
||||||
}];
|
|
||||||
|
|
||||||
return requestTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@interface SKBufferingPluginTests : XCTestCase
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation SKBufferingPluginTests
|
|
||||||
|
|
||||||
- (void)testCacheAfterSuccessfulConnection {
|
|
||||||
SKBufferingPlugin *plugin = [[SKBufferingPlugin alloc] initWithQueue:std::make_shared<facebook::sonar::SyncQueue>()];
|
|
||||||
|
|
||||||
FBMonotonicTimeMilliseconds timestamp1 = sendRequestInfoForIdentifier(1, plugin);
|
|
||||||
FBMonotonicTimeMilliseconds timestamp2 = sendRequestInfoForIdentifier(2, plugin);
|
|
||||||
SonarConnectionMock *connection = [SonarConnectionMock new];
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
FBMonotonicTimeMilliseconds timestamp3 = sendRequestInfoForIdentifier(3, plugin);
|
|
||||||
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @1,
|
|
||||||
@"timestamp": @(timestamp1),
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @2,
|
|
||||||
@"timestamp": @(timestamp2),
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @3,
|
|
||||||
@"timestamp": @(timestamp3),
|
|
||||||
}]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testCacheAfterDisconnection {
|
|
||||||
SKBufferingPlugin *plugin = [[SKBufferingPlugin alloc] initWithQueue:std::make_shared<facebook::sonar::SyncQueue>()];
|
|
||||||
|
|
||||||
FBMonotonicTimeMilliseconds timestamp1 = sendRequestInfoForIdentifier(1, plugin);
|
|
||||||
SonarConnectionMock *connection = [SonarConnectionMock new];
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
FBMonotonicTimeMilliseconds timestamp2 = sendRequestInfoForIdentifier(2, plugin);
|
|
||||||
[plugin didDisconnect];
|
|
||||||
connection.connected = NO;
|
|
||||||
FBMonotonicTimeMilliseconds timestamp3 = sendRequestInfoForIdentifier(3, plugin);
|
|
||||||
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @1,
|
|
||||||
@"timestamp": @(timestamp1),
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @2,
|
|
||||||
@"timestamp": @(timestamp2),
|
|
||||||
}]));
|
|
||||||
XCTAssertFalse(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @3,
|
|
||||||
@"timestamp": @(timestamp3),
|
|
||||||
}]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testCacheAfterDisconnectionAndConnection {
|
|
||||||
SKBufferingPlugin *plugin = [[SKBufferingPlugin alloc] initWithQueue:std::make_shared<facebook::sonar::SyncQueue>()];
|
|
||||||
|
|
||||||
FBMonotonicTimeMilliseconds timestamp1 = sendRequestInfoForIdentifier(1, plugin);
|
|
||||||
SonarConnectionMock *connection = [SonarConnectionMock new];
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
FBMonotonicTimeMilliseconds timestamp2 = sendRequestInfoForIdentifier(2, plugin);
|
|
||||||
[plugin didDisconnect];
|
|
||||||
connection.connected = NO;
|
|
||||||
FBMonotonicTimeMilliseconds timestamp3 = sendRequestInfoForIdentifier(3, plugin);
|
|
||||||
connection.connected = YES;
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @1,
|
|
||||||
@"timestamp": @(timestamp1),
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @2,
|
|
||||||
@"timestamp": @(timestamp2),
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @3,
|
|
||||||
@"timestamp": @(timestamp3),
|
|
||||||
}]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testLossOfEventsDueToDisconnection {
|
|
||||||
auto queue = std::make_shared<facebook::sonar::SyncQueue>();
|
|
||||||
SKBufferingPlugin *plugin = [[SKBufferingPlugin alloc] initWithQueue:queue];
|
|
||||||
FBMonotonicTimeMilliseconds timestamp1 = sendRequestInfoForIdentifier(1, plugin);
|
|
||||||
queue->suspend();
|
|
||||||
FBMonotonicTimeMilliseconds timestamp2 = sendRequestInfoForIdentifier(2, plugin);
|
|
||||||
SonarConnectionMock *connection = [SonarConnectionMock new];
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
[plugin didDisconnect];
|
|
||||||
connection.connected = NO;
|
|
||||||
queue->resume();
|
|
||||||
XCTAssertFalse(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @1,
|
|
||||||
@"timestamp": @(timestamp1),
|
|
||||||
}]));
|
|
||||||
XCTAssertFalse(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @2,
|
|
||||||
@"timestamp": @(timestamp2),
|
|
||||||
}]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testCacheInQueueSuspension {
|
|
||||||
auto queue = std::make_shared<facebook::sonar::SyncQueue>();
|
|
||||||
SKBufferingPlugin *plugin = [[SKBufferingPlugin alloc] initWithQueue:queue];
|
|
||||||
FBMonotonicTimeMilliseconds timestamp1 = sendRequestInfoForIdentifier(1, plugin);
|
|
||||||
queue->suspend();
|
|
||||||
FBMonotonicTimeMilliseconds timestamp2 = sendRequestInfoForIdentifier(2, plugin);
|
|
||||||
SonarConnectionMock *connection = [SonarConnectionMock new];
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
queue->resume();
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @1,
|
|
||||||
@"timestamp": @(timestamp1),
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @2,
|
|
||||||
@"timestamp": @(timestamp2),
|
|
||||||
}]));
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#import <XCTest/XCTest.h>
|
|
||||||
|
|
||||||
#import <WebKit/WebKit.h>
|
|
||||||
#import <Foundation/NSURLResponse.h>
|
|
||||||
|
|
||||||
#import <SonarKitTestUtils/SonarConnectionMock.h>
|
|
||||||
#import <SKTigonNetworkPluginTestUtils/SKTigonNetworkPluginMock.h>
|
|
||||||
#import <SonarKitNetworkPlugin/SonarKitNetworkPlugin.h>
|
|
||||||
#import <SKTigonNetworkPlugin/SKTigonObserver.h>
|
|
||||||
#import <SKTigonNetworkPlugin/SKTigonAdapter.h>
|
|
||||||
|
|
||||||
static BOOL isResponseStrippedForContentType(NSString *contentType)
|
|
||||||
{
|
|
||||||
SKTigonNetworkPluginMock *plugin = [[SKTigonNetworkPluginMock alloc] initWithNetworkAdapter:[SKTigonAdapter new]];
|
|
||||||
SonarConnectionMock *connection = [SonarConnectionMock new];
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
id<SKNetworkReporterDelegate> delegate = (id<SKNetworkReporterDelegate>)plugin;
|
|
||||||
|
|
||||||
NSURL *url = [NSURL URLWithString: @"http://fakeurl"];
|
|
||||||
NSURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL: url
|
|
||||||
statusCode: 200
|
|
||||||
HTTPVersion: @"1.1"
|
|
||||||
headerFields: @{
|
|
||||||
@"content-type": contentType
|
|
||||||
}];
|
|
||||||
|
|
||||||
FBMonotonicTimeMilliseconds responseTimestamp = FBMonotonicTimeGetCurrentMilliseconds();
|
|
||||||
NSData *responseBody = [@"some-response-data" dataUsingEncoding: NSUTF8StringEncoding];
|
|
||||||
|
|
||||||
ResponseInfo responseInfo = {
|
|
||||||
.identifier = 1,
|
|
||||||
.timestamp = responseTimestamp,
|
|
||||||
.response = response,
|
|
||||||
.body = nil,
|
|
||||||
};
|
|
||||||
responseInfo.setBody(responseBody);
|
|
||||||
|
|
||||||
[delegate didObserveResponse:responseInfo];
|
|
||||||
id data = connection.sent[@"newResponse"][0][@"data"];
|
|
||||||
|
|
||||||
return [data isEqual:[NSNull null]];
|
|
||||||
}
|
|
||||||
|
|
||||||
static FBMonotonicTimeMilliseconds sendRequestInfoForIdentifier(NSInteger identifier, NSData *requestBody, SonarKitNetworkPlugin *plugin)
|
|
||||||
{
|
|
||||||
id<SKNetworkReporterDelegate> delegate = (id<SKNetworkReporterDelegate>)plugin;
|
|
||||||
NSURL *url = [NSURL URLWithString: @"http://fakeurl"];
|
|
||||||
NSMutableURLRequest *request = [[NSURLRequest requestWithURL: url] mutableCopy];
|
|
||||||
[request setHTTPMethod: @"POST"];
|
|
||||||
[request addValue: @"somevalue" forHTTPHeaderField:@"some-header-field"];
|
|
||||||
|
|
||||||
FBMonotonicTimeMilliseconds requestTimestamp = FBMonotonicTimeGetCurrentMilliseconds();
|
|
||||||
|
|
||||||
RequestInfo requestInfo = {
|
|
||||||
.identifier = identifier,
|
|
||||||
.timestamp = requestTimestamp,
|
|
||||||
.request = request,
|
|
||||||
.body = nil,
|
|
||||||
};
|
|
||||||
requestInfo.setBody(requestBody);
|
|
||||||
[delegate didObserveRequest:requestInfo];
|
|
||||||
return requestTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@interface SKTigonNetworkPluginTests : XCTestCase
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation SKTigonNetworkPluginTests
|
|
||||||
|
|
||||||
- (void)testPluginIsObserverDelegate
|
|
||||||
{
|
|
||||||
SonarKitNetworkPlugin *plugin = [[SKTigonNetworkPluginMock alloc] initWithNetworkAdapter:[SKTigonAdapter new]];
|
|
||||||
XCTAssertTrue([plugin conformsToProtocol: @protocol(SKNetworkReporterDelegate)], @"SKTigonNetworkPlugin should conform to SKTigonObserverDelegate");
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testObserveRequest
|
|
||||||
{
|
|
||||||
SKTigonNetworkPluginMock *plugin = [[SKTigonNetworkPluginMock alloc] initWithNetworkAdapter:[SKTigonAdapter new]];
|
|
||||||
SonarConnectionMock *connection = [SonarConnectionMock new];
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
id<SKNetworkReporterDelegate> delegate = (id<SKNetworkReporterDelegate>)plugin;
|
|
||||||
|
|
||||||
NSURL *url = [NSURL URLWithString: @"http://fakeurl"];
|
|
||||||
NSMutableURLRequest *request = [[NSURLRequest requestWithURL: url] mutableCopy];
|
|
||||||
[request setHTTPMethod: @"POST"];
|
|
||||||
[request addValue: @"somevalue" forHTTPHeaderField:@"some-header-field"];
|
|
||||||
|
|
||||||
FBMonotonicTimeMilliseconds requestTimestamp = FBMonotonicTimeGetCurrentMilliseconds();
|
|
||||||
NSData *requestBody = [@"some-request-data" dataUsingEncoding: NSUTF8StringEncoding];
|
|
||||||
|
|
||||||
RequestInfo requestInfo = {
|
|
||||||
.identifier = 1,
|
|
||||||
.timestamp = requestTimestamp,
|
|
||||||
.request = request,
|
|
||||||
.body = nil,
|
|
||||||
};
|
|
||||||
requestInfo.setBody(requestBody);
|
|
||||||
|
|
||||||
[delegate didObserveRequest:requestInfo];
|
|
||||||
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @1,
|
|
||||||
@"timestamp": @(requestTimestamp),
|
|
||||||
@"method": @"POST",
|
|
||||||
@"url": @"http://fakeurl",
|
|
||||||
@"headers": @[ @{
|
|
||||||
@"key": @"some-header-field",
|
|
||||||
@"value": @"somevalue"
|
|
||||||
}],
|
|
||||||
@"data": [requestBody base64EncodedStringWithOptions: 0]
|
|
||||||
}]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testObserveRequestWithCache {
|
|
||||||
SKTigonNetworkPluginMock *plugin = [[SKTigonNetworkPluginMock alloc] initWithNetworkAdapter:[SKTigonAdapter new]];
|
|
||||||
NSData *requestBody = [@"some-request-data" dataUsingEncoding: NSUTF8StringEncoding];
|
|
||||||
FBMonotonicTimeMilliseconds timestamp1 = sendRequestInfoForIdentifier(1, requestBody, plugin);
|
|
||||||
FBMonotonicTimeMilliseconds timestamp2 = sendRequestInfoForIdentifier(2, requestBody, plugin);
|
|
||||||
FBMonotonicTimeMilliseconds timestamp3 = sendRequestInfoForIdentifier(3, requestBody, plugin);
|
|
||||||
SonarConnectionMock *connection = [SonarConnectionMock new];
|
|
||||||
[plugin didConnect: connection];
|
|
||||||
FBMonotonicTimeMilliseconds timestamp4 = sendRequestInfoForIdentifier(4, requestBody, plugin);
|
|
||||||
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @1,
|
|
||||||
@"timestamp": @(timestamp1),
|
|
||||||
@"method": @"POST",
|
|
||||||
@"url": @"http://fakeurl",
|
|
||||||
@"headers": @[ @{
|
|
||||||
@"key": @"some-header-field",
|
|
||||||
@"value": @"somevalue"
|
|
||||||
}],
|
|
||||||
@"data": [requestBody base64EncodedStringWithOptions: 0]
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @2,
|
|
||||||
@"timestamp": @(timestamp2),
|
|
||||||
@"method": @"POST",
|
|
||||||
@"url": @"http://fakeurl",
|
|
||||||
@"headers": @[ @{
|
|
||||||
@"key": @"some-header-field",
|
|
||||||
@"value": @"somevalue"
|
|
||||||
}],
|
|
||||||
@"data": [requestBody base64EncodedStringWithOptions: 0]
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @3,
|
|
||||||
@"timestamp": @(timestamp3),
|
|
||||||
@"method": @"POST",
|
|
||||||
@"url": @"http://fakeurl",
|
|
||||||
@"headers": @[ @{
|
|
||||||
@"key": @"some-header-field",
|
|
||||||
@"value": @"somevalue"
|
|
||||||
}],
|
|
||||||
@"data": [requestBody base64EncodedStringWithOptions: 0]
|
|
||||||
}]));
|
|
||||||
XCTAssertTrue(([connection.sent[@"newRequest"]
|
|
||||||
containsObject: @{
|
|
||||||
@"id": @4,
|
|
||||||
@"timestamp": @(timestamp4),
|
|
||||||
@"method": @"POST",
|
|
||||||
@"url": @"http://fakeurl",
|
|
||||||
@"headers": @[ @{
|
|
||||||
@"key": @"some-header-field",
|
|
||||||
@"value": @"somevalue"
|
|
||||||
}],
|
|
||||||
@"data": [requestBody base64EncodedStringWithOptions: 0]
|
|
||||||
}]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)testStripBinaryResponse
|
|
||||||
{
|
|
||||||
XCTAssertTrue(isResponseStrippedForContentType(@"image/jpeg"));
|
|
||||||
XCTAssertTrue(isResponseStrippedForContentType(@"image/jpg"));
|
|
||||||
XCTAssertTrue(isResponseStrippedForContentType(@"image/png"));
|
|
||||||
XCTAssertTrue(isResponseStrippedForContentType(@"video/mp4"));
|
|
||||||
XCTAssertTrue(isResponseStrippedForContentType(@"application/zip"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#import <WebKit/WebKit.h>
|
|
||||||
|
|
||||||
#import <FBMonotonicTime/FBMonotonicTime.h>
|
|
||||||
#import <SonarKitNetworkPlugin/SKNetworkReporter.h>
|
|
||||||
#import <TigonSecretary/TigonDebugObserver.h>
|
|
||||||
#import <TigonSecretary/TigonObserver.h>
|
|
||||||
|
|
||||||
class SKTigonObserver : public facebook::tigon::TigonObserver, public facebook::tigon::TigonDebugObserver {
|
|
||||||
public:
|
|
||||||
SKTigonObserver(id<SKNetworkReporterDelegate> notifier);
|
|
||||||
|
|
||||||
void onAdded(std::shared_ptr<const facebook::tigon::TigonRequestAdded> requestAdded) override;
|
|
||||||
|
|
||||||
void onStarted(std::shared_ptr<const facebook::tigon::TigonRequestStarted> requestStarted) override;
|
|
||||||
|
|
||||||
void onResponse(std::shared_ptr<const facebook::tigon::TigonRequestResponse> requestResponse) override;
|
|
||||||
|
|
||||||
void onEOM(std::shared_ptr<const facebook::tigon::TigonRequestSucceeded> requestSucceeded) override;
|
|
||||||
|
|
||||||
void onError(std::shared_ptr<const facebook::tigon::TigonRequestErrored> requestErrored) override;
|
|
||||||
|
|
||||||
void onWillRetry(std::shared_ptr<const facebook::tigon::TigonRequestErrored> requestWillRetry) override {};
|
|
||||||
|
|
||||||
void onUploadBody(const std::shared_ptr<const facebook::tigon::TigonBodyObservation> &requestUploadBody) override;
|
|
||||||
|
|
||||||
void onDownloadBody(const std::shared_ptr<const facebook::tigon::TigonBodyObservation> &requestDownloadBody) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
id<SKNetworkReporterDelegate> _delegate;
|
|
||||||
std::unordered_map<NSUInteger, RequestInfo> _trackedRequests;
|
|
||||||
std::unordered_map<NSUInteger, ResponseInfo> _trackedResponses;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
|
|
||||||
#if FB_SONARKIT_ENABLED
|
|
||||||
|
|
||||||
#import "SKTigonObserver.h"
|
|
||||||
|
|
||||||
#import <FBDataCompress/NSData+Compress.h>
|
|
||||||
#import <FBTigonUtils/FBTigonRequest.h>
|
|
||||||
#import <FBNetworker/FBHttpExecutor.h>
|
|
||||||
#import <FBNetworker/FBHttpExecutor+Tigon.h>
|
|
||||||
#import <TigonSecretary/TigonDebugObserver.h>
|
|
||||||
#import <TigonSecretary/TigonObserver.h>
|
|
||||||
#import <FBTigonUtils/FBTigonBuffer.h>
|
|
||||||
#import <FBTigonUtils/FBTigonError.h>
|
|
||||||
#import <FBTigonUtils/FBTigonRequest.h>
|
|
||||||
#import <TigonSecretary/TigonRequestStats.h>
|
|
||||||
#import <FBHttpExecutorSingletons/FBHttpExecutor+Singletons.h>
|
|
||||||
|
|
||||||
SKTigonObserver::SKTigonObserver(id<SKNetworkReporterDelegate> delegate) : _delegate(delegate) {}
|
|
||||||
|
|
||||||
void SKTigonObserver::onAdded(std::shared_ptr<const facebook::tigon::TigonRequestAdded> requestAdded) {
|
|
||||||
NSURLRequest *request = facebook::FBTigon::fromTigonRequest(requestAdded->submittedTigonRequest());
|
|
||||||
_trackedRequests[requestAdded->requestId()] = {
|
|
||||||
.identifier = requestAdded->requestId(),
|
|
||||||
.request = request,
|
|
||||||
.timestamp = FBMonotonicTimeGetCurrentMilliseconds(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void SKTigonObserver::onStarted(std::shared_ptr<const facebook::tigon::TigonRequestStarted> requestStarted) {
|
|
||||||
NSURLRequest *request = facebook::FBTigon::fromTigonRequest(requestStarted->submittedTigonRequest());
|
|
||||||
_trackedRequests[requestStarted->requestId()] = {
|
|
||||||
.identifier = requestStarted->requestId(),
|
|
||||||
.request = request,
|
|
||||||
.timestamp = FBMonotonicTimeGetCurrentMilliseconds(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void SKTigonObserver::onResponse(std::shared_ptr<const facebook::tigon::TigonRequestResponse> requestResponse) {
|
|
||||||
NSURLRequest *request = facebook::FBTigon::fromTigonRequest(requestResponse->sentTigonRequest());
|
|
||||||
NSHTTPURLResponse *response = facebook::FBTigon::fromTigonResponse(requestResponse->tigonResponse(), [request URL]);
|
|
||||||
_trackedResponses[requestResponse->requestId()] = {
|
|
||||||
.identifier = requestResponse->requestId(),
|
|
||||||
.timestamp = FBMonotonicTimeGetCurrentMilliseconds(),
|
|
||||||
.response = response,
|
|
||||||
.body = nil
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void SKTigonObserver::onError(std::shared_ptr<const facebook::tigon::TigonRequestErrored> requestErrored) {
|
|
||||||
auto result = _trackedResponses.find(requestErrored->requestId());
|
|
||||||
if (result == _trackedResponses.end()) {
|
|
||||||
NSURLRequest *request = facebook::FBTigon::fromTigonRequest(requestErrored->sentTigonRequest());
|
|
||||||
NSHTTPURLResponse *response = facebook::FBTigon::fromTigonResponse(requestErrored->tigonResponse(), [request URL]);
|
|
||||||
[_delegate didObserveResponse:{
|
|
||||||
.identifier = requestErrored->requestId(),
|
|
||||||
.timestamp = FBMonotonicTimeGetCurrentMilliseconds(),
|
|
||||||
.response = response,
|
|
||||||
.body = nil
|
|
||||||
}];
|
|
||||||
} else {
|
|
||||||
ResponseInfo &responseInfo = _trackedResponses[requestErrored->requestId()];
|
|
||||||
responseInfo.timestamp = FBMonotonicTimeGetCurrentMilliseconds();
|
|
||||||
[_delegate didObserveResponse:responseInfo];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SKTigonObserver::onEOM(std::shared_ptr<const facebook::tigon::TigonRequestSucceeded> requestSucceeded) {
|
|
||||||
if (_trackedRequests.count(requestSucceeded->requestId()) != 0) {
|
|
||||||
RequestInfo &requestInfo = _trackedRequests[requestSucceeded->requestId()];
|
|
||||||
[_delegate didObserveRequest:requestInfo];
|
|
||||||
_trackedRequests.erase(requestSucceeded->requestId());
|
|
||||||
}
|
|
||||||
|
|
||||||
ResponseInfo &responseInfo = _trackedResponses[requestSucceeded->requestId()];
|
|
||||||
responseInfo.timestamp = FBMonotonicTimeGetCurrentMilliseconds();
|
|
||||||
[_delegate didObserveResponse:responseInfo];
|
|
||||||
_trackedResponses.erase(requestSucceeded->requestId());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SKTigonObserver::onUploadBody(const std::shared_ptr<const facebook::tigon::TigonBodyObservation> &requestUploadBody) {
|
|
||||||
RequestInfo &requestInfo = _trackedRequests[requestUploadBody->requestId()];
|
|
||||||
|
|
||||||
NSURLRequest *urlRequest = requestInfo.request;
|
|
||||||
|
|
||||||
NSString *contentType = [urlRequest valueForHTTPHeaderField: @"Content-Type"];
|
|
||||||
BOOL isFormData = [contentType hasPrefix: @"application/x-www-form-urlencoded"] ||
|
|
||||||
[contentType hasPrefix: @"multipart/form-data"];
|
|
||||||
|
|
||||||
if (requestUploadBody->body() && isFormData) {
|
|
||||||
NSString *contentEncoding = [urlRequest valueForHTTPHeaderField: @"Content-Encoding"];
|
|
||||||
BOOL isGzip = [contentEncoding isEqualToString: @"gzip"];
|
|
||||||
|
|
||||||
NSData *data = facebook::FBTigon::toNSData(requestUploadBody->body());
|
|
||||||
if (isGzip) {
|
|
||||||
data = [data newDataByDecompressingWithGZIP];
|
|
||||||
}
|
|
||||||
|
|
||||||
requestInfo.setBody(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
[_delegate didObserveRequest:requestInfo];
|
|
||||||
_trackedRequests.erase(requestUploadBody->requestId());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SKTigonObserver::onDownloadBody(const std::shared_ptr<const facebook::tigon::TigonBodyObservation> &requestDownloadBody) {
|
|
||||||
if (requestDownloadBody->body()) {
|
|
||||||
ResponseInfo &responseInfo = _trackedResponses[requestDownloadBody->requestId()];
|
|
||||||
NSData *data = facebook::FBTigon::toNSData(requestDownloadBody->body());
|
|
||||||
responseInfo.setBody(data);
|
|
||||||
_trackedResponses[requestDownloadBody->requestId()] = responseInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user