This commit is contained in:
Vladimir Enchev
2015-08-03 09:19:40 +03:00
parent 5e5d75c09d
commit cd01d2e55a

View File

@ -35,7 +35,7 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
if (types.isString(options.content) || options.content instanceof FormData) { if (types.isString(options.content) || options.content instanceof FormData) {
urlRequest.HTTPBody = NSString.alloc().initWithString(options.content.toString()).dataUsingEncoding(4); urlRequest.HTTPBody = NSString.alloc().initWithString(options.content.toString()).dataUsingEncoding(4);
} }
if (types.isNumber(options.timeout)) { if (types.isNumber(options.timeout)) {
urlRequest.timeoutInterval = options.timeout / 1000; urlRequest.timeoutInterval = options.timeout / 1000;
} }
@ -46,12 +46,14 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
reject(new Error(error.localizedDescription)); reject(new Error(error.localizedDescription));
} else { } else {
var headers = {}; var headers = {};
var headerFields = response.allHeaderFields; if (response && response.allHeaderFields) {
var keys = headerFields.allKeys; var headerFields = response.allHeaderFields;
var keys = headerFields.allKeys;
for (var i = 0, l = keys.count; i < l; i++) { for (var i = 0, l = keys.count; i < l; i++) {
var key = keys.objectAtIndex(i); var key = keys.objectAtIndex(i);
headers[key] = headerFields.valueForKey(key); headers[key] = headerFields.valueForKey(key);
}
} }
resolve({ resolve({