Simulation of HTTP responses using HTTP Filter Plugin on Symbian
Article Metadata
Code Example
Tested with
Compatibility
Article
Description
The HTTP Filter Plugins sit between the HTTP Framework and the client and are loaded whenever there is a HTTP Session on the device. The filter receives all the transaction events that take place between the client and the HTTP framework and can be used to manipulate them. Thus it's also possible to even stop a transaction and send a dummy HTTP response to the client.
Solution
A HTTP Transaction encapsulates a HTTP request and a response. The code snippet given below shows how to cancel the HTTP request received from the client.
iTransaction = aTransaction; //take a copy of the transaction
aTransaction.Cancel(iFilterHandle); //cancel the transaction
The transaction's response object can then be set with our own headers and body and the function RHTTPTransaction::SendEventL() is used to send the response events. The code snippet given below illustrates this:
RHTTPResponse resp = iTransaction.Response();
//Sending response headers
RHTTPHeaders hdrs = resp.GetHeaderCollection();
RStringF valStr = iSession.StringPool().OpenFStringL( KContenttype );
THTTPHdrVal val( valStr );
hdrs.SetFieldL( iSession.StringPool().StringF( HTTP::EContentType,
RHTTPSession::GetTable()), val );
RStringF okStr = iSession.StringPool().OpenFStringL(KOk);
iTransaction.Response().SetStatusCode(200);
iTransaction.Response().SetStatusText(okStr);
iTransaction.SendEventL(THTTPEvent::EGotResponseHeaders, THTTPEvent::EIncoming, iFilterHandle);
valStr.Close();
okStr.Close();
Sending response body
resp.SetBody(*this);
iTransaction.SendEventL(THTTPEvent::EGotResponseBodyData, THTTPEvent::EIncoming, iFilterHandle);
Sending response complete event
iTransaction.SendEventL(THTTPEvent::EResponseComplete, THTTPEvent::EIncoming, iFilterHandle);
Sending transaction succeed event
iTransaction.SendEventL(THTTPEvent::ESucceeded, THTTPEvent::EIncoming, iFilterHandle);
Please note that the events must be sent in the above sequence for the transaction to succeed.
NOTE: HTTP filters require an extensive set of capabilities, including NetworkControl. See the below example application for details.

