1 /*
2  * Copyright (c) 2021-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 #ifndef COMMUNICATIONNETSTACK_HTTP_MODULE_H
17 #define COMMUNICATIONNETSTACK_HTTP_MODULE_H
18 
19 #include "napi/native_api.h"
20 
21 namespace OHOS::NetStack::Http {
22 class HttpModuleExports {
23 public:
24     class HttpResponseCache {
25     public:
26         static constexpr const char *FUNCTION_FLUSH = "flush";
27         static constexpr const char *FUNCTION_DELETE = "delete";
28 
29         static napi_value Flush(napi_env env, napi_callback_info info);
30         static napi_value Delete(napi_env env, napi_callback_info info);
31     };
32 
33     class HttpRequest {
34     public:
35         static constexpr const char *FUNCTION_REQUEST = "request";
36         static constexpr const char *FUNCTION_REQUEST_IN_STREAM = "requestInStream";
37         static constexpr const char *FUNCTION_DESTROY = "destroy";
38         static constexpr const char *FUNCTION_ON = "on";
39         static constexpr const char *FUNCTION_ONCE = "once";
40         static constexpr const char *FUNCTION_OFF = "off";
41 
42         static napi_value Request(napi_env env, napi_callback_info info);
43         static napi_value RequestInStream(napi_env env, napi_callback_info info);
44         static napi_value Destroy(napi_env env, napi_callback_info info);
45         static napi_value On(napi_env env, napi_callback_info info);
46         static napi_value Once(napi_env env, napi_callback_info info);
47         static napi_value Off(napi_env env, napi_callback_info info);
48     };
49 
50     static constexpr const char *FUNCTION_CREATE_HTTP = "createHttp";
51     static constexpr const char *FUNCTION_CREATE_HTTP_RESPONSE_CACHE = "createHttpResponseCache";
52     static constexpr const char *INTERFACE_REQUEST_METHOD = "RequestMethod";
53     static constexpr const char *INTERFACE_RESPONSE_CODE = "ResponseCode";
54     static constexpr const char *INTERFACE_HTTP_REQUEST = "OHOS_NET_HTTP_HttpRequest";
55     static constexpr const char *INTERFACE_HTTP_PROTOCOL = "HttpProtocol";
56     static constexpr const char *INTERFACE_CERT_TYPE = "CertType";
57     static constexpr const char *INTERFACE_HTTP_RESPONSE_CACHE = "OHOS_NET_HTTP_HttpResponseCache";
58     static constexpr const char *INTERFACE_HTTP_DATA_TYPE = "HttpDataType";
59 
60     static napi_value InitHttpModule(napi_env env, napi_value exports);
61 
62 private:
63     static napi_value CreateHttp(napi_env env, napi_callback_info info);
64 
65     static napi_value CreateHttpResponseCache(napi_env env, napi_callback_info info);
66 
67     static void DefineHttpRequestClass(napi_env env, napi_value exports);
68 
69     static void DefineHttpResponseCacheClass(napi_env env, napi_value exports);
70 
71     static void InitHttpProperties(napi_env env, napi_value exports);
72 
73     static void InitRequestMethod(napi_env env, napi_value exports);
74 
75     static void InitResponseCode(napi_env env, napi_value exports);
76 
77     static void InitHttpProtocol(napi_env env, napi_value exports);
78 
79     static void InitCertType(napi_env env, napi_value exports);
80 
81     static void InitHttpDataType(napi_env env, napi_value exports);
82 };
83 } // namespace OHOS::NetStack::Http
84 #endif // COMMUNICATIONNETSTACK_HTTP_MODULE_H