My favorites | Sign in
Project Logo
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">

<!--
Copyright 2007, Google Inc.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of Google Inc. nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<html>
<head>
<title>HttpRequest API</title>
<link rel="stylesheet" type="text/css" href="gears.css" />
</head>

<body>

<h1>HttpRequest API</h1>

<div id="pagecontent">

<p>The HttpRequest API implements a subset of the
<a href="http://www.w3.org/TR/XMLHttpRequest/">W3C XmlHttpRequest
specification</a>, and makes it available in both workers and the
main HTML page.</p>

<h3>Contents</h3>
<ol class="toc">
<li><a href="#overview">Overview</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#interfaces">Interfaces</a>
<ol>
<li><a href="#HttpRequest">HttpRequest</a></li>
<li><a href="#HttpRequestUpload">HttpRequestUpload</a></li>
<li><a href="#ProgressEvent">ProgressEvent</a></li>
</ol>
</li>
</ol>

<a name="overview"></a><h2>Overview</h2>
<p>Since the browser's XmlHttpRequest object is not available in the context of
a worker, Gears provides its own HttpRequest object to fill that need. Gears HttpRequest
provides most of the features of XmlHttpRequest except for the ability to access the response
as an XML DOM object and the ability to send a request synchronously.
</p>
<h4>Permission</h4>

<p>Does not require user permission.</p>
<a name="example"></a><h2>Example</h2>

<pre><code>&lt;script type="text/javascript" src="<a href='tools.html#gears_init'>gears_init.js</a>"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
var request = google.gears.factory.create('beta.httprequest');
request.open('GET', '/index.html');
request.onreadystatechange = function() {
if (request.readyState == 4) {
console.write(request.responseText);
}
};
request.send();
&lt;/script&gt;</code></pre>


<h3 id="interfaces">Interfaces</h3>
<pre><code><a href="#HttpRequest" class="section">HttpRequest class</a>
void <b>open</b>(method, url)
void <b>setRequestHeader</b>(name, value)
void <b>send</b>([postData])
void <b>abort</b>()
string <b>getResponseHeader</b>(name)
string <b>getAllResponseHeaders</b>()
callback <b>onprogress</b>(progressEvent)
callback <b>onreadystatechange</b>()
readonly attribute int <b>readyState</b>
readonly attribute Blob <b>responseBlob</b>
readonly attribute string <b>responseText</b>
readonly attribute int <b>status</b>
readonly attribute string <b>statusText</b>
readonly attribute HttpRequestUpload <b>upload</b>
</code></pre>
<pre><code><a href="#HttpRequestUpload" class="section">HttpRequestUpload class</a>
callback <b>onprogress</b>(progressEvent)
</code></pre>
<pre><code><a href="#ProgressEvent" class="section">ProgressEvent class</a>
readonly attribute int <b>total</b>
readonly attribute int <b>loaded</b>
readonly attribute bool <b>lengthComputable</b>
</code></pre>


<br>
<a name="HttpRequest"></a>
<h2>HttpRequest class</h2>

