CHENGQI YANG / SmartLab_MuRata
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPResponse.cpp Source File

HTTPResponse.cpp

00001 #include "HTTPResponse.h"
00002 
00003 using namespace SmartLabMuRata;
00004 
00005 HTTPResponse::HTTPResponse(Payload * payload)
00006     : Payload(payload)
00007 {
00008     if (payload == NULL)
00009         return;
00010         
00011     statusCode = GetData()[2] << 8 | GetData()[3];
00012     if (statusCode >= 100) {
00013         contentLength = (GetData()[4] & 0x7F) << 8 | GetData()[5];
00014         contentType.assign(GetData() + 6);
00015         payloadOffset = 6 + contentType.length() + 1;
00016 
00017         GetData()[payloadOffset + contentLength] = 0x00;
00018     }
00019 }
00020 
00021 bool HTTPResponse::isMoreDataComing()
00022 {
00023     return (GetData()[4] >> 7) == 0x01 ? true : false;
00024 }
00025 
00026 int HTTPResponse::GetContentLength()
00027 {
00028     return contentLength;
00029 }
00030 
00031 int HTTPResponse::GetStatusCode()
00032 {
00033     return statusCode;
00034 }
00035 
00036 char HTTPResponse::GetContent(int index)
00037 {
00038     return GetData()[index + payloadOffset];
00039 }
00040 
00041 const char * HTTPResponse::GetContent()
00042 {
00043     return GetData() + payloadOffset;
00044 }
00045 
00046 string & HTTPResponse::GetContentType()
00047 {
00048     return contentType;
00049 }
00050 
00051 int HTTPResponse::GetContentOffset()
00052 {
00053     return payloadOffset;
00054 }