RequestHeader.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 "RequestHeader.h"
00025 #include "Imports.cpp"
00026
00028 auto_ptr <DataBase> RequestHeader::copy() const
00029 {
00030 return auto_ptr <DataBase> (new RequestHeader (*this));
00031 }
00032
00034
00040 RequestHeader::RequestHeader (const QByteArray &method,
00041 const QByteArray &path,
00042 int majorVersion,
00043 int minorVersion)
00044 : HeaderBase (new Data)
00045 {
00046 Q_SD (Data);
00047 d->method = method;
00048 d->path = path;
00049 d->majorVersion = majorVersion;
00050 d->minorVersion = minorVersion;
00051 }
00052
00054 bool RequestHeader::parseStartLine (const QByteArray &startLine)
00055 {
00056 QRegExp startLineRegExp ("(\\S*)(.*)HTTP/(\\d+).(\\d+)",
00057 Qt::CaseSensitive, QRegExp::RegExp2);
00058 if (!startLineRegExp.exactMatch (startLine)
00059 || startLineRegExp.cap (2).trimmed().isEmpty()) {
00060 return false;
00061 } else {
00062 Q_SD (Data);
00063 d->method = startLineRegExp.cap (1).toLatin1();
00064 d->path = startLineRegExp.cap (2).toLatin1().trimmed();
00065 d->majorVersion = startLineRegExp.cap (3).toInt();
00066 d->minorVersion = startLineRegExp.cap (4).toInt();
00067 return true;
00068 }
00069 }
00070
00072 QByteArray RequestHeader::rawStartLine() const
00073 {
00074 Q_SD (const Data);
00075 QByteArray res = d->method;
00076 res += " ";
00077 res += d->path;
00078 res += " HTTP/";
00079 res += QByteArray().setNum (d->majorVersion);
00080 res += ".";
00081 res += QByteArray().setNum (d->minorVersion);
00082 res += "\r\n";
00083 return res;
00084 }