|
||
Transactions that have been submitted can be cancelled at any time using
RHTTPTransaction::Cancel()
. When this is done, no further
events are received for that transaction as originally submitted.
An example from HTTPEXAMPLECLIENT
:
void CHttpEventHandler::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
switch (aEvent.iStatus)
{
case THTTPEvent::EGotResponseHeaders:
{
...
// If we're cancelling, do it now...
if (cancelling)
{
iUtils.Test().Printf(_L("\nTransaction Cancelled\n"));
aTransaction.Close();
CActiveScheduler::Stop();
}
...
In this case, the transaction is left in a cancelled state. The client now has the option to modify the request if required, 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 after cancellation, it is exactly as if it had been submitted for the first time. For example, no preferential treatment is given to it in terms of time-to-service.
The process of cancelling in an MHFRunL()
method, modifying
the request, and resubmitting is common in filter design. See
Filters for more information.
If the client wants to abort a transaction, it can 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. Reusing a closed transaction causes the client to behave unpredictably.