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,
|
https = 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module Typertext.Http {
|
||||||
|
interface HttpQueryString {
|
||||||
|
[index: string]: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module Typertext.Http {
|
declare module Typertext.Http {
|
||||||
class HttpRequest implements GenericRequest<HttpResponseHandler> {
|
class HttpRequest implements GenericRequest<HttpResponseHandler> {
|
||||||
private static parseHeaderString(headerStr);
|
private static parseHeaderString(headerStr);
|
||||||
|
@ -98,12 +103,13 @@ declare module Typertext.Http {
|
||||||
private _Protocol;
|
private _Protocol;
|
||||||
private _QueryString;
|
private _QueryString;
|
||||||
static DefaultPort(protocol: HttpProtocol): number;
|
static DefaultPort(protocol: HttpProtocol): number;
|
||||||
static EncodeQueryString(query: {
|
static FromUrl(location: string): HttpUrl;
|
||||||
[index: string]: string;
|
static DecodeQueryString(queryString: string): HttpQueryString;
|
||||||
}): string;
|
static EncodeQueryString(query: HttpQueryString): string;
|
||||||
static URLEncodeObject(data: {
|
static URLEncodeObject(data: {
|
||||||
[index: string]: string;
|
[index: string]: string;
|
||||||
}): string;
|
}): string;
|
||||||
|
private static splitString(input, separator, limit?);
|
||||||
constructor(domain: string, protocol?: HttpProtocol, path?: string, queryString?: {
|
constructor(domain: string, protocol?: HttpProtocol, path?: string, queryString?: {
|
||||||
[index: string]: string;
|
[index: string]: string;
|
||||||
}, port?: number);
|
}, port?: number);
|
||||||
|
|
|
@ -224,6 +224,36 @@ var Typertext;
|
||||||
return ((protocol == 0 /* http */) ? 80 : 443);
|
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) {
|
HttpUrl.EncodeQueryString = function (query) {
|
||||||
var rs = "?" + HttpUrl.URLEncodeObject(query);
|
var rs = "?" + HttpUrl.URLEncodeObject(query);
|
||||||
return ((rs.length == 1) ? "" : rs);
|
return ((rs.length == 1) ? "" : rs);
|
||||||
|
@ -240,6 +270,18 @@ var Typertext;
|
||||||
return rs.slice(0, -1);
|
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 () {
|
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);
|
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 {
|
public static DecodeQueryString(queryString:string):HttpQueryString {
|
||||||
var returnValue = {};
|
var returnValue:HttpQueryString = {};
|
||||||
if (queryString.length == 0 || queryString == "?") {
|
if (queryString.length == 0 || queryString == "?") {
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue