• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "fetch_request.h"
17 
18 #include "constant.h"
19 #include "netstack_common_utils.h"
20 
21 namespace OHOS::NetStack::Fetch {
FetchRequest()22 FetchRequest::FetchRequest() : method_(FetchConstant::HTTP_METHOD_GET)
23 {
24     header_[CommonUtils::ToLower(FetchConstant::HTTP_CONTENT_TYPE)] = FetchConstant::HTTP_CONTENT_TYPE_JSON; // default
25 }
26 
SetUrl(const std::string & url)27 void FetchRequest::SetUrl(const std::string &url)
28 {
29     url_ = url;
30 }
31 
SetMethod(const std::string & method)32 void FetchRequest::SetMethod(const std::string &method)
33 {
34     method_ = method;
35 }
36 
SetBody(const void * data,size_t length)37 void FetchRequest::SetBody(const void *data, size_t length)
38 {
39     body_.append(static_cast<const char *>(data), length);
40 }
41 
SetHeader(const std::string & key,const std::string & val)42 void FetchRequest::SetHeader(const std::string &key, const std::string &val)
43 {
44     header_[key] = val;
45 }
46 
GetUrl() const47 const std::string &FetchRequest::GetUrl() const
48 {
49     return url_;
50 }
51 
GetMethod() const52 const std::string &FetchRequest::GetMethod() const
53 {
54     return method_;
55 }
56 
GetBody() const57 const std::string &FetchRequest::GetBody() const
58 {
59     return body_;
60 }
61 
GetHeader() const62 const std::map<std::string, std::string> &FetchRequest::GetHeader() const
63 {
64     return header_;
65 }
66 } // namespace OHOS::NetStack::Fetch