@ooneex/http-request 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +61 -2
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
// src/HttpRequest.ts
|
|
2
|
+
import { Header } from "@ooneex/http-header";
|
|
3
|
+
import { RequestFile } from "@ooneex/http-request-file";
|
|
4
|
+
import { Url } from "@ooneex/url";
|
|
5
|
+
import parser from "accept-language-parser";
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
class HttpRequest {
|
|
8
|
+
native;
|
|
9
|
+
path;
|
|
10
|
+
url;
|
|
11
|
+
method;
|
|
12
|
+
header;
|
|
13
|
+
userAgent;
|
|
14
|
+
params = {};
|
|
15
|
+
payload = {};
|
|
16
|
+
queries = {};
|
|
17
|
+
form;
|
|
18
|
+
files = {};
|
|
19
|
+
ip;
|
|
20
|
+
host;
|
|
21
|
+
language;
|
|
22
|
+
constructor(native, config) {
|
|
23
|
+
this.native = native;
|
|
24
|
+
this.url = new Url(this.native.url);
|
|
25
|
+
this.path = this.url.getPath();
|
|
26
|
+
this.method = this.native.method.toUpperCase();
|
|
27
|
+
this.header = new Header(native.headers);
|
|
28
|
+
this.queries = this.url.getQueries();
|
|
29
|
+
this.payload = config?.payload || {};
|
|
30
|
+
this.params = config?.params || {};
|
|
31
|
+
this.form = config?.form || null;
|
|
32
|
+
this.userAgent = this.header.getUserAgent();
|
|
33
|
+
if (config?.form) {
|
|
34
|
+
config.form.forEach((value, key) => {
|
|
35
|
+
if (value instanceof File) {
|
|
36
|
+
this.files[key] = new RequestFile(value);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
this.ip = config?.ip || null;
|
|
41
|
+
this.host = this.header.getHost() || "";
|
|
42
|
+
const customLang = this.url.getQuery("lang") || this.url.getQuery("locale") || this.header.get("X-Custom-Lang");
|
|
43
|
+
if (customLang) {
|
|
44
|
+
this.language = {
|
|
45
|
+
code: customLang,
|
|
46
|
+
region: null
|
|
47
|
+
};
|
|
48
|
+
} else {
|
|
49
|
+
const languages = parser.parse(this.header.get("Accept-Language") ?? "en-US");
|
|
50
|
+
const language = languages[0];
|
|
51
|
+
this.language = {
|
|
52
|
+
code: language?.code,
|
|
53
|
+
region: language?.region ?? null
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
HttpRequest
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//# debugId=4D868DC43B9DFAA464756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { Header, type IUserAgent } from \"@ooneex/http-header\";\nimport { type IRequestFile, RequestFile } from \"@ooneex/http-request-file\";\nimport type { LocaleInfoType, LocaleType } from \"@ooneex/translation\";\nimport type { HttpMethodType, ScalarType } from \"@ooneex/types\";\nimport { type IUrl, Url } from \"@ooneex/url\";\nimport parser from \"accept-language-parser\";\nimport type { IRequest, RequestConfigType } from \"./types\";\n\nexport class HttpRequest<Config extends RequestConfigType = RequestConfigType> implements IRequest<Config> {\n public readonly path: string;\n public readonly url: IUrl;\n public readonly method: HttpMethodType;\n public readonly header: Header;\n public readonly userAgent: IUserAgent | null;\n public readonly params: Config[\"params\"] = {};\n public readonly payload: Config[\"payload\"] = {};\n public readonly queries: Config[\"queries\"] = {};\n public readonly form: FormData | null;\n public readonly files: Record<string, IRequestFile> = {};\n public readonly ip: string | null;\n public readonly host: string;\n public readonly language: LocaleInfoType;\n\n constructor(\n public readonly native: Readonly<Request>,\n config?: {\n params?: Record<string, ScalarType>;\n form?: FormData | null;\n payload?: Record<string, unknown>;\n ip?: string | null;\n },\n ) {\n this.url = new Url(this.native.url);\n this.path = this.url.getPath();\n this.method = this.native.method.toUpperCase() as HttpMethodType;\n this.header = new Header(native.headers);\n this.queries = this.url.getQueries();\n this.payload = config?.payload || {};\n this.params = config?.params || {};\n this.form = config?.form || null;\n this.userAgent = this.header.getUserAgent();\n\n if (config?.form) {\n config.form.forEach((value, key) => {\n if (value instanceof File) {\n this.files[key] = new RequestFile(value);\n }\n });\n }\n\n this.ip = config?.ip || null;\n this.host = this.header.getHost() || \"\";\n\n const customLang = this.url.getQuery(\"lang\") || this.url.getQuery(\"locale\") || this.header.get(\"X-Custom-Lang\");\n if (customLang) {\n this.language = {\n code: customLang as LocaleType,\n region: null,\n };\n } else {\n const languages = parser.parse(this.header.get(\"Accept-Language\") ?? \"en-US\");\n const language = languages[0];\n this.language = {\n code: language?.code as LocaleType,\n region: language?.region ?? null,\n };\n }\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "AAAA,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AACA;AAGA;AACA;AAAA;AAGO,MAAM,YAA8F;AAAA,EAgBvF;AAAA,EAfF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAA2B,CAAC;AAAA,EAC5B,UAA6B,CAAC;AAAA,EAC9B,UAA6B,CAAC;AAAA,EAC9B;AAAA,EACA,QAAsC,CAAC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,WAAW,CACO,QAChB,QAMA;AAAA,IAPgB;AAAA,IAQhB,KAAK,MAAM,IAAI,IAAI,KAAK,OAAO,GAAG;AAAA,IAClC,KAAK,OAAO,KAAK,IAAI,QAAQ;AAAA,IAC7B,KAAK,SAAS,KAAK,OAAO,OAAO,YAAY;AAAA,IAC7C,KAAK,SAAS,IAAI,OAAO,OAAO,OAAO;AAAA,IACvC,KAAK,UAAU,KAAK,IAAI,WAAW;AAAA,IACnC,KAAK,UAAU,QAAQ,WAAW,CAAC;AAAA,IACnC,KAAK,SAAS,QAAQ,UAAU,CAAC;AAAA,IACjC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