
/*---------------------------------------------------------------------------*/
/* http_passthrough_handler.h                                                */
/* copyright (c) innovaphone 2016                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

class HTTPPassthroughHandler: public HTTPMethodHandler {
protected:
    // These fields are proteted in the HTTPMethodHandler class. So define our own here...
    byte * restDataBuffer;
    byte * curRestDataBufferPos;
    size_t restDataBufferSize;
    byte * recvBuffer;
    size_t recvBufferSize;
    bool recvCalled;
    bool isTLS;

    virtual void OnPrepareHeader() override { /* No need for HTTPPassthroughHandler */ };
    virtual void OnSendMetaData(dword info, class ExtendedHeader & extHeader) override;
    virtual void OnRecv(dword size) override;
    virtual void OnSend(dword info, byte * buffer, size_t size) override;
    virtual void OnHandlerClose(dword info, class ExtendedHeader & extHeader) override;
    virtual http_method_init_t OnHandlerInit(const HTTPParser * parser, byte * buffer, size_t size) override;

public:
    HTTPPassthroughHandler(UHTTPMethodHandler * const user, class HTTPRegisteredPath * reqPathObj, class HTTPDataSource * dataSource, ISocket * const remoteSocket, bool isTLS, IInstanceLog * const log, connection_flags_t connFlags);
    virtual ~HTTPPassthroughHandler();

    virtual void SocketRecvResult(byte * buffer, size_t size) override;
    virtual void SocketShutdown(shutdownreason_t reason) override;
    
    bool RecvCalled() { return this->recvCalled; }
    byte * GetRecvBufferOwnership()
    {
        byte * tmp = this->recvBuffer;
        this->recvBuffer = nullptr;
        return tmp;
    }
};
