21 #include "httpcachemanager.h" |
21 #include "httpcachemanager.h" |
22 #include "HttpCacheDataSupplier.h" |
22 #include "HttpCacheDataSupplier.h" |
23 #include "HttpConnection.h" |
23 #include "HttpConnection.h" |
24 #include "ResourceLoaderDelegate.h" |
24 #include "ResourceLoaderDelegate.h" |
25 #include "StaticObjectsContainer.h" |
25 #include "StaticObjectsContainer.h" |
|
26 #include "HttpDlConnection.h" |
26 |
27 |
27 #include <http/RHTTPTransaction.h> |
28 #include <http/RHTTPTransaction.h> |
28 #include <http/mhttpdatasupplier.h> |
29 #include <http/mhttpdatasupplier.h> |
29 #include <http/rhttpsession.h> |
30 #include <http/rhttpsession.h> |
30 #include <httperr.h> |
31 #include <httperr.h> |
225 // ----------------------------------------------------------------------------- |
226 // ----------------------------------------------------------------------------- |
226 // |
227 // |
227 void CHttpCacheSupply::SupplyResponseL() |
228 void CHttpCacheSupply::SupplyResponseL() |
228 { |
229 { |
229 RHTTPTransaction* trans = m_httpTransaction->HttpTransaction(); |
230 RHTTPTransaction* trans = m_httpTransaction->HttpTransaction(); |
|
231 if(!trans && m_dlTransaction){ |
|
232 SupplyToDownloadManager(); |
|
233 } |
|
234 else{ |
230 // |
235 // |
231 switch( m_reponseState ) |
236 switch( m_reponseState ) |
232 { |
237 { |
233 case THTTPEvent::EGotResponseHeaders: |
238 case THTTPEvent::EGotResponseHeaders: |
234 { |
239 { |
235 m_failed = EFalse; |
240 m_failed = EFalse; |
236 if( m_cacheManager->RequestHeadersL( *trans, m_cacheEntry ) == KErrNone ) { |
241 if( m_cacheManager->RequestHeadersL( *trans, m_cacheEntry ) == KErrNone ) { |
237 // |
242 // |
238 trans->Response().SetStatusCode( HTTPStatus::EOk ); |
243 trans->Response().SetStatusCode( HTTPStatus::EOk ); |
239 // |
244 // |
240 m_httpTransaction->MHFRunL( THTTPEvent::EGotResponseHeaders ); |
245 m_httpTransaction->MHFRunL( THTTPEvent::EGotResponseHeaders ); |
241 // move to the next state |
246 // move to the next state |
242 m_reponseState = THTTPEvent::EGotResponseBodyData; |
247 m_reponseState = THTTPEvent::EGotResponseBodyData; |
|
248 } |
|
249 else { |
|
250 // move to the next state |
|
251 m_failed = ETrue; |
|
252 // move to the next state |
|
253 m_reponseState = THTTPEvent::EResponseComplete; |
|
254 } |
|
255 break; |
243 } |
256 } |
244 else { |
257 case THTTPEvent::EGotResponseBodyData: |
245 // move to the next state |
258 { |
246 m_failed = ETrue; |
259 SendBodyL(); |
247 // move to the next state |
260 // move to the next state |
248 m_reponseState = THTTPEvent::EResponseComplete; |
261 m_reponseState = THTTPEvent::EResponseComplete; |
|
262 break; |
249 } |
263 } |
|
264 case THTTPEvent::EResponseComplete: |
|
265 { |
|
266 m_httpTransaction->MHFRunL(THTTPEvent::EResponseComplete ); |
|
267 // move to the next state |
|
268 m_reponseState = !m_failed ? THTTPEvent::ESucceeded : THTTPEvent::EFailed; |
|
269 break; |
|
270 } |
|
271 case THTTPEvent::ESucceeded: |
|
272 { |
|
273 // move to the next state |
|
274 m_reponseState = THTTPEvent::EClosed; |
|
275 // cancel timer |
|
276 m_responseTimer->Cancel(); |
|
277 // |
|
278 m_httpTransaction->MHFRunL(THTTPEvent::ESucceeded ); |
|
279 // this obj is destroyed at this point |
|
280 break; |
|
281 } |
|
282 case THTTPEvent::EFailed: |
|
283 { |
|
284 // move to the next state |
|
285 m_reponseState = THTTPEvent::EClosed; |
|
286 // cancel timer |
|
287 m_responseTimer->Cancel(); |
|
288 m_httpTransaction->MHFRunL(THTTPEvent::EFailed ); |
|
289 // this obj is destroyed at this point |
|
290 break; |
|
291 } |
|
292 default: |
250 break; |
293 break; |
251 } |
294 } |
252 case THTTPEvent::EGotResponseBodyData: |
|
253 { |
|
254 SendBodyL(); |
|
255 // move to the next state |
|
256 m_reponseState = THTTPEvent::EResponseComplete; |
|
257 break; |
|
258 } |
|
259 case THTTPEvent::EResponseComplete: |
|
260 { |
|
261 m_httpTransaction->MHFRunL(THTTPEvent::EResponseComplete ); |
|
262 // move to the next state |
|
263 m_reponseState = !m_failed ? THTTPEvent::ESucceeded : THTTPEvent::EFailed; |
|
264 break; |
|
265 } |
|
266 case THTTPEvent::ESucceeded: |
|
267 { |
|
268 // move to the next state |
|
269 m_reponseState = THTTPEvent::EClosed; |
|
270 // cancel timer |
|
271 m_responseTimer->Cancel(); |
|
272 // |
|
273 m_httpTransaction->MHFRunL(THTTPEvent::ESucceeded ); |
|
274 // this obj is destroyed at this point |
|
275 break; |
|
276 } |
|
277 case THTTPEvent::EFailed: |
|
278 { |
|
279 // move to the next state |
|
280 m_reponseState = THTTPEvent::EClosed; |
|
281 // cancel timer |
|
282 m_responseTimer->Cancel(); |
|
283 m_httpTransaction->MHFRunL(THTTPEvent::EFailed ); |
|
284 // this obj is destroyed at this point |
|
285 break; |
|
286 } |
|
287 default: |
|
288 break; |
|
289 } |
295 } |
290 } |
296 } |
291 |
297 |
292 // ----------------------------------------------------------------------------- |
298 // ----------------------------------------------------------------------------- |
293 // CHttpCacheSupply::SendBodyL |
299 // CHttpCacheSupply::SendBodyL |
334 { |
340 { |
335 if( m_responseTimer && !m_responseTimer->IsActive() ) |
341 if( m_responseTimer && !m_responseTimer->IsActive() ) |
336 m_responseTimer->Start( KResponseTimeout, KResponseTimeout, TCallBack( &ResponseCallbackL, this ) ); |
342 m_responseTimer->Start( KResponseTimeout, KResponseTimeout, TCallBack( &ResponseCallbackL, this ) ); |
337 } |
343 } |
338 |
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CHttpCacheSupply::SetDownloadTransaction |
|
347 //------------------------------------------------------------------------------ |
|
348 void CHttpCacheSupply::SetDownloadTransaction(RHTTPTransaction* transaction) |
|
349 { |
|
350 m_dlTransaction = transaction; |
|
351 } |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CHttpCacheSupply::SupplyToDownloadManager |
|
355 //------------------------------------------------------------------------------ |
|
356 void CHttpCacheSupply::SupplyToDownloadManager() |
|
357 { |
|
358 RHTTPTransactionPropertySet propSet = m_dlTransaction->PropertySet(); |
|
359 RStringPool strPool = m_dlTransaction->Session().StringPool(); |
|
360 THTTPHdrVal callback; |
|
361 RStringF downloadPropStr; |
|
362 HttpDlConnection* httpDlConnection = HttpDlConnection::dlConnectionFromTransaction(*m_dlTransaction); |
|
363 if (httpDlConnection) { |
|
364 RStringF downloadPropStr = strPool.OpenFStringL( _L8( "TransactionCallback" ) ); |
|
365 if( propSet.Property( downloadPropStr, callback ) ){ |
|
366 MHTTPTransactionCallback* callbackPtr = REINTERPRET_CAST( MHTTPTransactionCallback*, callback.Int() ); |
|
367 if( callbackPtr ){ |
|
368 switch( m_reponseState ) |
|
369 { |
|
370 case THTTPEvent::EGotResponseHeaders: |
|
371 { |
|
372 m_failed = EFalse; |
|
373 if( m_cacheManager->RequestHeadersL( *m_dlTransaction, m_cacheEntry ) == KErrNone ) { |
|
374 // |
|
375 m_dlTransaction->Response().SetStatusCode( HTTPStatus::EOk ); |
|
376 // |
|
377 callbackPtr->MHFRunL( *m_dlTransaction,THTTPEvent::EGotResponseHeaders ); |
|
378 // move to the next state |
|
379 m_reponseState = THTTPEvent::EGotResponseBodyData; |
|
380 } |
|
381 else { |
|
382 // move to the next state |
|
383 m_failed = ETrue; |
|
384 // move to the next state |
|
385 m_reponseState = THTTPEvent::EResponseComplete; |
|
386 } |
|
387 break; |
|
388 } |
|
389 case THTTPEvent::EGotResponseBodyData: |
|
390 { |
|
391 // |
|
392 TBool lastChunk; |
|
393 // currently it is always the last chunk |
|
394 HBufC8* body = m_cacheManager->RequestNextChunkL( *m_dlTransaction, lastChunk, m_cacheEntry ); |
|
395 if( body ) { |
|
396 CleanupStack::PushL( body ); |
|
397 // create datasupplier and attach it to the transaction |
|
398 if( !m_dataSupplier ) |
|
399 m_dataSupplier = CHttpCacheDataSupplier::NewL( body ); |
|
400 m_dlTransaction->Response().SetBody( *m_dataSupplier ); |
|
401 CleanupStack::Pop(); // body |
|
402 callbackPtr->MHFRunL(*m_dlTransaction,THTTPEvent::EGotResponseBodyData); |
|
403 } |
|
404 else { |
|
405 // move to the next state |
|
406 m_failed = ETrue; |
|
407 } |
|
408 // move to the next state |
|
409 m_reponseState = THTTPEvent::EResponseComplete; |
|
410 break; |
|
411 } |
|
412 case THTTPEvent::EResponseComplete: |
|
413 { |
|
414 callbackPtr->MHFRunL(*m_dlTransaction, THTTPEvent::EResponseComplete ); |
|
415 // move to the next state |
|
416 m_reponseState = !m_failed ? THTTPEvent::ESucceeded : THTTPEvent::EFailed; |
|
417 break; |
|
418 } |
|
419 case THTTPEvent::ESucceeded: |
|
420 { |
|
421 // move to the next state |
|
422 m_reponseState = THTTPEvent::EClosed; |
|
423 // cancel timer |
|
424 m_responseTimer->Cancel(); |
|
425 // |
|
426 callbackPtr->MHFRunL(*m_dlTransaction, THTTPEvent::ESucceeded ); |
|
427 // this obj is destroyed at this point |
|
428 break; |
|
429 } |
|
430 case THTTPEvent::EFailed: |
|
431 { |
|
432 // move to the next state |
|
433 m_reponseState = THTTPEvent::EClosed; |
|
434 // cancel timer |
|
435 m_responseTimer->Cancel(); |
|
436 callbackPtr->MHFRunL(*m_dlTransaction, THTTPEvent::EFailed ); |
|
437 // this obj is destroyed at this point |
|
438 break; |
|
439 } |
|
440 default: |
|
441 break; |
|
442 } |
|
443 } |
|
444 } |
|
445 } |
|
446 } |
339 // End of File |
447 // End of File |