• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
22 class HttpModuleExports {
23 public:
24     class HttpRequest {
25     public:
26         static constexpr const char *FUNCTION_REQUEST = "request";
27         static constexpr const char *FUNCTION_DESTROY = "destroy";
28         static constexpr const char *FUNCTION_ON = "on";
29         static constexpr const char *FUNCTION_ONCE = "once";
30         static constexpr const char *FUNCTION_OFF = "off";
31 
32         static napi_value Request(napi_env env, napi_callback_info info);
33         static napi_value Destroy(napi_env env, napi_callback_info info);
34         static napi_value On(napi_env env, napi_callback_info info);
35         static napi_value Once(napi_env env, napi_callback_info info);
36         static napi_value Off(napi_env env, napi_callback_info info);
37     };
38 
39     enum class ResponseCode {
40         OK = 200,
41         CREATED,
42         ACCEPTED,
43         NOT_AUTHORITATIVE,
44         NO_CONTENT,
45         RESET,
46         PARTIAL,
47         MULT_CHOICE = 300,
48         MOVED_PERM,
49         MOVED_TEMP,
50         SEE_OTHER,
51         NOT_MODIFIED,
52         USE_PROXY,
53         BAD_REQUEST = 400,
54         UNAUTHORIZED,
55         PAYMENT_REQUIRED,
56         FORBIDDEN,
57         NOT_FOUND,
58         BAD_METHOD,
59         NOT_ACCEPTABLE,
60         PROXY_AUTH,
61         CLIENT_TIMEOUT,
62         CONFLICT,
63         GONE,
64         LENGTH_REQUIRED,
65         PRECON_FAILED,
66         ENTITY_TOO_LARGE,
67         REQ_TOO_LONG,
68         UNSUPPORTED_TYPE,
69         INTERNAL_ERROR = 500,
70         NOT_IMPLEMENTED,
71         BAD_GATEWAY,
72         UNAVAILABLE,
73         GATEWAY_TIMEOUT,
74         VERSION,
75     };
76 
77     static constexpr const char *FUNCTION_CREATE_HTTP = "createHttp";
78     static constexpr const char *INTERFACE_REQUEST_METHOD = "RequestMethod";
79     static constexpr const char *INTERFACE_RESPONSE_CODE = "ResponseCode";
80     static constexpr const char *INTERFACE_HTTP_REQUEST = "HttpRequest";
81 
82     static napi_value InitHttpModule(napi_env env, napi_value exports);
83 
84 private:
85     static napi_value CreateHttp(napi_env env, napi_callback_info info);
86 
87     static void DefineHttpRequestClass(napi_env env, napi_value exports);
88 
89     static void InitHttpProperties(napi_env env, napi_value exports);
90 
91     static void InitRequestMethod(napi_env env, napi_value exports);
92 
93     static void InitResponseCode(napi_env env, napi_value exports);
94 };
95 } // namespace OHOS::NetStack
96 #endif // COMMUNICATIONNETSTACK_HTTP_MODULE_H