HTTPChunkedStream.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // HTTPChunkedStream.h
  3. //
  4. // Library: Net
  5. // Package: HTTP
  6. // Module: HTTPChunkedStream
  7. //
  8. // Definition of the HTTPChunkedStream class.
  9. //
  10. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Net_HTTPChunkedStream_INCLUDED
  16. #define Net_HTTPChunkedStream_INCLUDED
  17. #include "Poco/Net/Net.h"
  18. #include "Poco/Net/HTTPBasicStreamBuf.h"
  19. #include "Poco/MemoryPool.h"
  20. #include <cstddef>
  21. #include <istream>
  22. #include <ostream>
  23. namespace Poco {
  24. namespace Net {
  25. class HTTPSession;
  26. class Net_API HTTPChunkedStreamBuf: public HTTPBasicStreamBuf
  27. /// This is the streambuf class used for reading and writing
  28. /// HTTP message bodies in chunked transfer coding.
  29. {
  30. public:
  31. typedef HTTPBasicStreamBuf::openmode openmode;
  32. HTTPChunkedStreamBuf(HTTPSession& session, openmode mode);
  33. ~HTTPChunkedStreamBuf();
  34. void close();
  35. protected:
  36. int readFromDevice(char* buffer, std::streamsize length);
  37. int writeToDevice(const char* buffer, std::streamsize length);
  38. private:
  39. HTTPSession& _session;
  40. openmode _mode;
  41. std::streamsize _chunk;
  42. std::string _chunkBuffer;
  43. };
  44. class Net_API HTTPChunkedIOS: public virtual std::ios
  45. /// The base class for HTTPInputStream.
  46. {
  47. public:
  48. HTTPChunkedIOS(HTTPSession& session, HTTPChunkedStreamBuf::openmode mode);
  49. ~HTTPChunkedIOS();
  50. HTTPChunkedStreamBuf* rdbuf();
  51. protected:
  52. HTTPChunkedStreamBuf _buf;
  53. };
  54. class Net_API HTTPChunkedInputStream: public HTTPChunkedIOS, public std::istream
  55. /// This class is for internal use by HTTPSession only.
  56. {
  57. public:
  58. HTTPChunkedInputStream(HTTPSession& session);
  59. ~HTTPChunkedInputStream();
  60. void* operator new(std::size_t size);
  61. void operator delete(void* ptr);
  62. private:
  63. static Poco::MemoryPool _pool;
  64. };
  65. class Net_API HTTPChunkedOutputStream: public HTTPChunkedIOS, public std::ostream
  66. /// This class is for internal use by HTTPSession only.
  67. {
  68. public:
  69. HTTPChunkedOutputStream(HTTPSession& session);
  70. ~HTTPChunkedOutputStream();
  71. void* operator new(std::size_t size);
  72. void operator delete(void* ptr);
  73. private:
  74. static Poco::MemoryPool _pool;
  75. };
  76. } } // namespace Poco::Net
  77. #endif // Net_HTTPChunkedStream_INCLUDED