/mordor/http/chunked.h

http://github.com/mozy/mordor · C Header · 47 lines · 36 code · 10 blank · 1 comment · 0 complexity · a0d9481ad73954e4b96aaad6c4aa7406 MD5 · raw file

  1. #ifndef __MORDOR_HTTP_CHUNKED_H__
  2. #define __MORDOR_HTTP_CHUNKED_H__
  3. // Copyright (c) 2009 - Mozy, Inc.
  4. #include "mordor/exception.h"
  5. #include "mordor/streams/filter.h"
  6. namespace Mordor {
  7. namespace HTTP {
  8. struct InvalidChunkException : virtual StreamException
  9. {
  10. public:
  11. enum Type
  12. {
  13. HEADER,
  14. FOOTER
  15. };
  16. InvalidChunkException(const std::string &line, Type type);
  17. ~InvalidChunkException() throw() {}
  18. const std::string &line() const { return m_line; }
  19. Type type() const { return m_type; }
  20. private:
  21. std::string m_line;
  22. Type m_type;
  23. };
  24. class ChunkedStream : public MutatingFilterStream
  25. {
  26. public:
  27. ChunkedStream(Stream::ptr parent, bool own = true);
  28. void close(CloseType type = BOTH);
  29. using MutatingFilterStream::read;
  30. size_t read(Buffer &b, size_t len);
  31. using MutatingFilterStream::write;
  32. size_t write(const Buffer &b, size_t len);
  33. private:
  34. unsigned long long m_nextChunk;
  35. };
  36. }}
  37. #endif