PageSourceSearch

https://archive.scenicnh.com/js/BS/1788533357/0.8.2/BS.com.HTTP.js

js scenicnh.com collected 2026-10-02 10:21:12 UTC 3,916 bytes, 157 lines download raw bytes

1/*!\brief	HTTP class that fetches a URL and executes the specified
2 *		CustomEvent with the resulting text.  Supports request queue.
3 */
4BS.com.HTTP = function ()
5{
6	var x = null;
7
8	try { x = new ActiveXObject('Msxml2.XMLHTTP'); }
9	catch (e) {
10		try { x = new ActiveXObject('Microsoft.XMLHTTP'); }
11		catch (e2) { }
12	}
13
14	if (!x && typeof XMLHttpRequest != 'undefined')
15		x = new XMLHttpRequest();
16
17	if (!x) throw 'missing XMLHttpRequest';
18
19	this.http = x;
20
21	this.cbT = BS.utl.func.bind(this._parseCB, this);
22
23	this.busy = false;
24	this.reqA = [];
25	this.hA = [];
26
27	this.mm = new BS.com.Delete;
28	this.openE = this.mm.ceNew('openE', this);
29	this.openE.addCB(this._openCB);
30};
31
32BS.com.HTTP.prototype = {
33	CT:		'application/x-www-form-urlencoded; charset=utf-8',
34
35	_delete: function ()
36	{
37		delete this.http.onreadystatechange;
38		this.mm._delete();
39		this.cbT = this.http = null;
40	},
41
42	/*!\brief	Execute CustomEvent and adjust queue.  The CustomEvent
43	 *		args array will contain the following:
44	 *		args[0]		response
45	 *		args[1]		request URL
46	 *		args[2]		POST array (optional)
47	 *		args[3]		data
48	 */
49	_execCE: function (d)
50	{
51		var			t = this.reqA[0];
52
53		try { t[3].exec(d, t[1], t[2], t[4]); }
54		catch (e) { var eE = e; }
55
56		this.reqA.shift();
57
58		if (this.reqA.length) this.openE.setTimeout(0);
59		else this.busy = false;
60
61		if (typeof eE != 'undefined') throw eE;
62	},
63
64	/*!\brief	Callback that executes CustomEvent.
65	 * \param	s		synchronous (default false)
66	 * \note	s === true (distinguishes between event as argument)
67	 */
68	_parseCB: function (s)
69	{
70		if (!this || !this.http || this.http.readyState != 4) return;
71
72		if (!this.http.responseText) throw 'Text missing error';
73
74		if (s === true) return this.http.responseText;
75		this._execCE(this.http.responseText);
76	},
77
78	/*!\brief	Queue AJAX request and initiate if not busy
79	 * \param	method		request method
80	 * \param	url		request URL
81	 * \param	p		POST array (optional)
82	 * \param	ce		CustomEvent
83	 * \param	d		data (optional)
84	 */
85	_queue: function (method, url, p, ce, d)
86	{
87		this.reqA.push([method, url, p, ce, d]);
88		if (!this.busy) this._openCB();
89	},
90
91	/*!\brief	Callback that opens next item in queue. */
92	_openCB: function ()
93	{
94		var t = this.reqA[0];
95		this._open(t[0], t[1], t[2]);
96	},
97
98	/*!\brief	Open AJAX connection based on request queue.
99	 * \param	method		request method
100	 * \param	url		request URL
101	 * \param	p		POST array (optional)
102	 * \param	s		synchronous (default false)
103	 */
104	_open: function (method, url, p, s)
105	{
106		this.busy = true;
107		this.http.open(method, url, !s);
108		if (!s) this.http.onreadystatechange = this.cbT;
109
110		if (p) this.http.setRequestHeader('Content-Type', this.CT);
111
112		for (var i=0, l=this.hA.length; i<l; i++)
113			this.http.setRequestHeader(this.hA[i][0],
114						   this.hA[i][1]);
115
116		this.http.send(p ? BS.utl.array.urlencode(p) : null);
117
118		if (s) return this._parseCB(s);
119	},
120
121	/*!\brief	Open GET connection to URL and execute CustomEvent.
122	 * \param	url		URL
123	 * \param	ce		CustomEvent
124	 * \param	d		data (optional)
125	 */
126	get: function (url, ce, d) { this._queue('GET', url, null, ce, d); },
127
128	/*!\brief	Open POST connection to URL and execute CustomEvent.
129	 * \param	url		URL
130	 * \param	p		POST array
131	 * \param	ce		CustomEvent
132	 * \param	d		data (optional)
133	 */
134	post: function (url, p, ce, d) { this._queue('POST', url, p, ce, d); },
135
136	/*!\brief	Open wrapper in synchronous mode.
137	 * \param	method		request method
138	 * \param	url		request URL
139	 * \param	p		POST array (optional)
140	 */
141	_openS: function (method, url, p)
142	{
143		if (this.busy) throw 'AssertErr BS.com.HTTP.busy';
144		return this._open(method, url, p, true);
145	},
146
147	/*!\brief	Return synchronous GET from URL.
148	 * \param	url		URL
149	 */
150	getS: function (url) { return this._openS('GET', url); },
151
152	/*!\brief	Return synchronous POST from URL.
153	 * \param	url		URL
154	 * \param	p		POST array
155	 */
156	postS: function (url, p) { return this._openS('POST', url, p); }
157};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.