Allow arrays to be used as arguments for POST/PUT requests
This commit is contained in:
parent
85c5fe3d0d
commit
769c779d8c
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Typertext",
|
"name": "Typertext",
|
||||||
"version": "0.8.1",
|
"version": "0.8.2",
|
||||||
"homepage": "https://github.com/terribleplan/Typertext",
|
"homepage": "https://github.com/terribleplan/Typertext",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Kegan Myers <kegan@keganmyers.com>"
|
"Kegan Myers <kegan@keganmyers.com>"
|
||||||
|
|
|
@ -92,7 +92,11 @@ declare module Typertext.Http {
|
||||||
}
|
}
|
||||||
declare module Typertext.Http {
|
declare module Typertext.Http {
|
||||||
interface HttpQueryString {
|
interface HttpQueryString {
|
||||||
[index: string]: string;
|
[index: string]: any;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module Typertext.Http {
|
||||||
|
interface HttpResponseHandler extends GenericResponseHandler<HttpResponse> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module Typertext.Transport {
|
declare module Typertext.Transport {
|
||||||
|
@ -121,10 +125,6 @@ declare module Typertext.Http {
|
||||||
constructor(status: HttpResponseStatus, responseHeaderGetter?: (input: string) => string, httpResponseCode?: number, responseBody?: string);
|
constructor(status: HttpResponseStatus, responseHeaderGetter?: (input: string) => string, httpResponseCode?: number, responseBody?: string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module Typertext.Http {
|
|
||||||
interface HttpResponseHandler extends GenericResponseHandler<HttpResponse> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module Typertext.Http {
|
declare module Typertext.Http {
|
||||||
enum HttpResponseStatus {
|
enum HttpResponseStatus {
|
||||||
success = 0,
|
success = 0,
|
||||||
|
|
|
@ -130,7 +130,22 @@ var Typertext;
|
||||||
var temp;
|
var temp;
|
||||||
|
|
||||||
for (temp in data) {
|
for (temp in data) {
|
||||||
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(data[temp]) + "&";
|
var cur = data[temp];
|
||||||
|
|
||||||
|
if (cur instanceof Array) {
|
||||||
|
for (var i = 0; i < cur.length; i++) {
|
||||||
|
if (typeof cur[i] !== "string") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(cur[i]) + "&";
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof cur === "string") {
|
||||||
|
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(cur) + "&";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rs.slice(0, -1);
|
return rs.slice(0, -1);
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -5,8 +5,11 @@
|
||||||
module Typertext.Http {
|
module Typertext.Http {
|
||||||
/**
|
/**
|
||||||
* @interface HttpQueryString
|
* @interface HttpQueryString
|
||||||
|
*
|
||||||
|
* Although it appears that this can provide any type of value, implementations
|
||||||
|
* are allowed to disregard types they are unable to handle.
|
||||||
*/
|
*/
|
||||||
export interface HttpQueryString {
|
export interface HttpQueryString {
|
||||||
[index:string]:string
|
[index:string]:any
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,9 @@
|
||||||
|
/// <reference path="HttpResponseHandler.ts" />
|
||||||
|
/// <reference path="../GenericRequest.ts" />
|
||||||
/// <reference path="../Transport/TransportConstructor.ts" />
|
/// <reference path="../Transport/TransportConstructor.ts" />
|
||||||
/// <reference path="../Transport/GenericTransport.ts" />
|
/// <reference path="../Transport/GenericTransport.ts" />
|
||||||
/// <reference path="../Transport/TransportChooser.ts" />
|
/// <reference path="../Transport/TransportChooser.ts" />
|
||||||
|
|
||||||
//TODO add support for IE8-9 CORS via XDomain
|
|
||||||
//TODO better error handling, ala exceptions
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace Typertext
|
* @namespace Typertext
|
||||||
* @module Http
|
* @module Http
|
||||||
|
|
|
@ -79,7 +79,22 @@ module Typertext.Http {
|
||||||
var temp:string;
|
var temp:string;
|
||||||
|
|
||||||
for (temp in data) {
|
for (temp in data) {
|
||||||
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(data[temp]) + "&";
|
var cur = data[temp];
|
||||||
|
|
||||||
|
if (cur instanceof Array) {
|
||||||
|
for (var i = 0; i < cur.length; i++) {
|
||||||
|
if (typeof cur[i] !== "string") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(cur[i]) + "&";
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof cur === "string") {
|
||||||
|
rs += encodeURIComponent(temp) + "=" + encodeURIComponent(cur) + "&";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rs.slice(0, -1);
|
return rs.slice(0, -1);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/terribleplan/Typertext.git"
|
"url": "https://github.com/terribleplan/Typertext.git"
|
||||||
},
|
},
|
||||||
"version": "0.8.1",
|
"version": "0.8.2",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"grunt": "~0.4.2",
|
"grunt": "~0.4.2",
|
||||||
"grunt-cli": "~0.1.13",
|
"grunt-cli": "~0.1.13",
|
||||||
|
|
|
@ -209,6 +209,15 @@ describe("Typertext.Http.HttpUrl", function () {
|
||||||
|
|
||||||
expect(actualOutput).toEqual(expectedOutput);
|
expect(actualOutput).toEqual(expectedOutput);
|
||||||
});
|
});
|
||||||
|
it("encodes a key with an array value", function () {
|
||||||
|
var input = {
|
||||||
|
"foo": ["bar", "fizz", "buzz"]
|
||||||
|
},
|
||||||
|
expectedOutput = "foo=bar&foo=fizz&foo=buzz",
|
||||||
|
actualOutput = Typertext.Http.HttpUrl.UrlEncodeObject(input);
|
||||||
|
|
||||||
|
expect(actualOutput).toEqual(expectedOutput);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("UrlDecodeObject", function () {
|
describe("UrlDecodeObject", function () {
|
||||||
|
|
Reference in New Issue