HttpRequest.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef _D_HTTP_REQUEST_H_
  36. #define _D_HTTP_REQUEST_H_
  37. #include "common.h"
  38. #include "SharedHandle.h"
  39. #include <string>
  40. #include <deque>
  41. namespace aria2 {
  42. class Request;
  43. class Segment;
  44. class Range;
  45. class Option;
  46. class HttpRequest {
  47. private:
  48. static std::string USER_AGENT;
  49. SharedHandle<Request> request;
  50. SharedHandle<Segment> segment;
  51. int64_t entityLength;
  52. bool authEnabled;
  53. bool proxyEnabled;
  54. bool proxyAuthEnabled;
  55. std::string userAgent;
  56. std::string getHostText(const std::string& host, int32_t port) const;
  57. std::string getProxyAuthString() const;
  58. public:
  59. HttpRequest();
  60. SharedHandle<Segment> getSegment() const;
  61. void setSegment(const SharedHandle<Segment>& segment);
  62. void setRequest(const SharedHandle<Request>& request);
  63. /**
  64. * entityLength is used in isRangeSatisfied() method.
  65. */
  66. void setEntityLength(int64_t entityLength)
  67. {
  68. this->entityLength = entityLength;
  69. }
  70. int64_t getEntityLength() const
  71. {
  72. return entityLength;
  73. }
  74. std::string getHost() const;
  75. int32_t getPort() const;
  76. std::string getMethod() const;
  77. std::string getProtocol() const;
  78. std::string getCurrentURI() const;
  79. std::string getDir() const;
  80. std::string getFile() const;
  81. std::string getPreviousURI() const;
  82. SharedHandle<Range> getRange() const;
  83. /**
  84. * Inspects whether the specified response range is satisfiable
  85. * with request range.
  86. */
  87. bool isRangeSatisfied(const SharedHandle<Range>& range) const;
  88. SharedHandle<Request> getRequest() const;
  89. int64_t getStartByte() const;
  90. int64_t getEndByte() const;
  91. /**
  92. * Returns string representation of http request.
  93. * It usually starts with "GET ..." and ends with "\r\n".
  94. */
  95. std::string createRequest() const;
  96. /**
  97. * Returns string representation of http tunnel request.
  98. * It usually starts with "CONNECT ..." and ends with "\r\n".
  99. */
  100. std::string createProxyRequest() const;
  101. /**
  102. * Configures this object with option.
  103. * Following values are evaluated:
  104. * PREF_HTTP_AUTH_ENABLED, PREF_HTTP_PROXY_ENABLED,
  105. * PREF_HTTP_PROXY_METHOD, PREF_HTTP_PROXY_AUTH_ENABLED,
  106. * PREF_HTTP_USER, PREF_HTTP_PASSWD,
  107. * PREF_HTTP_PROXY_USER, PREF_HTTP_PROXY_PASSWD
  108. * The evaluation results are stored in instance variables.
  109. */
  110. void configure(const Option* option);
  111. void setProxyEnabled(bool proxyEnabled)
  112. {
  113. this->proxyEnabled = proxyEnabled;
  114. }
  115. void setProxyAuthEnabled(bool proxyAuthEnabled)
  116. {
  117. this->proxyAuthEnabled = proxyAuthEnabled;
  118. }
  119. void setAuthEnabled(bool authEnabled)
  120. {
  121. this->authEnabled = authEnabled;
  122. }
  123. void setUserAgent(const std::string& userAgent)
  124. {
  125. this->userAgent = userAgent;
  126. }
  127. };
  128. typedef SharedHandle<HttpRequest> HttpRequestHandle;
  129. typedef std::deque<HttpRequestHandle> HttpRequests;
  130. } // namespace aria2
  131. #endif // _D_HTTP_REQUEST_H_