headers protection, textResponse support, improve logging

pull/807/head
Ryan Tharp 5 years ago
parent 47e87a4720
commit df1d032d96

@ -367,12 +367,17 @@ class LokiAppDotNetServerAPI {
return nodeFetch(urlObj, fetchOptions);
}
async _sendToProxy(endpoint, fetchOptions) {
async _sendToProxy(endpoint, pFetchOptions) {
const randSnode = await lokiSnodeAPI.getRandomSnodeAddress();
const url = `https://${randSnode.ip}:${randSnode.port}/file_proxy`;
const fetchOptions = pFetchOptions; // make lint happy
// safety issue with file server, just safer to have this
if (fetchOptions.headers === undefined) {
fetchOptions.headers = {};
}
const payloadObj = {
// I think this is a stream, we may need to collect it all?
body: fetchOptions.body, // might need to b64 if binary...
endpoint,
method: fetchOptions.method,
@ -446,7 +451,7 @@ class LokiAppDotNetServerAPI {
const txtResponse = await result.text();
if (txtResponse === 'Service node is not ready: not in any swarm; \n') {
// mark snode bad
log.warn('Marking random snode bad', randSnode);
log.warn(`Marking random snode bad, internet address ${randSnode.ip}:${randSnode.port}`);
lokiSnodeAPI.markRandomNodeUnreachable(randSnode);
// retry (hopefully with new snode)
// FIXME: max number of retries...
@ -563,7 +568,8 @@ class LokiAppDotNetServerAPI {
// always make sure this check is enabled
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 1;
txtResponse = await result.text();
response = JSON.parse(txtResponse);
// hrm cloudflare timeouts (504s) will be html...
response = options.textResponse ? txtResponse : JSON.parse(txtResponse);
}
} catch (e) {
if (txtResponse) {
@ -574,7 +580,7 @@ class LokiAppDotNetServerAPI {
`json: ${txtResponse}`
);
} else {
log.info(`serverRequest ${mode} error`, e.code, e.message);
log.info(`serverRequest ${mode} error`, e.code, e.message, 'atttempting connection to', url);
}
return {
err: e,

Loading…
Cancel
Save