Skip to content

Add metadata headers to responses. #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const numCPUs = require('os').cpus().length;
const PROXY_PORT = process.env.PROXY_PORT || 8080;
const WS_PORT = process.env.WS_PORT || 4343;
const API_SERVER_PORT = process.env.API_SERVER_PORT || 8118;
const ADD_METADATA_HEADERS = process.env.ADD_METADATA_HEADERS !== "0";
const SERVER_VERSION = '1.0.0';

const RPC_CALL_TABLE = {
Expand Down Expand Up @@ -318,13 +319,18 @@ const options = {
// For connection errors
if (!response) {
logit(`[${auth_details.id}][${auth_details.name}] A connection error occurred while requesting ${requestDetail._req.method} ${requestDetail.url}`);
const error_header = {
'Content-Type': 'text/plain',
'X-Frame-Options': 'DENY'
};
if (ADD_METADATA_HEADERS) {
error_header['X-CC-Bot-Name'] = auth_details.name;
error_header['X-CC-Bot-Id'] = auth_details.browser_id;
}
return {
response: {
statusCode: 503,
header: {
'Content-Type': 'text/plain',
'X-Frame-Options': 'DENY'
},
header: error_header,
body: (new Buffer(`CursedChrome encountered an error while requesting the page.`))
}
};
Expand All @@ -339,6 +345,11 @@ const options = {
delete response.headers['content-encoding'];
}

if (ADD_METADATA_HEADERS) {
response.headers['X-CC-Bot-Name'] = auth_details.name;
response.headers['X-CC-Bot-Id'] = auth_details.browser_id;
}

return {
response: {
statusCode: response.status,
Expand Down