Transactions that have been submitted may be cancelled at any time,
using RHTTPTransaction::Cancel()
. When this is done, no
further events will be received for that transaction as originally submitted.
An example from HTTPEXAMPLECLIENT
:
void CHttpEventHandler::MHFRunL(RHTTPTransaction aTransaction, THTTPEvent aEvent)
{
switch (aEvent.iStatus)
{
case THTTPEvent::EGotResponseHeaders:
{
...
// If we're cancelling, do it now...
if (cancelling)
{
aTransaction.Cancel();
Printf(_L("\nTransaction Cancelled\n"));
...
}
...
In this case, the transaction is left in a cancelled state. The client has the option, at this time, to modify the request if desired, and to resubmit the transaction. This might be done, for example, if the HTTP server has indicated with a 400-series status code that there was a client error.
When a transaction is resubmitted following cancellation, it is exactly as if it had been submitted for the first time: for example, no preferential treatment as given it in terms of time-to-service.
The practice of cancelling in an MHFRunL()
method,
modifying the request, and resubmitting is common in filter design. See
Filters for more information.
If the client wishes to abort a transaction, it may close the
transaction using RHTTPTransaction::Close()
. It is not
necessary to cancel first, since a Cancel()
is done automatically
during the Close()
. Closing the transaction enables HTTP to clean
up resources allocated during the execution of that transaction.
Once a transaction is closed, it must not be reused. Doing so will cause the client to panic, or behave unpredictably.