Namespaces
Variants
Actions

Simulation of HTTP responses using HTTP Filter Plugin on Symbian

Jump to: navigation, search
Article Metadata

Code Example
Source file: Media:Filter.zip

Tested with
Devices(s): Tested on Nokia N95, N78

Compatibility
Platform(s): S60 3rd Edition and later

Article
Keywords: RHTTPSession, RHTTPFilterCollection
Created: User:TechnicalWriter2 (12 Jun 2009)
Last edited: hamishwillee (17 Sep 2012)

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.

Example Application

File:Filter.zip

This page was last modified on 17 September 2012, at 10:32.
181 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved