old mode 100755
new mode 100644
| | |
| | | NSMutableString *escaped = @"".mutableCopy; |
| | | |
| | | while (index < string.length) { |
| | | #pragma GCC diagnostic push |
| | | #pragma GCC diagnostic ignored "-Wgnu" |
| | | NSUInteger length = MIN(string.length - index, batchSize); |
| | | #pragma GCC diagnostic pop |
| | | NSRange range = NSMakeRange(index, length); |
| | | |
| | | // To avoid breaking up character sequences such as 👴🏻👮🏽 |
| | |
| | | @interface AFHTTPRequestSerializer () |
| | | @property (readwrite, nonatomic, strong) NSMutableSet *mutableObservedChangedKeyPaths; |
| | | @property (readwrite, nonatomic, strong) NSMutableDictionary *mutableHTTPRequestHeaders; |
| | | @property (readwrite, nonatomic, strong) dispatch_queue_t requestHeaderModificationQueue; |
| | | @property (readwrite, nonatomic, assign) AFHTTPRequestQueryStringSerializationStyle queryStringSerializationStyle; |
| | | @property (readwrite, nonatomic, copy) AFQueryStringSerializationBlock queryStringSerialization; |
| | | @end |
| | |
| | | self.stringEncoding = NSUTF8StringEncoding; |
| | | |
| | | self.mutableHTTPRequestHeaders = [NSMutableDictionary dictionary]; |
| | | self.requestHeaderModificationQueue = dispatch_queue_create("requestHeaderModificationQueue", DISPATCH_QUEUE_CONCURRENT); |
| | | |
| | | // Accept-Language HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 |
| | | NSMutableArray *acceptLanguagesComponents = [NSMutableArray array]; |
| | |
| | | [self setValue:[acceptLanguagesComponents componentsJoinedByString:@", "] forHTTPHeaderField:@"Accept-Language"]; |
| | | |
| | | NSString *userAgent = nil; |
| | | #pragma clang diagnostic push |
| | | #pragma clang diagnostic ignored "-Wgnu" |
| | | #if TARGET_OS_IOS |
| | | // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 |
| | | userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]]; |
| | |
| | | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) |
| | | userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]; |
| | | #endif |
| | | #pragma clang diagnostic pop |
| | | if (userAgent) { |
| | | if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) { |
| | | NSMutableString *mutableUserAgent = [userAgent mutableCopy]; |
| | |
| | | #pragma mark - |
| | | |
| | | - (NSDictionary *)HTTPRequestHeaders { |
| | | return [NSDictionary dictionaryWithDictionary:self.mutableHTTPRequestHeaders]; |
| | | NSDictionary __block *value; |
| | | dispatch_sync(self.requestHeaderModificationQueue, ^{ |
| | | value = [NSDictionary dictionaryWithDictionary:self.mutableHTTPRequestHeaders]; |
| | | }); |
| | | return value; |
| | | } |
| | | |
| | | - (void)setValue:(NSString *)value |
| | | forHTTPHeaderField:(NSString *)field |
| | | { |
| | | [self.mutableHTTPRequestHeaders setValue:value forKey:field]; |
| | | dispatch_barrier_async(self.requestHeaderModificationQueue, ^{ |
| | | [self.mutableHTTPRequestHeaders setValue:value forKey:field]; |
| | | }); |
| | | } |
| | | |
| | | - (NSString *)valueForHTTPHeaderField:(NSString *)field { |
| | | return [self.mutableHTTPRequestHeaders valueForKey:field]; |
| | | NSString __block *value; |
| | | dispatch_sync(self.requestHeaderModificationQueue, ^{ |
| | | value = [self.mutableHTTPRequestHeaders valueForKey:field]; |
| | | }); |
| | | return value; |
| | | } |
| | | |
| | | - (void)setAuthorizationHeaderFieldWithUsername:(NSString *)username |
| | |
| | | } |
| | | |
| | | - (void)clearAuthorizationHeader { |
| | | [self.mutableHTTPRequestHeaders removeObjectForKey:@"Authorization"]; |
| | | dispatch_barrier_async(self.requestHeaderModificationQueue, ^{ |
| | | [self.mutableHTTPRequestHeaders removeObjectForKey:@"Authorization"]; |
| | | }); |
| | | } |
| | | |
| | | #pragma mark - |
| | |
| | | } |
| | | |
| | | - (void)encodeWithCoder:(NSCoder *)coder { |
| | | [coder encodeObject:self.mutableHTTPRequestHeaders forKey:NSStringFromSelector(@selector(mutableHTTPRequestHeaders))]; |
| | | dispatch_sync(self.requestHeaderModificationQueue, ^{ |
| | | [coder encodeObject:self.mutableHTTPRequestHeaders forKey:NSStringFromSelector(@selector(mutableHTTPRequestHeaders))]; |
| | | }); |
| | | [coder encodeInteger:self.queryStringSerializationStyle forKey:NSStringFromSelector(@selector(queryStringSerializationStyle))]; |
| | | } |
| | | |
| | |
| | | |
| | | - (instancetype)copyWithZone:(NSZone *)zone { |
| | | AFHTTPRequestSerializer *serializer = [[[self class] allocWithZone:zone] init]; |
| | | serializer.mutableHTTPRequestHeaders = [self.mutableHTTPRequestHeaders mutableCopyWithZone:zone]; |
| | | dispatch_sync(self.requestHeaderModificationQueue, ^{ |
| | | serializer.mutableHTTPRequestHeaders = [self.mutableHTTPRequestHeaders mutableCopyWithZone:zone]; |
| | | }); |
| | | serializer.queryStringSerializationStyle = self.queryStringSerializationStyle; |
| | | serializer.queryStringSerialization = self.queryStringSerialization; |
| | | |
| | |
| | | self.bodyStream = [[AFMultipartBodyStream alloc] initWithStringEncoding:encoding]; |
| | | |
| | | return self; |
| | | } |
| | | |
| | | - (void)setRequest:(NSMutableURLRequest *)request |
| | | { |
| | | _request = [request mutableCopy]; |
| | | } |
| | | |
| | | - (BOOL)appendPartWithFileURL:(NSURL *)fileURL |
| | |
| | | @end |
| | | |
| | | @implementation AFMultipartBodyStream |
| | | #pragma clang diagnostic push |
| | | #pragma clang diagnostic ignored "-Wimplicit-atomic-properties" |
| | | #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1100) |
| | | @synthesize delegate; |
| | | #endif |
| | | @synthesize streamStatus; |
| | | @synthesize streamError; |
| | | #pragma clang diagnostic pop |
| | | |
| | | - (instancetype)initWithStringEncoding:(NSStringEncoding)encoding { |
| | | self = [super init]; |
| | |
| | | |
| | | NSInteger totalNumberOfBytesRead = 0; |
| | | |
| | | #pragma clang diagnostic push |
| | | #pragma clang diagnostic ignored "-Wgnu" |
| | | while ((NSUInteger)totalNumberOfBytesRead < MIN(length, self.numberOfBytesInPacket)) { |
| | | if (!self.currentHTTPBodyPart || ![self.currentHTTPBodyPart hasBytesAvailable]) { |
| | | if (!(self.currentHTTPBodyPart = [self.HTTPBodyPartEnumerator nextObject])) { |
| | |
| | | } |
| | | } |
| | | } |
| | | #pragma clang diagnostic pop |
| | | |
| | | return totalNumberOfBytesRead; |
| | | } |
| | |
| | | return YES; |
| | | } |
| | | |
| | | #pragma clang diagnostic push |
| | | #pragma clang diagnostic ignored "-Wcovered-switch-default" |
| | | switch (self.inputStream.streamStatus) { |
| | | case NSStreamStatusNotOpen: |
| | | case NSStreamStatusOpening: |
| | |
| | | default: |
| | | return NO; |
| | | } |
| | | #pragma clang diagnostic pop |
| | | } |
| | | |
| | | - (NSInteger)read:(uint8_t *)buffer |
| | |
| | | intoBuffer:(uint8_t *)buffer |
| | | maxLength:(NSUInteger)length |
| | | { |
| | | #pragma clang diagnostic push |
| | | #pragma clang diagnostic ignored "-Wgnu" |
| | | NSRange range = NSMakeRange((NSUInteger)_phaseReadOffset, MIN([data length] - ((NSUInteger)_phaseReadOffset), length)); |
| | | [data getBytes:buffer range:range]; |
| | | #pragma clang diagnostic pop |
| | | |
| | | _phaseReadOffset += range.length; |
| | | |
| | |
| | | return YES; |
| | | } |
| | | |
| | | #pragma clang diagnostic push |
| | | #pragma clang diagnostic ignored "-Wcovered-switch-default" |
| | | switch (_phase) { |
| | | case AFEncapsulationBoundaryPhase: |
| | | _phase = AFHeaderPhase; |
| | |
| | | break; |
| | | } |
| | | _phaseReadOffset = 0; |
| | | #pragma clang diagnostic pop |
| | | |
| | | return YES; |
| | | } |
| | |
| | | [mutableRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; |
| | | } |
| | | |
| | | [mutableRequest setHTTPBody:[NSJSONSerialization dataWithJSONObject:parameters options:self.writingOptions error:error]]; |
| | | if (![NSJSONSerialization isValidJSONObject:parameters]) { |
| | | if (error) { |
| | | NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: NSLocalizedStringFromTable(@"The `parameters` argument is not valid JSON.", @"AFNetworking", nil)}; |
| | | *error = [[NSError alloc] initWithDomain:AFURLRequestSerializationErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo]; |
| | | } |
| | | return nil; |
| | | } |
| | | |
| | | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:self.writingOptions error:error]; |
| | | |
| | | if (!jsonData) { |
| | | return nil; |
| | | } |
| | | |
| | | [mutableRequest setHTTPBody:jsonData]; |
| | | } |
| | | |
| | | return mutableRequest; |
| | |
| | | [mutableRequest setValue:@"application/x-plist" forHTTPHeaderField:@"Content-Type"]; |
| | | } |
| | | |
| | | [mutableRequest setHTTPBody:[NSPropertyListSerialization dataWithPropertyList:parameters format:self.format options:self.writeOptions error:error]]; |
| | | NSData *plistData = [NSPropertyListSerialization dataWithPropertyList:parameters format:self.format options:self.writeOptions error:error]; |
| | | |
| | | if (!plistData) { |
| | | return nil; |
| | | } |
| | | |
| | | [mutableRequest setHTTPBody:plistData]; |
| | | } |
| | | |
| | | return mutableRequest; |