Magic_Game/src/kiwano-network/HttpRequest.h

89 lines
2.8 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// 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-04-11 14:40:54 +08:00
namespace kiwano
{
namespace network
{
2019-09-30 10:59:04 +08:00
class HttpResponse;
KGE_DECLARE_SMART_PTR(HttpRequest);
2019-04-11 14:40:54 +08:00
class KGE_API HttpRequest
2019-08-18 10:23:54 +08:00
: public ObjectBase
{
public:
2019-09-30 10:59:04 +08:00
using ResponseCallback = Function<void(HttpRequest*, HttpResponse*)>;
enum class Type
{
Unknown,
Get,
Post,
Put,
Delete
};
2019-09-30 10:59:04 +08:00
inline HttpRequest() : type_(Type::Unknown) {}
2019-09-30 10:59:04 +08:00
inline HttpRequest(Type type) : type_(type) {}
2019-09-30 10:59:04 +08:00
inline void SetUrl(String const& url) { url_ = url; }
2019-09-30 10:59:04 +08:00
inline String const& GetUrl() const { return url_; }
2019-09-30 10:59:04 +08:00
inline void SetType(Type type) { type_ = type; }
2019-09-30 10:59:04 +08:00
inline Type GetType() const { return type_; }
2019-09-30 10:59:04 +08:00
inline void SetData(String const& data) { data_ = data; }
2019-09-30 10:59:04 +08:00
void SetJsonData(Json const& json);
2019-09-30 10:59:04 +08:00
inline String const& GetData() const { return data_; }
2019-09-30 10:59:04 +08:00
inline void SetHeaders(Map<String, String> const& headers) { headers_ = headers; }
2019-09-30 10:59:04 +08:00
void SetHeader(String const& field, String const& content);
2019-09-30 10:59:04 +08:00
inline Map<String, String>& GetHeaders() { return headers_; }
2019-09-30 10:59:04 +08:00
inline String const& GetHeader(String const& header) const { return headers_.at(header); }
2019-09-30 10:59:04 +08:00
inline void SetResponseCallback(ResponseCallback const& callback) { response_cb_ = callback; }
2019-09-30 10:59:04 +08:00
inline ResponseCallback const& GetResponseCallback() const { return response_cb_; }
protected:
Type type_;
2019-03-31 13:09:31 +08:00
String url_;
String data_;
Map<String, String> headers_;
ResponseCallback response_cb_;
};
}
}