From dcae9269b8f44a36837a3a0f79241a08f9c6c3a7 Mon Sep 17 00:00:00 2001 From: Christiaan Baartse Date: Tue, 27 Oct 2020 13:56:35 +0100 Subject: [PATCH] fix(ios): headers are not being sent (#284) --- src/ios/CDVFileTransfer.m | 45 ++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m index f1bb44d9..5d556b01 100644 --- a/src/ios/CDVFileTransfer.m +++ b/src/ios/CDVFileTransfer.m @@ -103,34 +103,31 @@ - (NSString*)escapePathComponentForUrlString:(NSString*)urlString - (void)applyRequestHeaders:(NSDictionary*)headers toRequest:(NSMutableURLRequest*)req { [req setValue:@"XMLHttpRequest" forHTTPHeaderField:@"X-Requested-With"]; - [self.webViewEngine evaluateJavaScript:@"navigator.userAgent" completionHandler:^(NSString* userAgent, NSError* error) { - [req setValue:userAgent forHTTPHeaderField:@"User-Agent"]; - for (NSString* headerName in headers) { - id value = [headers objectForKey:headerName]; - if (!value || (value == [NSNull null])) { - value = @"null"; - } - - // First, remove an existing header if one exists. - [req setValue:nil forHTTPHeaderField:headerName]; - - if (![value isKindOfClass:[NSArray class]]) { - value = [NSArray arrayWithObject:value]; + for (NSString* headerName in headers) { + id value = [headers objectForKey:headerName]; + if (!value || (value == [NSNull null])) { + value = @"null"; + } + + // First, remove an existing header if one exists. + [req setValue:nil forHTTPHeaderField:headerName]; + + if (![value isKindOfClass:[NSArray class]]) { + value = [NSArray arrayWithObject:value]; + } + + // Then, append all header values. + for (id __strong subValue in value) { + // Convert from an NSNumber -> NSString. + if ([subValue respondsToSelector:@selector(stringValue)]) { + subValue = [subValue stringValue]; } - - // Then, append all header values. - for (id __strong subValue in value) { - // Convert from an NSNumber -> NSString. - if ([subValue respondsToSelector:@selector(stringValue)]) { - subValue = [subValue stringValue]; - } - if ([subValue isKindOfClass:[NSString class]]) { - [req addValue:subValue forHTTPHeaderField:headerName]; - } + if ([subValue isKindOfClass:[NSString class]]) { + [req addValue:subValue forHTTPHeaderField:headerName]; } } - }]; + } } - (NSURLRequest*)requestForUploadCommand:(CDVInvokedUrlCommand*)command fileData:(NSData*)fileData