<!-- ########## Methods ########## -->
<h3>Methods</h3>
<table>
<tr class="odd">
<th colspan="2"><div align="left"><code>abort()</code></div></th>
</tr>
<tr class="odd">
<td width="113">Return value: </td>
<td width="489" ><code>void</code></td>
</tr>
<tr class="odd">
<td>Description:</td>
<td class="odd">
Cancels the request.
</td>
</tr>
</table>
<table>
<tr class="odd">
<th colspan="2"><div align="left"><code>getAllResponseHeaders()</code></div></th>
</tr>
<tr class="odd">
<td width="113">Return value: </td>
<td width="489"><code>string</code></td>
</tr>
<tr class="odd">
<td>Description:</td>
<td class="odd">
Returns a string containing the entire set of HTTP headers in the server response.
</td>
</tr>
</table>
<table>
<tr class="odd">
<th colspan="2"><div align="left"><code>getResponseHeader(headerName)</code></div></th>
</tr>
<tr class="odd">
<td width="113">Return value: </td>
<td width="489"><code>string</code></td>
</tr>
<tr class="odd">
<td>Parameters:</td>
<td class="odd">
<code>headerName</code>
</td>
</tr>
<tr class="odd">
<td>Description:</td>
<td class="odd">
Returns the value of a specific HTTP header in the server response.
</td>
</tr>
</table>
<table>
<tr class="odd">
<th colspan="2"><div align="left"><code>open(method, url)</code></div></th>
</tr>
<tr class="odd">
<td width="113">Return value: </td>
<td width="489"><code>void</code></td>
</tr>
<tr class="odd">
<td>Parameters:</td>
<td class="odd">
<code>method</code><br/>
<code>url</code>
</td>
</tr>
<tr class="odd">
<td>Description:</td>
<td class="odd">
Specifies the method and URL of a request.
<p>The method parameter can have a value of "GET", "POST", "HEAD" or another HTTP method listed in the W3C specification.</p>
<p>The URL parameter may be either a relative or complete URL and must be from the same origin as the current context.</p>
</td>
</tr>
</table>
<table>
<tr class="odd">
<th colspan="2"><div align="left"><code>send([postData])</code></div></th>
</tr>
<tr class="odd">
<td width="113">Return value: </td>
<td width="489"><code>void</code></td>
</tr>
<tr class="odd">
<td>Parameters:</td>
<td class="odd">
<code>postData</code> - an optional string or Blob to be sent as the body of a POST or PUT request.<br/>
</td>
</tr>
<tr class="odd">
<td>Description:</td>
<td class="odd">
Sends the request.
</td>
</tr>
</table>
<table>
<tr class="odd">
<th colspan="2"><div align="left"><code>setRequestHeader(name, value)</code></div></th>
</tr>
<tr class="odd">
<td width="113">Return value: </td>
<td width="489"><code>void</code></td>
</tr>
<tr class="odd">
<td>Parameters:</td>
<td class="odd">
<code>name</code> - the HTTP header to set<br/>
<code>value</code> - the value of the header<br/>
</td>
</tr>
<tr class="odd">
<td>Description:</td>
<td class="odd">
Adds the header to the set of HTTP headers to be sent.
</td>
</tr>
</table>

<!-- ########## Events ########## -->
<h3>Event Handlers</h3>
<table>
<tr class="odd">
<th colspan="2">
<div align="left"><code>callback onprogress(progressEvent)</code></div>
</th>
</tr>
<tr class="odd">
<td width="113">Parameters: </td>
<td width="489">
<code>progressEvent</code> - A <a href="#ProgressEvent">ProgressEvent</a> object.
</td>
</tr>
<tr class="odd">
<td width="113">Description: </td>
<td width="489">
An event handler that fires as response data is downloaded.
</td>
</tr>
</table>
<table>
<tr class="odd">
<th colspan="2"><div align="left"><code>callback onreadystatechange()</code></div></th>
</tr>
<tr class="odd">
<td width="113">Description: </td>
<td width="489">An event handler that fires at every state change and repeatedly as new responseText data becomes available while the request is in the Interactive state.</td>
</tr>
</table>

