ResponseHeader.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Qt.h"
00024 #include "ResponseHeader.h"
00025 #include "Imports.cpp"
00026
00028 auto_ptr <DataBase> ResponseHeader::copy() const
00029 {
00030 return auto_ptr <DataBase> (new ResponseHeader (*this));
00031 }
00032
00034
00040 ResponseHeader::ResponseHeader (int statusCode,
00041 const QByteArray &reasonPhrase,
00042 int majorVersion,
00043 int minorVersion)
00044 : HeaderBase (new Data)
00045 {
00046 Q_SD (Data);
00047 d->statusCode = statusCode;
00048 d->reasonPhrase = reasonPhrase;
00049 d->majorVersion = majorVersion;
00050 d->minorVersion = minorVersion;
00051 }
00052
00054 bool ResponseHeader::parseStartLine (const QByteArray &startLine)
00055 {
00056 QRegExp startLineRegExp ("HTTP/(\\d+).(\\d+)\\s*(\\d{3})(.*)",
00057 Qt::CaseSensitive, QRegExp::RegExp2);
00058 if (!startLineRegExp.exactMatch (startLine)
00059 || startLineRegExp.cap (4).trimmed().isEmpty()) {
00060 return false;
00061 } else {
00062 Q_SD (Data);
00063 d->majorVersion = startLineRegExp.cap (1).toInt();
00064 d->minorVersion = startLineRegExp.cap (2).toInt();
00065 d->statusCode = startLineRegExp.cap (3).toInt();
00066 d->reasonPhrase = startLineRegExp.cap (4).toLatin1().trimmed();
00067 return true;
00068 }
00069 }
00070
00072 QByteArray ResponseHeader::rawStartLine() const
00073 {
00074 Q_SD (const Data);
00075 QByteArray res = "HTTP/";
00076 res += QByteArray().setNum (d->majorVersion);
00077 res += ".";
00078 res += QByteArray().setNum (d->minorVersion);
00079 res += " ";
00080 res += QByteArray().setNum (d->statusCode);
00081 res += " ";
00082 res += d->reasonPhrase;
00083 res += "\r\n";
00084 return res;
00085 }