Skip to content

Commit

Permalink
fix(ios): headers are not being sent (apache#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
christiaan authored Oct 27, 2020
1 parent 24b15c5 commit dcae926
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/ios/CDVFileTransfer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dcae926

Please sign in to comment.