• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ota-meshi / eslint-plugin-json-schema-validator / 15509456335

07 Jun 2025 04:00PM UTC coverage: 87.33%. Remained the same
15509456335

Pull #371

github

web-flow
Merge 6eb844245 into 6fa634a04
Pull Request #371: chore(deps): update dependency vue-eslint-parser to v10

372 of 455 branches covered (81.76%)

Branch coverage included in aggregate %.

910 of 1013 relevant lines covered (89.83%)

178.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.23
/src/utils/http-client/get-modules/http.ts
1
import type { RequestOptions } from "https";
9✔
2
import https from "https";
1✔
3
import http from "http";
1✔
4
// @ts-expect-error -- no types
5
import tunnel from "tunnel-agent";
1✔
6

7
const TIMEOUT = 60000;
1✔
8

9
/**
10
 * GET Method using http modules.
11
 */
12
export default function get(
13
  url: string,
14
  options?: RequestOptions,
15
): Promise<string> {
16
  return get0(url, options, 0);
3✔
17
}
18

19
/** Implementation of HTTP GET method */
20
function get0(
21
  url: string,
22
  options: RequestOptions | undefined,
23
  redirectCount: number,
24
): Promise<string> {
25
  const client = url.startsWith("https") ? https : http;
5!
26
  const parsedOptions = parseUrlAndOptions(url, options || {});
5✔
27

28
  return new Promise((resolve, reject) => {
5✔
29
    let result = "";
5✔
30
    const req = client.get(parsedOptions, (res) => {
5✔
31
      res.on("data", (chunk) => {
5✔
32
        result += chunk;
11✔
33
      });
34
      res.on("end", () => {
5✔
35
        if (
5✔
36
          res.statusCode &&
14✔
37
          res.statusCode >= 300 &&
38
          res.statusCode < 400 &&
39
          redirectCount < 3 // max redirect
40
        ) {
41
          const location = res.headers.location!;
2✔
42
          try {
2✔
43
            const redirectUrl = new URL(location, url).toString();
2✔
44
            resolve(get0(redirectUrl, options, redirectCount + 1));
2✔
45
          } catch (e) {
46
            reject(e);
×
47
          }
48
          return;
2✔
49
        }
50
        resolve(result);
3✔
51
      });
52
    });
53
    req.on("error", (e) => {
5✔
54
      reject(e);
×
55
    });
56
    req.setTimeout(TIMEOUT, function handleRequestTimeout() {
5✔
57
      if (req.destroy) {
×
58
        req.destroy();
×
59
      } else {
60
        req.abort();
×
61
      }
62
      reject(new Error(`Timeout of ${TIMEOUT}ms exceeded`));
×
63
    });
64
  });
65
}
66

67
/** Parse URL and options */
68
function parseUrlAndOptions(urlStr: string, baseOptions: RequestOptions) {
69
  const url = new URL(urlStr);
5✔
70
  const hostname =
71
    typeof url.hostname === "string" && url.hostname.startsWith("[")
5!
72
      ? url.hostname.slice(1, -1)
73
      : url.hostname;
74
  const options: RequestOptions = {
5✔
75
    agent: false,
76
    ...baseOptions,
77
    protocol: url.protocol,
78
    hostname,
79
    path: `${url.pathname || ""}${url.search || ""}`,
15!
80
  };
81
  if (url.port !== "") {
5!
82
    options.port = Number(url.port);
×
83
  }
84
  if (url.username || url.password) {
5!
85
    options.auth = `${url.username}:${url.password}`;
×
86
  }
87

88
  const PROXY_ENV = [
5✔
89
    "https_proxy",
90
    "HTTPS_PROXY",
91
    "http_proxy",
92
    "HTTP_PROXY",
93
    "npm_config_https_proxy",
94
    "npm_config_http_proxy",
95
  ];
96

97
  const proxyStr: string =
98
    // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore
99
    (options as any)?.proxy ||
5✔
100
    // eslint-disable-next-line no-process-env -- ignore
101
    PROXY_ENV.map((k) => process.env[k]).find((v) => v);
30✔
102
  if (proxyStr) {
5!
103
    const proxyUrl = new URL(proxyStr);
×
104

105
    options.agent = tunnel[
×
106
      `http${url.protocol === "https:" ? "s" : ""}OverHttp${
×
107
        proxyUrl.protocol === "https:" ? "s" : ""
×
108
      }`
109
    ]({
110
      proxy: {
111
        host: proxyUrl.hostname,
112
        port: Number(proxyUrl.port),
113
        proxyAuth:
114
          proxyUrl.username || proxyUrl.password
×
115
            ? `${proxyUrl.username}:${proxyUrl.password}`
116
            : undefined,
117
      },
118
    });
119
  }
120
  return options;
5✔
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc