Skip to content

Commit 213b4e7

Browse files
author
Vladimir Enchev
committed
Merge pull request NativeScript#160 from NativeScript/http-timeout
http timeout fixes + test
2 parents 3a53ad0 + d8bd003 commit 213b4e7

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

apps/tests/http-tests.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ export var test_request_shouldFailIfOptionsUrlIsNotDefined = function (done) {
160160
});
161161
};
162162

163+
export var test_request_requestShouldTimeout = function (done) {
164+
var result;
165+
http.request({ url: "http://10.255.255.1", method: "GET", timeout: 500 }).catch(function (e) {
166+
result = e;
167+
try {
168+
TKUnit.assert(result instanceof Error, "Result from request().fail() should be Error! Current type is " + typeof result);
169+
done(null);
170+
}
171+
catch (err) {
172+
done(err);
173+
}
174+
});
175+
};
176+
163177
export var test_request_responseStatusCodeShouldBeDefined = function (done) {
164178
var result: http.HttpResponse;
165179

http/http-request.ios.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
3232
}
3333
}
3434

35-
if (types.isNumber(options.timeout)) {
36-
urlRequest.timeoutInterval = options.timeout * 1000;
37-
}
38-
3935
if (types.isString(options.content)) {
4036
urlRequest.HTTPBody = NSString.alloc().initWithString(options.content).dataUsingEncoding(4);
4137
}
38+
39+
if (types.isNumber(options.timeout)) {
40+
urlRequest.timeoutInterval = options.timeout / 1000;
41+
}
4242

4343
var dataTask = session.dataTaskWithRequestCompletionHandler(urlRequest,
4444
function (data: NSData, response: NSHTTPURLResponse, error: NSError) {

http/http.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ declare module "http" {
7272
content?: string;
7373

7474
/**
75-
* Gets or sets the request timeout.
75+
* Gets or sets the request timeout in milliseconds.
7676
*/
7777
timeout?: number;
7878
}

0 commit comments

Comments
 (0)