mirror of
https://github.com/NohamR/knowledge-kit.git
synced 2026-05-25 04:17:17 +00:00
docs: 微服务平台下基于 GraphQL 构建 BFF 的思考changeLog
This commit is contained in:
@@ -263,8 +263,8 @@ typedef CF_OPTIONS(CFOptionFlags, CFRunLoopActivity) {
|
||||
kCFRunLoopBeforeTimers , // 触发 Timer 回调
|
||||
kCFRunLoopBeforeSources , // 触发 Source0 回调
|
||||
kCFRunLoopBeforeWaiting , // 等待 mach_port 消息
|
||||
kCFRunLoopAfterWaiting ), // 接收 mach_port 消息
|
||||
kCFRunLoopExit , // 退出 loop
|
||||
kCFRunLoopAfterWaiting, // 接收 mach_port 消息
|
||||
kCFRunLoopExit, // 退出 loop
|
||||
kCFRunLoopAllActivities // loop 所有状态改变
|
||||
}
|
||||
```
|
||||
@@ -2678,24 +2678,24 @@ CFNetwork 使用 CFReadStreamRef 来传递数据,使用回调函数的形式
|
||||
|
||||
```objective-c
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
||||
// 为 NSURLConnection、NSURLSession、CFNetwork 代理设置代理转发
|
||||
@interface NetworkDelegateProxy : NSProxy
|
||||
|
||||
|
||||
+ (instancetype)setProxyForObject:(id)originalTarget withNewDelegate:(id)newDelegate;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
|
||||
// .m
|
||||
@interface NetworkDelegateProxy () {
|
||||
id _originalTarget;
|
||||
id _NewDelegate;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
```
|
||||
|
||||
@@ -2797,7 +2797,7 @@ CFNetwork 使用 CFReadStreamRef 来传递数据,使用回调函数的形式
|
||||
```objective-c
|
||||
// NSURLConnection+Monitor.m
|
||||
@implementation NSURLConnection (Monitor)
|
||||
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
@@ -2807,7 +2807,7 @@ CFNetwork 使用 CFReadStreamRef 来传递数据,使用回调函数的形式
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
- (_Nonnull instancetype)apm_initWithRequest:(NSURLRequest *)request delegate:(nullable id)delegate
|
||||
{
|
||||
/*
|
||||
@@ -2823,23 +2823,23 @@ CFNetwork 使用 CFReadStreamRef 来传递数据,使用回调函数的形式
|
||||
return [self apm_initWithRequest:rq delegate:delegate];
|
||||
} else {
|
||||
[rq setValue:traceId forHTTPHeaderField:@"head_key_traceid"];
|
||||
|
||||
|
||||
NSURLSessionAndConnectionImplementor *mockDelegate = [NSURLSessionAndConnectionImplementor new];
|
||||
[self registerDelegateMethod:@"connection:didFailWithError:" originalDelegate:delegate newDelegate:mockDelegate flag:"v@:@@"];
|
||||
|
||||
|
||||
[self registerDelegateMethod:@"connection:didReceiveResponse:" originalDelegate:delegate newDelegate:mockDelegate flag:"v@:@@"];
|
||||
[self registerDelegateMethod:@"connection:didReceiveData:" originalDelegate:delegate newDelegate:mockDelegate flag:"v@:@@"];
|
||||
[self registerDelegateMethod:@"connection:didFailWithError:" originalDelegate:delegate newDelegate:mockDelegate flag:"v@:@@"];
|
||||
|
||||
|
||||
[self registerDelegateMethod:@"connectionDidFinishLoading:" originalDelegate:delegate newDelegate:mockDelegate flag:"v@:@"];
|
||||
[self registerDelegateMethod:@"connection:willSendRequest:redirectResponse:" originalDelegate:delegate newDelegate:mockDelegate flag:"@@:@@"];
|
||||
delegate = [NetworkDelegateProxy setProxyForObject:delegate withNewDelegate:mockDelegate];
|
||||
|
||||
|
||||
// 调用 hook 之前的初始化方法,返回 NSURLConnection
|
||||
return [self apm_initWithRequest:rq delegate:delegate];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)registerDelegateMethod:(NSString *)methodName originalDelegate:(id<NSURLConnectionDelegate>)originalDelegate newDelegate:(NSURLSessionAndConnectionImplementor *)newDelegate flag:(const char *)flag
|
||||
{
|
||||
if ([originalDelegate respondsToSelector:NSSelectorFromString(methodName)]) {
|
||||
@@ -2853,7 +2853,7 @@ CFNetwork 使用 CFReadStreamRef 来传递数据,使用回调函数的形式
|
||||
class_addMethod([originalDelegate class], NSSelectorFromString(methodName), class_getMethodImplementation([newDelegate class], NSSelectorFromString(methodName)), flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
```
|
||||
|
||||
@@ -2897,10 +2897,10 @@ CFNetwork 使用 CFReadStreamRef 来传递数据,使用回调函数的形式
|
||||
struct objc_object {
|
||||
Class _Nonnull isa OBJC_ISA_AVAILABILITY;
|
||||
};
|
||||
|
||||
|
||||
/// A pointer to an instance of a class.
|
||||
typedef struct objc_object *id;
|
||||
|
||||
|
||||
```
|
||||
|
||||

|
||||
@@ -3324,7 +3324,7 @@ typedef CFHTTPMessageRef (*APMURLResponseFetchHTTPResponse)(CFURLRef response);
|
||||
- (void)stopLoadi
|
||||
{
|
||||
[self.internalConnection cancel];
|
||||
|
||||
|
||||
HCTNetworkTrafficModel *model = [[HCTNetworkTrafficModel alloc] init];
|
||||
model.path = self.request.URL.path;
|
||||
model.host = self.request.URL.host;
|
||||
@@ -3489,7 +3489,7 @@ typedef CFHTTPMessageRef (*APMURLResponseFetchHTTPResponse)(CFURLRef response);
|
||||
self.internalResponse = response;
|
||||
[self.client URLProtocol:self wasRedirectedToRequest:request redirectResponse:response];
|
||||
}
|
||||
|
||||
|
||||
HCTNetworkTrafficModel *model = [[HCTNetworkTrafficModel alloc] init];
|
||||
model.path = request.URL.path;
|
||||
model.host = request.URL.host;
|
||||
@@ -3499,7 +3499,7 @@ typedef CFHTTPMessageRef (*APMURLResponseFetchHTTPResponse)(CFURLRef response);
|
||||
model.bodyLength = [connection.currentRequest dgm_getBodyLength];
|
||||
model.emptyLineLength = [self.internalResponse apm_getEmptyLineLength];
|
||||
model.length = model.lineLength + model.headerLength + model.bodyLength + model.emptyLineLength;
|
||||
|
||||
|
||||
NSDictionary *networkTrafficDictionary = [model convertToDictionary];
|
||||
[[HermesClient sharedInstance] sendWithType:APMMonitorNetworkTrafficType meta:networkTrafficDictionary payload:nil];
|
||||
return request;
|
||||
|
||||
Reference in New Issue
Block a user