qhttpheader_p.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
  3. These were part of the QtNetwork module of the Qt Toolkit.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef qhttpheader_p_h
  18. #define qhttpheader_p_h
  19. #include <QPair>
  20. #include <QString>
  21. #include <QStringList>
  22. namespace WebKit {
  23. class QHttpHeader {
  24. public:
  25. QHttpHeader();
  26. QHttpHeader(const QString&);
  27. virtual ~QHttpHeader();
  28. void setValue(const QString& key, const QString& value);
  29. void addValue(const QString& key, const QString& value);
  30. QString value(const QString& key) const;
  31. bool hasKey(const QString&) const;
  32. // ### Qt 5: change to qint64
  33. bool hasContentLength() const;
  34. uint contentLength() const;
  35. void setContentLength(int);
  36. bool hasContentType() const;
  37. QString contentType() const;
  38. void setContentType(const QString&);
  39. virtual QString toString() const;
  40. bool isValid() const { return m_valid; }
  41. virtual int majorVersion() const = 0;
  42. virtual int minorVersion() const = 0;
  43. protected:
  44. virtual bool parseLine(const QString& line, int number);
  45. bool parse(const QString&);
  46. void setValid(bool v) { m_valid = v; }
  47. private:
  48. bool m_valid;
  49. QList<QPair<QString, QString> > m_values;
  50. };
  51. class QHttpResponseHeader : public QHttpHeader {
  52. public:
  53. QHttpResponseHeader(int code, const QString& text = QString(), int majorVer = 1, int minorVer = 1);
  54. int statusCode() const { return m_statusCode; }
  55. QString reasonPhrase() const {return m_reasonPhrase; }
  56. int majorVersion() const { return m_majorVersion; }
  57. int minorVersion() const { return m_minorVersion; }
  58. QString toString() const;
  59. protected:
  60. bool parseLine(const QString& line, int number);
  61. private:
  62. int m_statusCode;
  63. QString m_reasonPhrase;
  64. int m_majorVersion;
  65. int m_minorVersion;
  66. };
  67. class QHttpRequestHeader : public QHttpHeader {
  68. public:
  69. QHttpRequestHeader();
  70. QHttpRequestHeader(const QString&);
  71. QString method() const { return m_method; }
  72. QString path() const { return m_path; }
  73. int majorVersion() const { return m_majorVersion; }
  74. int minorVersion() const { return m_minorVersion; }
  75. QString toString() const;
  76. protected:
  77. bool parseLine(const QString& line, int number);
  78. private:
  79. QString m_method;
  80. QString m_path;
  81. int m_majorVersion;
  82. int m_minorVersion;
  83. };
  84. }
  85. #endif