Click here to Skip to main content
15,881,709 members
Articles / Desktop Programming / ATL
Article

CAtlHttpClientT Bug Fixed

Rate me:
Please Sign up or sign in to vote.
4.91/5 (5 votes)
7 Mar 2004 46.5K   29   4
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


Written By
Web Developer
Russian Federation Russian Federation
A developer with more than 20 years expierence.

Comments and Discussions

 
GeneralAnother bug in atlhttp.inl Pin
Shaunco7-Apr-05 9:14
Shaunco7-Apr-05 9:14 
GeneralLittle improvement... Pin
Ralph Wetzel8-Mar-04 10:07
Ralph Wetzel8-Mar-04 10:07 
GeneralRe: Little improvement... Pin
Jerry III8-Mar-04 14:16
Jerry III8-Mar-04 14:16 
Oh those shortcuts. Ralph, what do you think will happen when your code receives "Transfer-Encoding: chunked-v2" header? Instead of not understanding it it will assume it is chunked. Please do not use your code, that's how security bugs get started.
GeneralRe: Little improvement... Pin
Ralph Wetzel9-Mar-04 4:49
Ralph Wetzel9-Mar-04 4:49 

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

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