http timeout fixes + test

This commit is contained in:
Vladimir Enchev
2015-05-14 11:32:33 +03:00
parent 3a53ad049b
commit d8bd0031db
3 changed files with 19 additions and 5 deletions

View File

@ -160,6 +160,20 @@ export var test_request_shouldFailIfOptionsUrlIsNotDefined = function (done) {
});
};
export var test_request_requestShouldTimeout = function (done) {
var result;
http.request({ url: "http://10.255.255.1", method: "GET", timeout: 500 }).catch(function (e) {
result = e;
try {
TKUnit.assert(result instanceof Error, "Result from request().fail() should be Error! Current type is " + typeof result);
done(null);
}
catch (err) {
done(err);
}
});
};
export var test_request_responseStatusCodeShouldBeDefined = function (done) {
var result: http.HttpResponse;

View File

@ -32,14 +32,14 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
}
}
if (types.isNumber(options.timeout)) {
urlRequest.timeoutInterval = options.timeout * 1000;
}
if (types.isString(options.content)) {
urlRequest.HTTPBody = NSString.alloc().initWithString(options.content).dataUsingEncoding(4);
}
if (types.isNumber(options.timeout)) {
urlRequest.timeoutInterval = options.timeout / 1000;
}
var dataTask = session.dataTaskWithRequestCompletionHandler(urlRequest,
function (data: NSData, response: NSHTTPURLResponse, error: NSError) {
if (error) {

2
http/http.d.ts vendored
View File

@ -72,7 +72,7 @@ declare module "http" {
content?: string;
/**
* Gets or sets the request timeout.
* Gets or sets the request timeout in milliseconds.
*/
timeout?: number;
}