2019-04-11 14:40:54 +08:00
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +08:00
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2019-10-11 21:12:29 +08:00
|
|
|
#include <kiwano/core/function.hpp>
|
2019-08-13 21:16:38 +08:00
|
|
|
#include <kiwano/core/basic_json.hpp>
|
2019-08-18 10:23:54 +08:00
|
|
|
#include <kiwano/base/ObjectBase.h>
|
2019-09-30 10:59:04 +08:00
|
|
|
#include <kiwano/base/SmartPtr.hpp>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
namespace network
|
|
|
|
|
{
|
2019-09-30 10:59:04 +08:00
|
|
|
class HttpResponse;
|
|
|
|
|
|
|
|
|
|
KGE_DECLARE_SMART_PTR(HttpRequest);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
class KGE_API HttpRequest
|
2019-08-18 10:23:54 +08:00
|
|
|
: public ObjectBase
|
2019-03-31 01:37:06 +08:00
|
|
|
{
|
|
|
|
|
public:
|
2019-09-30 10:59:04 +08:00
|
|
|
using ResponseCallback = Function<void(HttpRequest*, HttpResponse*)>;
|
|
|
|
|
|
2019-03-31 01:37:06 +08:00
|
|
|
enum class Type
|
|
|
|
|
{
|
|
|
|
|
Unknown,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Delete
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline HttpRequest() : type_(Type::Unknown) {}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline HttpRequest(Type type) : type_(type) {}
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline void SetUrl(String const& url) { url_ = url; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline String const& GetUrl() const { return url_; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline void SetType(Type type) { type_ = type; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline Type GetType() const { return type_; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline void SetData(String const& data) { data_ = data; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
void SetJsonData(Json const& json);
|
2019-03-31 23:09:49 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline String const& GetData() const { return data_; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline void SetHeaders(Map<String, String> const& headers) { headers_ = headers; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
void SetHeader(String const& field, String const& content);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline Map<String, String>& GetHeaders() { return headers_; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline String const& GetHeader(String const& header) const { return headers_.at(header); }
|
2019-03-31 23:09:49 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline void SetResponseCallback(ResponseCallback const& callback) { response_cb_ = callback; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
2019-09-30 10:59:04 +08:00
|
|
|
inline ResponseCallback const& GetResponseCallback() const { return response_cb_; }
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Type type_;
|
2019-03-31 13:09:31 +08:00
|
|
|
String url_;
|
|
|
|
|
String data_;
|
2019-03-31 23:09:49 +08:00
|
|
|
Map<String, String> headers_;
|
2019-03-31 01:37:06 +08:00
|
|
|
ResponseCallback response_cb_;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|