<!-- ########## Attributes ########## -->
<h3>Attributes</h3>
<table>
<tr class="odd">
<th width="158">Attribute</th>
<th >Type</th>
<th >Description</th>
</tr>
<tr class="odd">
<td width="158"><strong>readyState</strong></td>
<td width="109" >readonly int</td>
<td width="432" > Returns the state of the object:
<table class="noborders">
<tr>
<td><strong>0</strong></td>
<td>Uninitialized</td>
</tr>
<tr>
<td><strong>1</strong></td>
<td>Open</td>
</tr>
<tr>
<td><strong>2</strong></td>
<td>Sent</td>
</tr>
<tr>
<td><strong>3</strong></td>
<td>Interactive</td>
</tr>
<tr>
<td><strong>4</strong></td>
<td>Complete</td>
</table>
</td>
</tr>
<tr class="odd">
<td><strong>responseBlob</strong></td>
<td class="" >readonly Blob</td>
<td class="" >Returns the response body as a Blob. This property can be read when the request is in the Complete state.</td>
</tr>
<tr class="odd">
<td><strong>responseText</strong></td>
<td class="" >readonly string </td>
<td class="" >Returns the response body as a string. This property can be read when the request is in the Interactive or Complete state.</td>
</tr>
<tr class="odd">
<td><strong>status</strong></td>
<td class="odd">readonly int</td>
<td class="odd">Returns the status as a number (e.g. 404 for "Not Found" or 200 for "OK"). This property can be read when the request is in the Interactive or Complete state.</td>
</tr>
<tr class="odd">
<td><strong>statusText</strong></td>
<td class="odd">readonly string </td>
<td class="odd">Returns the status as a string (e.g. "Not Found" or "OK"). This property can be read when the request is in the Interactive or Complete state.</td>
</tr>
<tr class="odd">
<td><strong>upload</strong></td>
<td class="odd">readonly Object</td>
<td class="odd">Returns an
<a href="#HttpRequestUpload">HttpRequestUpload</a> object for
accessing properties associated with POST or PUT data uploads.
</td>
</tr>
</table>

<!-- ########## Class Reference ########## -->

<br>
<a name="HttpRequestUpload"></a>
<h2>HttpRequestUpload class</h2>

<!-- ########## Events ########## -->
<h3>Event Handlers</h3>
<table>
<tr class="odd">
<th colspan="2">
<div align="left"><code>callback onprogress(progressEvent)</code></div>
</th>
</tr>
<tr class="odd">
<td width="113">Parameters: </td>
<td width="489">
<code>progressEvent</code> - A <a href="#ProgressEvent">ProgressEvent</a> object.
</td>
</tr>
<tr class="odd">
<td width="113">Description: </td>
<td width="489">
An event handler that fires as PUT or POST data is uploaded.
</td>
</tr>
</table>

<!-- ########## Class Reference ########## -->

<br>
<a name="ProgressEvent"></a>
<h2>ProgressEvent class</h2>

<!-- ########## Attributes ########## -->
<h3>Attributes</h3>
<table>
<tr class="odd">
<th width="158">Attribute</th>
<th >Type</th>
<th >Description</th>
</tr>
<tr class="odd">
<td><strong>total</strong></td>
<td class="" >readonly int</td>
<td class="" >
Returns the total number of bytes to be loaded.
Returns 0 if unknown (i.e. - lengthComputable is false).
</td>
</tr>
<tr class="odd">
<td><strong>loaded</strong></td>
<td class="" >readonly int</td>
<td class="" >Returns the total number of bytes currently loaded.</td>
</tr>
<tr class="odd">
<td><strong>lengthComputable</strong></td>
<td class="" >readonly bool</td>
<td class="" >
Returns true if the total number of bytes to be transferred is known.
</td>
</tr>
</table>


</div>
</body>
</html>
Show details Hide details

Change log

r2759 by gears.daemon on Aug 22, 2008   Diff
[Author: cprince]

More doc cleanup. No rush to push this.

PRESUBMIT=passed
R=michaeln
CC=gears-eng@googlegroups.com
DELTA=36  (11 added, 2 deleted, 23
changed)
OCL=8067089
SCL=8078398
Go to: 
Project members, sign in to write a code review

Older revisions

r2757 by gears.daemon on Aug 22, 2008   Diff
[Author: andreip]

Replace "module" with "API" in the
Gears documentation pages.

...
r2670 by gears.daemon on Aug 11, 2008   Diff
[Author: bgarcia]

Update HttpRequest API documentation.
Adding Upload & Blob support.

...
r1740 by gears.daemon on May 22, 2008   Diff
[Author: lisbakke]

Changed Docs; added which modules
cause Gears permission dialog
(LocalServer, Database, WorkerPool
...
All revisions of this file

File info

Size: 12683 bytes, 399 lines

File properties

svn:mime-type
text/html
Hosted by Google Code