http_client_tcp.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*************************************************************************/
  2. /* http_client_tcp.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef HTTP_CLIENT_TCP_H
  31. #define HTTP_CLIENT_TCP_H
  32. #include "http_client.h"
  33. class HTTPClientTCP : public HTTPClient {
  34. private:
  35. Status status = STATUS_DISCONNECTED;
  36. IP::ResolverID resolving = IP::RESOLVER_INVALID_ID;
  37. Array ip_candidates;
  38. int conn_port = -1;
  39. String conn_host;
  40. bool ssl = false;
  41. bool ssl_verify_host = false;
  42. bool blocking = false;
  43. bool handshaking = false;
  44. bool head_request = false;
  45. Vector<uint8_t> response_str;
  46. bool chunked = false;
  47. Vector<uint8_t> chunk;
  48. int chunk_left = 0;
  49. bool chunk_trailer_part = false;
  50. int body_size = -1;
  51. int body_left = 0;
  52. bool read_until_eof = false;
  53. Ref<StreamPeerTCP> tcp_connection;
  54. Ref<StreamPeer> connection;
  55. int response_num = 0;
  56. Vector<String> response_headers;
  57. // 64 KiB by default (favors fast download speeds at the cost of memory usage).
  58. int read_chunk_size = 65536;
  59. Error _get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received);
  60. public:
  61. static HTTPClient *_create_func();
  62. Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override;
  63. Error connect_to_host(const String &p_host, int p_port = -1, bool p_ssl = false, bool p_verify_host = true) override;
  64. void set_connection(const Ref<StreamPeer> &p_connection) override;
  65. Ref<StreamPeer> get_connection() const override;
  66. void close() override;
  67. Status get_status() const override;
  68. bool has_response() const override;
  69. bool is_response_chunked() const override;
  70. int get_response_code() const override;
  71. Error get_response_headers(List<String> *r_response) override;
  72. int get_response_body_length() const override;
  73. PackedByteArray read_response_body_chunk() override;
  74. void set_blocking_mode(bool p_enable) override;
  75. bool is_blocking_mode_enabled() const override;
  76. void set_read_chunk_size(int p_size) override;
  77. int get_read_chunk_size() const override;
  78. Error poll() override;
  79. HTTPClientTCP();
  80. };
  81. #endif // HTTP_CLIENT_TCP_H