Click here to Skip to main content
Licence 
First Posted 7 Mar 2004
Views 35,669
Bookmarked 29 times

CAtlHttpClientT Bug Fixed

By | 7 Mar 2004 | Article
A fix of ATL 7 CAtlHttpClientT code

Introduction

This article provides a small but important fix to the ATL 7 CAtlHttpClientT class.

Background

The HTTP/1.1 specification supports chunked transfer encoding of the message body (see section 3.6 of RFC 2068). Chunked transfer encoding modifies the body of a message in order to transfer it as a series of chunks, each with its own size indicator. Unlike usual HTTP file transfer, chunked transfer does not specify the transfer length, i.e. there is no "Content-Length:" header transferred – the sender adds a "Transfer-Encoding: chunked" header instead.

ATL 7 Bug

In ATL 7 HTTP client transactions are performed with the CAtlHttpClientT class. This class supports, in particular, chunked-transfer encoding/decoding. It contains a protected method IsMsgBodyChunked() that checks whether the message body is chunked. The code of this method looks as following (ATLHTTP.INL, lines 1254 - 1263):

template<class TSocketClass>
inline bool CAtlHttpClientT<TSocketClass>::IsMsgBodyChunked()
{
  CString strValue;
  return (
    GetHeaderValue(_T("Transfer-Encoding"), strValue) &&
    strValue == _T("chunked") // m_HeaderMap lower cases 
                    // all values before storing
  );
}

Unfortunately, strValue here may end with CR/LF, i.e. be equal to "chunked\r\n" (I have met this situation while receiving files from the Microsoft IIS). In this case CAtlHttpClientT does not recognize chunked-transfer encoding and returns the raw response body. Below is a bug fix:

template<class TSocketClass>
inline bool CAtlHttpClientT<TSocketClass>::IsMsgBodyChunked()
{
  CString strValue;
  if (!GetHeaderValue(_T("Transfer-Encoding"), strValue))
    return false;
  if (strValue.Right(2) == _T("\r\n"))
    strValue = strValue.Left(strValue.GetLength() - 2);
  // m_HeaderMap lower cases all values before storing
  return strValue == _T("chunked");
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Yury Lukach

Web Developer

Russian Federation Russian Federation

Member

A developer with more than 20 years expierence.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAnother bug in atlhttp.inl PinmemberShaunco9:14 7 Apr '05  
GeneralLittle improvement... PinmemberRalph Wetzel10:07 8 Mar '04  
GeneralRe: Little improvement... PinsussJerry Pisk14:16 8 Mar '04  
GeneralRe: Little improvement... PinmemberRalph Wetzel4:49 9 Mar '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 8 Mar 2004
Article Copyright 2004 by Yury Lukach
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid