Skip to content

Commit dcae926

Browse files
authoredOct 27, 2020
fix(ios): headers are not being sent (#284)
1 parent 24b15c5 commit dcae926

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed
 

‎src/ios/CDVFileTransfer.m

+21-24
Original file line numberDiff line numberDiff line change
@@ -103,34 +103,31 @@ - (NSString*)escapePathComponentForUrlString:(NSString*)urlString
103103
- (void)applyRequestHeaders:(NSDictionary*)headers toRequest:(NSMutableURLRequest*)req
104104
{
105105
[req setValue:@"XMLHttpRequest" forHTTPHeaderField:@"X-Requested-With"];
106-
[self.webViewEngine evaluateJavaScript:@"navigator.userAgent" completionHandler:^(NSString* userAgent, NSError* error) {
107-
[req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
108106

109-
for (NSString* headerName in headers) {
110-
id value = [headers objectForKey:headerName];
111-
if (!value || (value == [NSNull null])) {
112-
value = @"null";
113-
}
114-
115-
// First, remove an existing header if one exists.
116-
[req setValue:nil forHTTPHeaderField:headerName];
117-
118-
if (![value isKindOfClass:[NSArray class]]) {
119-
value = [NSArray arrayWithObject:value];
107+
for (NSString* headerName in headers) {
108+
id value = [headers objectForKey:headerName];
109+
if (!value || (value == [NSNull null])) {
110+
value = @"null";
111+
}
112+
113+
// First, remove an existing header if one exists.
114+
[req setValue:nil forHTTPHeaderField:headerName];
115+
116+
if (![value isKindOfClass:[NSArray class]]) {
117+
value = [NSArray arrayWithObject:value];
118+
}
119+
120+
// Then, append all header values.
121+
for (id __strong subValue in value) {
122+
// Convert from an NSNumber -> NSString.
123+
if ([subValue respondsToSelector:@selector(stringValue)]) {
124+
subValue = [subValue stringValue];
120125
}
121-
122-
// Then, append all header values.
123-
for (id __strong subValue in value) {
124-
// Convert from an NSNumber -> NSString.
125-
if ([subValue respondsToSelector:@selector(stringValue)]) {
126-
subValue = [subValue stringValue];
127-
}
128-
if ([subValue isKindOfClass:[NSString class]]) {
129-
[req addValue:subValue forHTTPHeaderField:headerName];
130-
}
126+
if ([subValue isKindOfClass:[NSString class]]) {
127+
[req addValue:subValue forHTTPHeaderField:headerName];
131128
}
132129
}
133-
}];
130+
}
134131
}
135132

136133
- (NSURLRequest*)requestForUploadCommand:(CDVInvokedUrlCommand*)command fileData:(NSData*)fileData

0 commit comments

Comments
 (0)
Failed to load comments.