Home

# Class goog.net.ChannelRequest

Creates a ChannelRequest object which encapsulates a request to the server. A new ChannelRequest is created for each request to the server.

Instance Method Summary
| `cancel()` Cancels the request no matter what the underlying transport is.
| `cancelWatchDogTimer_()` Cancels the watchdog timer if it has been started.
| `cleanup_()` Cleans up the objects used to make the request. This function is idempotent.
| `decodeNextChunks_(number readyState, string responseText)` Decodes the next set of available chunks in the response.
| `dispatchFailure_()` Notifies the channel that this request failed.
| `ensureWatchDogTimer_()` Ensures that there is watchdog timeout which is used to ensure that the connection completes in time.
| `getLastError() ⇒ ?goog.net.ChannelRequest.Error` If the request was not successful, returns the reason.
| `getLastStatusCode() ⇒ number` Returns the status code of the last request.

`getNextChunk_(string responseText) ⇒ (Object|null|string)`

Returns the next chunk of a chunk-encoded response. This is not standard HTTP chunked encoding because browsers don't expose the chunk boundaries to the application through XMLHTTP. So we have an additional chunk encoding at the application level that lets us tell where the beginning and end of individual responses are so that we can only try to eval a complete JS array. The encoding is the size of the chunk encoded as a decimal string followed by a newline followed by the data.

| `getPostData() ⇒ ?string` Returns the data for a post, if this request is a post.
| `getRequestId() ⇒ (number|string|undefined)` Returns the request id for this request. Each request has a unique request id and the request IDs are a sequential increasing count.
| `getRequestStartTime() ⇒ ?number` Returns the time that the request started, if it has started.
| `getSessionId() ⇒ (string|undefined)` Returns the session id for this channel.
| `getSuccess() ⇒ boolean` Indicates whether the request was successful. Only valid after the handler is called to indicate completion of the request.
| `handleTimeout_()` Called when the request has actually timed out. Will cleanup and notify the channel of the failure.
| `imgTagGet_()` Starts the IMG request.
| `onTridentDoneAsync_(boolean successful)` Callback from the Trident htmlfile ActiveX control for when the request is complete
| `onTridentDone_(boolean successful)` Callback from the Trident htmlfile ActiveX control for when the request is complete
| `onTridentRpcMessageAsync_(string msg)` Callback from the Trident htmlfile ActiveX control for when a new message is received.
| `onTridentRpcMessage_(string msg)` Callback from the Trident htmlfile ActiveX control for when a new message is received.
| `onWatchDogTimeout_()` Called when the watchdog timer is triggered. It also handles a case where it is called too early which we suspect may be happening sometimes (not sure why)
| `onXmlHttpReadyStateChanged_()` Called by the readystate handler for XMLHTTP requests.
| `pollResponse_()` Polls the response for new data.
| `safeOnRequestData_(string data)` Helper to call the callback's onRequestData, which catches any exception and cleans up the request.
| `sendUsingImgTag(?goog.Uri uri)` Uses an IMG tag to send an HTTP get to the server. This is only currently used to terminate the connection, as an IMG tag is the most reliable way to send something to the server while the page is getting torn down.
| `sendXmlHttp_(?string hostPrefix)` Sends a request via XMLHTTP according to the current state of the ChannelRequest object.
| `setExtraHeaders(?Object extraHeaders)` Sets extra HTTP headers to add to all the requests sent to the server.
| `setTimeout(number timeout)` Sets the timeout for a request
| `startPolling_()` Starts a polling interval for changes to responseText of the XMLHttpRequest, for browsers that don't fire onreadystatechange as data comes in incrementally.
| `startWatchDogTimer_(number time)` Starts the watchdog timer which is used to ensure that the connection completes in time.
| `stopPolling_()` Stops the polling interval for changes to responseText.
| `tridentGet(?goog.Uri uri, boolean usingSecondaryDomain)` Uses the Trident htmlfile ActiveX control to send a GET request in IE. This is the innovation discovered that lets us get intermediate results in Internet Explorer. Thanks to http://go/kev
| `tridentGet_(boolean usingSecondaryDomain)` Starts the Trident request.
| `xmlHttpGet(?goog.Uri uri, boolean decodeChunks, ?string hostPrefix, boolean= opt_noClose)` Uses XMLHTTP to send an HTTP GET to the server.
| `xmlHttpHandler_(?goog.events.Event e)` XmlHttp handler
| `xmlHttpPost(?goog.Uri uri, string postData, boolean decodeChunks)` Uses XMLHTTP to send an HTTP POST to the server.

Static Method Summary
| `errorStringFromCode(?goog.net.ChannelRequest.Error errorCode, number statusCode) ⇒ string` Returns a useful error string for debugging based on the specified error code.
| `supportsXhrStreaming() ⇒ boolean` Returns whether XHR streaming is supported on this browser. If XHR streaming is not supported, we will try to use an ActiveXObject to create a Forever IFrame.