Build and define type of intermediary
This commit is contained in:
parent
15dd2b9cf1
commit
c63007f3fd
12
build/typertext.d.ts
vendored
12
build/typertext.d.ts
vendored
|
@ -62,6 +62,11 @@ declare module Typertext.Http {
|
|||
https = 1,
|
||||
}
|
||||
}
|
||||
declare module Typertext.Http {
|
||||
interface HttpQueryString {
|
||||
[index: string]: string;
|
||||
}
|
||||
}
|
||||
declare module Typertext.Http {
|
||||
class HttpRequest implements GenericRequest<HttpResponseHandler> {
|
||||
private static parseHeaderString(headerStr);
|
||||
|
@ -98,12 +103,13 @@ declare module Typertext.Http {
|
|||
private _Protocol;
|
||||
private _QueryString;
|
||||
static DefaultPort(protocol: HttpProtocol): number;
|
||||
static EncodeQueryString(query: {
|
||||
[index: string]: string;
|
||||
}): string;
|
||||
static FromUrl(location: string): HttpUrl;
|
||||
static DecodeQueryString(queryString: string): HttpQueryString;
|
||||
static EncodeQueryString(query: HttpQueryString): string;
|
||||
static URLEncodeObject(data: {
|
||||
[index: string]: string;
|
||||
}): string;
|
||||
private static splitString(input, separator, limit?);
|
||||
constructor(domain: string, protocol?: HttpProtocol, path?: string, queryString?: {
|
||||
[index: string]: string;
|
||||
}, port?: number);
|
||||
|
|
|
@ -224,6 +224,36 @@ var Typertext;
|
|||
return ((protocol == 0 /* http */) ? 80 : 443);
|
||||
};
|
||||
|
||||
HttpUrl.FromUrl = function (location) {
|
||||
var l = document.createElement("a");
|
||||
l.href = location;
|
||||
return new HttpUrl(l.hostname, Typertext.Http.HttpProtocol[l.protocol], l.pathname, HttpUrl.DecodeQueryString(l.search));
|
||||
};
|
||||
|
||||
HttpUrl.DecodeQueryString = function (queryString) {
|
||||
var returnValue = {};
|
||||
if (queryString.length == 0 || queryString == "?") {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
if (queryString.indexOf("?") == 0) {
|
||||
queryString = queryString.substring(1);
|
||||
}
|
||||
|
||||
var params = HttpUrl.splitString(queryString, "&");
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var param = HttpUrl.splitString(params[i], "=", 2);
|
||||
if (param.length == 1) {
|
||||
returnValue[param[0]] = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
returnValue[param[0]] = param[1];
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
HttpUrl.EncodeQueryString = function (query) {
|
||||
var rs = "?" + HttpUrl.URLEncodeObject(query);
|
||||
return ((rs.length == 1) ? "" : rs);
|
||||
|
@ -240,6 +270,18 @@ var Typertext;
|
|||
return rs.slice(0, -1);
|
||||
};
|
||||
|
||||
HttpUrl.splitString = function (input, separator, limit) {
|
||||
if (typeof limit === "undefined") { limit = 0; }
|
||||
limit++;
|
||||
var chunks = input.split(separator);
|
||||
if (limit > 0 && chunks.length > limit) {
|
||||
var ret = chunks.splice(0, limit);
|
||||
ret.push(chunks.join(separator));
|
||||
return ret;
|
||||
}
|
||||
return chunks;
|
||||
};
|
||||
|
||||
HttpUrl.prototype.ToString = function () {
|
||||
return Typertext.Http.HttpProtocol[this._Protocol] + "://" + this._Domain + ((this._Port == HttpUrl.DefaultPort(this._Protocol)) ? "" : ":" + this._Port) + this._Path + HttpUrl.EncodeQueryString(this._QueryString);
|
||||
};
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -19,7 +19,7 @@ module Typertext.Http {
|
|||
}
|
||||
|
||||
public static DecodeQueryString(queryString:string):HttpQueryString {
|
||||
var returnValue = {};
|
||||
var returnValue:HttpQueryString = {};
|
||||
if (queryString.length == 0 || queryString == "?") {
|
||||
return returnValue;
|
||||
}
|
||||
|
|
Reference in a new issue