mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
http timeout fixes + test
This commit is contained in:
@ -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;
|
||||
|
||||
|
@ -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
2
http/http.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user