Skip to content

Commit 0c85372

Browse files
committed
Merge pull request #49 from longbai/detail_info
detail info
2 parents 74eab1e + 33c9c9c commit 0c85372

File tree

8 files changed

+79
-14
lines changed

8 files changed

+79
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#Changelog
22

3+
## 7.0.11.1 (2015-06-23)
4+
5+
### 增加
6+
* response info 增加 user id, timestamp
7+
38
## 7.0.11 (2015-06-07)
49

510
### 增加

Qiniu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Qiniu'
3-
s.version = '7.0.11'
3+
s.version = '7.0.11.1'
44
s.summary = 'Qiniu Resource Storage SDK for iOS and Mac'
55
s.homepage = 'https://github.com/qiniu/objc-sdk'
66
s.social_media_url = 'http://weibo.com/qiniutek'

QiniuSDK/Http/QNHttpManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ - (void) sendRequest:(NSMutableURLRequest *)request
138138
}
139139
[request setTimeoutInterval:_timeout];
140140

141-
[request setValue:QNUserAgent() forHTTPHeaderField:@"User-Agent"];
141+
[request setValue:[[QNUserAgent sharedInstance] description] forHTTPHeaderField:@"User-Agent"];
142142
[request setValue:nil forHTTPHeaderField:@"Accept-Language"];
143143
[_httpManager.operationQueue addOperation:operation];
144144
}

QiniuSDK/Http/QNResponseInfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ extern const int kQNFileError;
7878
*/
7979
@property (nonatomic, readonly) NSString *serverIp;
8080

81+
/**
82+
* 客户端id
83+
*/
84+
@property (nonatomic, readonly) NSString *id;
85+
86+
/**
87+
* 时间戳
88+
*/
89+
@property (readonly) UInt64 timeStamp;
90+
8191
/**
8292
* 网络类型
8393
*/

QiniuSDK/Http/QNResponseInfo.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
#import "QNResponseInfo.h"
11+
#import "QNUserAgent.h"
1112

1213
const int kQNInvalidToken = -5;
1314
const int kQNFileError = -4;
@@ -112,6 +113,8 @@ - (instancetype)initWithStatus:(int)status
112113
_error = error;
113114
_host = host;
114115
_duration = duration;
116+
_id = [QNUserAgent sharedInstance].id;
117+
_timeStamp = [[NSDate date] timeIntervalSince1970];
115118
}
116119
return self;
117120
}
@@ -138,6 +141,8 @@ - (instancetype)init:(int)status
138141
_host = [host copy];
139142
_duration = duration;
140143
_serverIp = ip;
144+
_id = [QNUserAgent sharedInstance].id;
145+
_timeStamp = [[NSDate date] timeIntervalSince1970];
141146
if (status != 200) {
142147
if (body == nil) {
143148
_error = [[NSError alloc] initWithDomain:domain code:_statusCode userInfo:nil];
@@ -165,7 +170,7 @@ - (instancetype)init:(int)status
165170
}
166171

167172
- (NSString *)description {
168-
return [NSString stringWithFormat:@"<%@: %p, status: %d, requestId: %@, xlog: %@, xvia: %@, host: %@ ip: %@ duration:%f s error: %@>", NSStringFromClass([self class]), self, _statusCode, _reqId, _xlog, _xvia, _host, _serverIp, _duration, _error];
173+
return [NSString stringWithFormat:@"<%@= id: %@, status: %d, requestId: %@, xlog: %@, xvia: %@, host: %@ ip: %@ duration: %f s time: %llu error: %@>", NSStringFromClass([self class]), _id, _statusCode, _reqId, _xlog, _xvia, _host, _serverIp, _duration, _timeStamp, _error];
169174
}
170175

171176
- (BOOL)isCancelled {

QiniuSDK/Http/QNSessionManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ - (void) sendRequest:(NSMutableURLRequest *)request
201201

202202
[request setTimeoutInterval:_timeout];
203203

204-
[request setValue:QNUserAgent() forHTTPHeaderField:@"User-Agent"];
204+
[request setValue:[[QNUserAgent sharedInstance] description] forHTTPHeaderField:@"User-Agent"];
205205
[request setValue:nil forHTTPHeaderField:@"Accept-Language"];
206206
[uploadTask resume];
207207
}

QiniuSDK/Http/QNUserAgent.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,24 @@
99
#import <Foundation/Foundation.h>
1010

1111
/**
12-
* UserAgent 生成函数
12+
* UserAgent
1313
*
14-
* @return UserAgent 字串
1514
*/
16-
NSString *QNUserAgent(void);
15+
16+
@interface QNUserAgent : NSObject
17+
18+
/**
19+
* 用户id
20+
*/
21+
@property (copy, nonatomic, readonly) NSString *id;
22+
23+
/**
24+
* UserAgent 字串
25+
*/
26+
- (NSString *)description;
27+
28+
/**
29+
* 单例
30+
*/
31+
+ (instancetype)sharedInstance;
32+
@end

QiniuSDK/Http/QNUserAgent.m

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,44 @@
2323
return [NSString stringWithFormat:@"%lld%u", now_timestamp, r];
2424
}
2525

26-
NSString *QNUserAgent(void) {
27-
static NSString *ua = nil;
28-
static dispatch_once_t onceToken;
29-
dispatch_once(&onceToken, ^{
26+
static NSString *userAgent(NSString *id) {
3027
#if __IPHONE_OS_VERSION_MIN_REQUIRED
31-
ua = [NSString stringWithFormat:@"QiniuObject-C/%@ (%@; iOS %@; %@)", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], clientId()];
28+
return [NSString stringWithFormat:@"QiniuObject-C/%@ (%@; iOS %@; %@)", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], id];
3229
#else
33-
ua = [NSString stringWithFormat:@"QiniuObject-C/%@ (Mac OS X %@; %@)", kQiniuVersion, [[NSProcessInfo processInfo] operatingSystemVersionString], clientId()];
30+
return [NSString stringWithFormat:@"QiniuObject-C/%@ (Mac OS X %@; %@)", kQiniuVersion, [[NSProcessInfo processInfo] operatingSystemVersionString], id];
3431
#endif
32+
}
33+
34+
@interface QNUserAgent ()
35+
@property (nonatomic) NSString *ua;
36+
@end
37+
38+
@implementation QNUserAgent
39+
40+
- (NSString *)description {
41+
return _ua;
42+
}
43+
44+
- (instancetype)init {
45+
if (self = [super init]) {
46+
_id = clientId();
47+
_ua = userAgent(_id);
48+
}
49+
return self;
50+
}
51+
52+
/**
53+
* 单例
54+
*/
55+
+ (instancetype)sharedInstance {
56+
static QNUserAgent *sharedInstance = nil;
57+
58+
static dispatch_once_t onceToken;
59+
dispatch_once(&onceToken, ^{
60+
sharedInstance = [[self alloc] init];
3561
});
36-
return ua;
62+
63+
return sharedInstance;
3764
}
65+
66+
@end

0 commit comments

Comments
 (0)