Click here to Skip to main content
12,241,564 members (54,908 online)
Click here to Skip to main content
Add your own
alternative version

Stats

39.8K views
29 bookmarked
Posted

CAtlHttpClientT Bug Fixed

, 7 Mar 2004
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Yury Lukach
Web Developer
Russian Federation Russian Federation
A developer with more than 20 years expierence.

You may also be interested in...

Comments and Discussions

 
GeneralAnother bug in atlhttp.inl Pin
Shaunco7-Apr-05 10:14
memberShaunco7-Apr-05 10:14 
GeneralLittle improvement... Pin
Ralph Wetzel8-Mar-04 11:07
memberRalph Wetzel8-Mar-04 11:07 
GeneralRe: Little improvement... Pin
Jerry Pisk8-Mar-04 15:16
sussJerry Pisk8-Mar-04 15:16 
GeneralRe: Little improvement... Pin
Ralph Wetzel9-Mar-04 5:49
memberRalph Wetzel9-Mar-04 5: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.

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