1
0

HttpSession.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef HTTP_SESSION_H_
  2. #define HTTP_SESSION_H_
  3. #include "HttpMessage.h"
  4. class HttpSession {
  5. public:
  6. http_version version;
  7. http_session_type type;
  8. static HttpSession* New(http_session_type type = HTTP_CLIENT, http_version version = HTTP_V1);
  9. virtual ~HttpSession() {}
  10. virtual int GetSendData(char** data, size_t* len) = 0;
  11. virtual int FeedRecvData(const char* data, size_t len) = 0;
  12. // Http1Session: http_parser_state
  13. // Http2Session: http2_session_state
  14. virtual int GetState() = 0;
  15. // Http1Session: GetState() != HP_MESSAGE_COMPLETE
  16. // Http2Session: GetState() == HSS_WANT_RECV
  17. virtual bool WantRecv() = 0;
  18. // Http1Session: GetState() == HP_MESSAGE_COMPLETE
  19. // Http2Session: GetState() == HSS_WANT_SEND
  20. virtual bool WantSend() = 0;
  21. // IsComplete: Is recved HttpRequest or HttpResponse complete?
  22. // Http1Session: GetState() == HP_MESSAGE_COMPLETE
  23. // Http2Session: (state == HSS_RECV_HEADERS || state == HSS_RECV_DATA) && stream_closed
  24. virtual bool IsComplete() = 0;
  25. // client
  26. // SubmitRequest -> while(GetSendData) {send} -> InitResponse -> do {recv -> FeedRecvData} while(WantRecv)
  27. virtual int SubmitRequest(HttpRequest* req) = 0;
  28. virtual int InitResponse(HttpResponse* res) = 0;
  29. // server
  30. // InitRequest -> do {recv -> FeedRecvData} while(WantRecv) -> SubmitResponse -> while(GetSendData) {send}
  31. virtual int InitRequest(HttpRequest* req) = 0;
  32. virtual int SubmitResponse(HttpResponse* res) = 0;
  33. virtual int GetError() = 0;
  34. virtual const char* StrError(int error) = 0;
  35. };
  36. #endif // HTTP_SESSION_H_