HttpRequester.h 1.38 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2
 * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
xiongziliang committed
3
 *
4
 * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
xiongziliang committed
5
 *
xiongziliang committed
6 7 8
 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
xiongziliang committed
9
 */
xiongziliang committed
10 11 12 13 14 15

#ifndef Htt_HttpRequester_h
#define Htt_HttpRequester_h

#include "HttpClientImp.h"

xiongziliang committed
16 17
namespace mediakit{

xiongziliang committed
18 19 20 21 22 23 24
class HttpRequester : public HttpClientImp
{
public:
    typedef std::shared_ptr<HttpRequester> Ptr;
    typedef std::function<void(const SockException &ex,const string &status,const HttpHeader &header,const string &strRecvBody)> HttpRequesterResult;
    HttpRequester();
    virtual ~HttpRequester();
25
    void setOnResult(const HttpRequesterResult &onResult);
xiongziliang committed
26
    void startRequester(const string &url,const HttpRequesterResult &onResult,float timeOutSecond = 10);
27
    void clear() override ;
xiongziliang committed
28
private:
29
    ssize_t onResponseHeader(const string &status,const HttpHeader &headers) override;
30
    void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize)  override;
31
    void onResponseCompleted() override;
xiongziliang committed
32
    void onDisconnect(const SockException &ex) override;
33
private:
xiongziliang committed
34 35 36 37
    string _strRecvBody;
    HttpRequesterResult _onResult;
};

xiongziliang committed
38
}//namespace mediakit
xiongziliang committed
39 40

#endif /* Htt_HttpRequester_h */