• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "response_data.h"
17 
18 #include "http_constant.h"
19 #include "http_request_utils.h"
20 
21 namespace OHOS {
22 namespace ACELite {
23 
ResponseData()24 ResponseData::ResponseData()
25 {
26     code = HttpConstant::HTTP_RESPONSE_CODE_INVALID;
27 }
28 
SetCode(int32_t codePara)29 void ResponseData::SetCode(int32_t codePara)
30 {
31     code = codePara;
32 }
33 
SetErrString(const std::string & err)34 void ResponseData::SetErrString(const std::string &err)
35 {
36     errString = err;
37 }
38 
ParseHeaders(const std::string & headersStr)39 void ResponseData::ParseHeaders(const std::string &headersStr)
40 {
41     std::vector<std::string> vec = Split(headersStr, "\n");
42     for (auto header : vec) {
43         header = Strip(Strip(header), '\r');
44         if (header.empty()) {
45             continue;
46         }
47         size_t index = header.find(HttpConstant::HTTP_HEADER_SEPARATOR);
48         if (index == std::string::npos) {
49             statusLine = Strip(header);
50             continue;
51         }
52         headers[Strip(header.substr(0, index))] = Strip(header.substr(index + 1));
53     }
54 }
55 
GetCode() const56 int32_t ResponseData::GetCode() const
57 {
58     return code;
59 }
60 
GetErrString() const61 const std::string &ResponseData::GetErrString() const
62 {
63     return errString;
64 }
65 
AppendData(const char * dataPara,size_t size)66 void ResponseData::AppendData(const char *dataPara, size_t size)
67 {
68     data.append(dataPara, size);
69 }
70 
GetData() const71 const std::string &ResponseData::GetData() const
72 {
73     return data;
74 }
75 
GetStatusLine() const76 const std::string &ResponseData::GetStatusLine() const
77 {
78     return statusLine;
79 }
80 
GetHeaders() const81 const std::map<std::string, std::string> &ResponseData::GetHeaders() const
82 {
83     return headers;
84 }
85 } // namespace ACELite
86 } // namespace OHOS
87