mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2024-10-06 07:42:20 +08:00
fix(ios): headers are not being sent (#284)
This commit is contained in:
parent
24b15c5f5a
commit
dcae9269b8
@ -103,34 +103,31 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
|
|||||||
- (void)applyRequestHeaders:(NSDictionary*)headers toRequest:(NSMutableURLRequest*)req
|
- (void)applyRequestHeaders:(NSDictionary*)headers toRequest:(NSMutableURLRequest*)req
|
||||||
{
|
{
|
||||||
[req setValue:@"XMLHttpRequest" forHTTPHeaderField:@"X-Requested-With"];
|
[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) {
|
for (NSString* headerName in headers) {
|
||||||
id value = [headers objectForKey:headerName];
|
id value = [headers objectForKey:headerName];
|
||||||
if (!value || (value == [NSNull null])) {
|
if (!value || (value == [NSNull null])) {
|
||||||
value = @"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];
|
||||||
}
|
}
|
||||||
|
if ([subValue isKindOfClass:[NSString class]]) {
|
||||||
// First, remove an existing header if one exists.
|
[req addValue:subValue forHTTPHeaderField:headerName];
|
||||||
[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];
|
|
||||||
}
|
|
||||||
if ([subValue isKindOfClass:[NSString class]]) {
|
|
||||||
[req addValue:subValue forHTTPHeaderField:headerName];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}];
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURLRequest*)requestForUploadCommand:(CDVInvokedUrlCommand*)command fileData:(NSData*)fileData
|
- (NSURLRequest*)requestForUploadCommand:(CDVInvokedUrlCommand*)command fileData:(NSData*)fileData
|
||||||
|
Loading…
Reference in New Issue
Block a user