1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <alibabacloud/oss/http/HttpMessage.h>
18 
19 using namespace AlibabaCloud::OSS;
20 
HttpMessage()21 HttpMessage::HttpMessage() :
22     headers_(),
23     body_()
24 {
25 }
26 
HttpMessage(const HttpMessage & other)27 HttpMessage::HttpMessage(const HttpMessage &other) :
28     headers_(other.headers_),
29     body_(other.body_)
30 {
31 }
32 
HttpMessage(HttpMessage && other)33 HttpMessage::HttpMessage(HttpMessage &&other)
34 {
35     *this = std::move(other);
36 }
37 
operator =(const HttpMessage & other)38 HttpMessage& HttpMessage::operator=(const HttpMessage &other)
39 {
40     if (this != &other) {
41         body_ = other.body_;
42         headers_ = other.headers_;
43     }
44     return *this;
45 }
46 
operator =(HttpMessage && other)47 HttpMessage& HttpMessage::operator=(HttpMessage &&other)
48 {
49     if (this != &other) {
50         body_ = std::move(other.body_);
51         headers_ = std::move(other.headers_);
52     }
53     return *this;
54 }
55 
addHeader(const std::string & name,const std::string & value)56 void HttpMessage::addHeader(const std::string & name, const std::string & value)
57 {
58     setHeader(name, value);
59 }
60 
setHeader(const std::string & name,const std::string & value)61 void HttpMessage::setHeader(const std::string & name, const std::string & value)
62 {
63     headers_[name] = value;
64 }
65 
removeHeader(const std::string & name)66 void HttpMessage::removeHeader(const std::string & name)
67 {
68     headers_.erase(name);
69 }
70 
71 
hasHeader(const std::string & name) const72 bool HttpMessage::hasHeader(const std::string &name) const
73 {
74     return  (headers_.find(name) != headers_.end()) ? true : false;
75 }
76 
Header(const std::string & name) const77 std::string HttpMessage::Header(const std::string & name) const
78 {
79     auto it = headers_.find(name);
80     if (it != headers_.end())
81         return it->second;
82     else
83         return std::string();
84 }
85 
Headers() const86 const HeaderCollection &HttpMessage::Headers() const
87 {
88     return headers_;
89 }
90 
~HttpMessage()91 HttpMessage::~HttpMessage()
92 {
93 
94 }
95 
96 
97