source: cheroxy/trunk/src/CRXHttpResponse.cpp@ 17

Last change on this file since 17 was 17, checked in by cheese, 11 years ago

#1 fix crash bug at some sites like http://msdn.com .

File size: 1.4 KB
Line 
1/**
2 * CRXHttpResponse.cpp
3 */
4#ifdef _WIN32
5# pragma warning (disable:4996)
6#endif
7
8#include "CRXHttpResponse.h"
9
10#include <stdio.h>
11#include <stdlib.h>
12
13CRXHttpResponse::CRXHttpResponse (void)
14 : mStatusCode (0)
15{
16}
17
18void
19CRXHttpResponse::SetResponse (const char * aHttpResponse)
20{
21 SetMessage (aHttpResponse);
22}
23
24std::string
25CRXHttpResponse::GetResponse (void) const
26{
27 return GetMessage ();
28}
29
30CRXHttpResponse &
31CRXHttpResponse::operator = (const char * aHttpMessage)
32{
33 SetMessage (aHttpMessage);
34 return *this;
35}
36
37void
38CRXHttpResponse::Parse (void)
39{
40 std::string aHttpStatus = "";
41
42 char aStatusCode[64] = {0x00, };
43 char aStatusString[64] = {0x00, };
44 char aHttpVersion[64] = {0x00, };
45
46 /*----------------------------------------------------------------*/
47 aHttpStatus = GetResponse ().substr (0, mHttpMessage.find ('\r'));
48
49 /*----------------------------------------------------------------
50 * 1. separate first line to <METHOD>, <URL> and <VERSION>
51 *----------------------------------------------------------------*/
52 sscanf (aHttpStatus.c_str (), "%[^ ] %[^ ] %[^ ]\r\n", aHttpVersion, aStatusCode, aStatusString);
53 mHttpVersion.assign (aHttpVersion);
54 mStatusString.assign (aStatusString);
55 mStatusCode = atoi (aStatusCode);
56
57 /*----------------------------------------------------------------*/
58}
59
60int
61CRXHttpResponse::GetStatusCode (void) const
62{
63 return mStatusCode;
64}
Note: See TracBrowser for help on using the repository browser.