diff --git a/BCL.csproj b/BCL.csproj index 4eb71cf05..3ba5ddf24 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -159,7 +159,9 @@ - + + http.d.ts + @@ -189,6 +191,8 @@ + + diff --git a/Tests/http-tests.ts b/Tests/http-tests.ts index 957b23923..88a26a63a 100644 --- a/Tests/http-tests.ts +++ b/Tests/http-tests.ts @@ -43,13 +43,13 @@ export var test_getString_fail = function () { var completed: boolean; var isReady = function () { return completed; } - http.getString("hgfttp://httpbin.org/get").fail(function (e) { + http.getString({ url: "hgfttp://httpbin.org/get", method: "GET", timeout: 2000}).fail(function (e) { completed = true; result = e; }); TKUnit.waitUntilReady(isReady, 3); - TKUnit.assert(result instanceof Error, "Result from getString().fail() should be Error!"); + TKUnit.assert(result instanceof Error, "Result from getString().fail() should be Error! Current type is " + typeof result); }; export var test_getJSON_isDefined = function () { @@ -86,13 +86,13 @@ export var test_getJSON_fail = function () { var completed: boolean; var isReady = function () { return completed; } - http.getJSON("hgfttp://httpbin.org/get").fail(function (e) { + http.getJSON({ url: "hgfttp://httpbin.org/get", method: "GET", timeout: 2000 }).fail(function (e) { completed = true; result = e; }); TKUnit.waitUntilReady(isReady, 3); - TKUnit.assert(result instanceof Error, "Result from getJSON().fail() should be Error!"); + TKUnit.assert(result instanceof Error, "Result from getJSON().fail() should be Error! Current type is " + typeof result); }; export var test_getImage_isDefined = function () { @@ -129,13 +129,13 @@ export var test_getImage_fail = function () { var completed: boolean; var isReady = function () { return completed; } - http.getImage("htadvtp://www.google.com/images/errors/logo_sm_2.pngm").fail(function (e) { + http.getImage({ url: "hgfttp://httpbin.org/get", method: "GET", timeout: 2000 }).fail(function (e) { completed = true; result = e; }); TKUnit.waitUntilReady(isReady, 3); - TKUnit.assert(result instanceof Error, "Result from getImage().fail() should be Error!"); + TKUnit.assert(result instanceof Error, "Result from getImage().fail() should be Error! Current type is " + typeof result); }; export var test_request_isDefined = function () { @@ -153,7 +153,7 @@ export var test_request_shouldFailIfOptionsUrlIsNotDefined = function () { }); TKUnit.waitUntilReady(isReady, 3); - TKUnit.assert(result instanceof Error, "Result from request().fail() should be Error!"); + TKUnit.assert(result instanceof Error, "Result from request().fail() should be Error! Current type is " + typeof result); }; export var test_request_responseStatusCodeShouldBeDefined = function () { diff --git a/http/http.d.ts b/http/http.d.ts new file mode 100644 index 000000000..5611a20fd --- /dev/null +++ b/http/http.d.ts @@ -0,0 +1,12 @@ +import image = require("image-source/image-source"); +import promises = require("promises/promises"); +import request = require("http/http-request"); + +export declare function getString(url: string): promises.Promise +export declare function getString(options: request.HttpRequestOptions): promises.Promise + +export declare function getJSON(url: string): promises.Promise +export declare function getJSON(options: request.HttpRequestOptions): promises.Promise + +export declare function getImage(url: string): promises.Promise +export declare function getImage(options: request.HttpRequestOptions): promises.Promise \ No newline at end of file diff --git a/http/http.ts b/http/http.ts index 5a8ec7b15..78d13b674 100644 --- a/http/http.ts +++ b/http/http.ts @@ -1,4 +1,4 @@ -import image_module = require("image-source/image-source"); +import image = require("image-source/image-source"); import promises = require("promises/promises"); import http = require("http/http-request"); @@ -11,10 +11,10 @@ export interface HttpContent extends http.HttpContent { }; /** * Gets string from url. */ -export function getString(url: string): promises.Promise { +export function getString(arg: any): promises.Promise { var d = promises.defer(); - http.request({ url: url, method: "GET" }) + http.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => d.resolve(r.content.toString())) .fail(e => d.reject(e)); @@ -24,10 +24,10 @@ export function getString(url: string): promises.Promise { /** * Gets JSON from url. */ -export function getJSON(url: string): promises.Promise { +export function getJSON(arg: any): promises.Promise { var d = promises.defer(); - http.request({ url: url, method: "GET" }) + http.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => d.resolve(r.content.toJSON())) .fail(e => d.reject(e)); @@ -37,10 +37,11 @@ export function getJSON(url: string): promises.Promise { /** * Gets image from url. */ -export function getImage(url: string): promises.Promise { - var d = promises.defer(); - http.request({ url: url, method: "GET" }) +export function getImage(arg: any): promises.Promise { + var d = promises.defer(); + + http.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => d.resolve(r.content.toImage())) .fail(e => d.reject(e));