Skip to content

Commit add7a35

Browse files
authored
chore: bump version to v1.3.10 (#68)
1 parent d5af0b3 commit add7a35

File tree

7 files changed

+129
-8
lines changed

7 files changed

+129
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function isAddressUnreachableError(host: any): Promise<any>;
2+
export function dataToServeUnreachablePage(host: any): {
3+
status: number;
4+
contentType: string;
5+
body: string;
6+
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.isAddressUnreachableError = isAddressUnreachableError;
7+
exports.dataToServeUnreachablePage = dataToServeUnreachablePage;
8+
const dns_1 = __importDefault(require("dns"));
9+
function isAddressUnreachableError(host) {
10+
return new Promise((resolve, reject) => {
11+
dns_1.default.lookup(host, (err, address) => {
12+
if (err) {
13+
if (err.code === 'ENOTFOUND') {
14+
resolve(true);
15+
}
16+
else {
17+
reject(err);
18+
}
19+
}
20+
else {
21+
resolve(false);
22+
}
23+
});
24+
});
25+
}
26+
function dataToServeUnreachablePage(host) {
27+
return {
28+
status: 502,
29+
contentType: 'text/html',
30+
body: `
31+
<!DOCTYPE html>
32+
<html lang="en">
33+
<head>
34+
<meta charset="UTF-8">
35+
<title>ERR_NAME_NOT_RESOLVED</title>
36+
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
37+
<style>
38+
body {
39+
background-color: #f2f2f2;
40+
color: #333;
41+
font-family: 'Roboto', sans-serif;
42+
margin: 0;
43+
padding: 0;
44+
}
45+
.container {
46+
max-width: 600px;
47+
margin: 100px auto;
48+
padding: 20px;
49+
text-align: center;
50+
}
51+
.sad-face {
52+
font-size: 80px;
53+
margin-bottom: 20px;
54+
}
55+
h1 {
56+
font-size: 24px;
57+
font-weight: normal;
58+
margin-bottom: 10px;
59+
}
60+
p {
61+
font-size: 16px;
62+
color: #666;
63+
}
64+
@media (max-width: 600px) {
65+
.container {
66+
margin-top: 50px;
67+
padding: 10px;
68+
}
69+
.sad-face {
70+
font-size: 60px;
71+
}
72+
}
73+
</style>
74+
</head>
75+
<body>
76+
<div class="container">
77+
<div class="sad-face">:(</div>
78+
<h1>This site can’t be reached</h1>
79+
<p>The webpage at <strong>${host}/</strong> might be temporarily down or it may have moved permanently to a new web address.</p>
80+
<p><strong>ERR_NAME_NOT_RESOLVED</strong></p>
81+
</div>
82+
</body>
83+
</html>
84+
`.trim()
85+
};
86+
}

dist/components/proxy-middleware/index.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ctx_rq_namespace_1 = __importDefault(require("./helpers/ctx_rq_namespace")
1717
const http_helpers_1 = require("./helpers/http_helpers");
1818
const constants_1 = require("./constants");
1919
const requestly_core_1 = require("@requestly/requestly-core");
20+
const handleUnreachableAddress_1 = require("./helpers/handleUnreachableAddress");
2021
// import SSLProxyingConfigFetcher from "renderer/lib/fetcher/ssl-proxying-config-fetcher";
2122
// import SSLProxyingManager from "../ssl-proxying/ssl-proxying-manager";
2223
exports.MIDDLEWARE_TYPE = {
@@ -99,10 +100,34 @@ class ProxyMiddlewareManager {
99100
if (!ctx.rq.request_finished) {
100101
logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
101102
}
102-
else {
103-
console.log("Expected Error after early termination of request: ", err);
103+
}
104+
else if (kind === "PROXY_TO_SERVER_REQUEST_ERROR") {
105+
try {
106+
const host = (0, proxy_ctx_helper_1.get_request_url)(ctx);
107+
const isAddressUnreachable = await (0, handleUnreachableAddress_1.isAddressUnreachableError)(host);
108+
if (isAddressUnreachable) {
109+
const { status, contentType, body } = (0, handleUnreachableAddress_1.dataToServeUnreachablePage)(host);
110+
ctx.proxyToClientResponse.writeHead(status, http_1.default.STATUS_CODES[status], {
111+
"Content-Type": contentType,
112+
"x-rq-error": "ERR_NAME_NOT_RESOLVED"
113+
});
114+
ctx.proxyToClientResponse.end(body);
115+
ctx.rq.set_final_response({
116+
status_code: status,
117+
headers: { "Content-Type": contentType },
118+
body: body,
119+
});
120+
logger_middleware.send_network_log(ctx, rules_middleware.action_result_objs, requestly_core_1.CONSTANTS.REQUEST_STATE.COMPLETE);
121+
return;
122+
}
123+
}
124+
catch (error) {
125+
console.error("Error checking address:", error);
104126
}
105127
}
128+
else {
129+
console.log("Expected Error after early termination of request: ", err);
130+
}
106131
return callback();
107132
});
108133
let request_body_chunks = [];

dist/components/proxy-middleware/rule_action_processor/handle_mixed_response.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ declare function handleMixedResponse(ctx: any, destinationUrl: any): Promise<{
1212
status: boolean;
1313
response_data: {
1414
headers: {
15-
"Content-Type": any;
15+
"content-type": any;
1616
"Content-Length": number;
1717
"Cache-Control": string;
1818
} | {
1919
"Cache-Control": string;
20-
"Content-Type"?: undefined;
20+
"content-type"?: undefined;
2121
"Content-Length"?: undefined;
2222
};
2323
status_code: number;

dist/components/proxy-middleware/rule_action_processor/handle_mixed_response.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ const handleMixedResponse = async (ctx, destinationUrl) => {
7676
const mimeType = mime.lookup(path);
7777
const bodyContent = buffers.toString("utf-8"); // assuming utf-8 encoding
7878
const headers = mimeType ? {
79-
"Content-Type": mimeType,
79+
"content-type": mimeType,
8080
"Content-Length": Buffer.byteLength(bodyContent),
8181
"Cache-Control": "no-cache"
8282
} : {
8383
"Cache-Control": "no-cache"
8484
};
85+
headers["access-control-allow-origin"] = "*";
86+
headers["access-control-allow-credentials"] = "true";
87+
headers["access-control-allow-methods"] = "*";
88+
headers["access-control-allow-headers"] = "*";
8589
return {
8690
status: true,
8791
response_data: {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestly/requestly-proxy",
3-
"version": "1.3.9",
3+
"version": "1.3.10",
44
"description": "Proxy that gives superpowers to all the Requestly clients",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)