Skip to content

Commit

Permalink
Update the user agent for debug log requests
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jul 19, 2018
1 parent 57107d9 commit 0e49749
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
2 changes: 2 additions & 0 deletions debug_log_preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const config = url.parse(window.location.toString(), true).query;
const { locale } = config;
const localeMessages = ipcRenderer.sendSync('locale-data');

window.getVersion = () => config.version;

window.theme = config.theme;
window.i18n = i18n.setup(locale, localeMessages);

Expand Down
13 changes: 11 additions & 2 deletions js/modules/debuglogs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-env node */
/* global window */

const FormData = require('form-data');
const got = require('got');

const BASE_URL = 'https://debuglogs.org';
const VERSION = window.getVersion();
const USER_AGENT = `Signal Desktop ${VERSION}`;

// Workaround: Submitting `FormData` using native `FormData::submit` procedure
// as integration with `got` results in S3 error saying we haven’t set the
Expand All @@ -22,7 +25,12 @@ const submitFormData = (form, url) =>

// upload :: String -> Promise URL
exports.upload = async content => {
const signedForm = await got.get(BASE_URL, { json: true });
const signedForm = await got.get(BASE_URL, {
json: true,
headers: {
'user-agent': USER_AGENT,
},
});
const { fields, url } = signedForm.body;

const form = new FormData();
Expand All @@ -36,10 +44,11 @@ exports.upload = async content => {

const contentBuffer = Buffer.from(content, 'utf8');
const contentType = 'text/plain';
form.append('User-Agent', USER_AGENT);
form.append('Content-Type', contentType);
form.append('file', contentBuffer, {
contentType,
filename: 'signal-desktop-debug-log.txt',
filename: `signal-desktop-debug-log-${VERSION}.txt`,
});

// WORKAROUND: See comment on `submitFormData`:
Expand Down
5 changes: 3 additions & 2 deletions settings_preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ const config = url.parse(window.location.toString(), true).query;
const { locale } = config;
const localeMessages = ipcRenderer.sendSync('locale-data');

window.getVersion = () => config.version;
window.theme = config.theme;
window.i18n = i18n.setup(locale, localeMessages);

require('./js/logging');

// So far we're only using this for Signal.Types
const Signal = require('./js/modules/signal');

Expand Down Expand Up @@ -78,3 +77,5 @@ function makeSetter(name) {
ipcRenderer.send(`set-${name}`, value);
});
}

require('./js/logging');
18 changes: 0 additions & 18 deletions test/modules/debuglogs_test.js

This file was deleted.

0 comments on commit 0e49749

Please sign in to comment.