Skip to content

Commit 3a7ed30

Browse files
committed
Report the upload settings to the server
Uploads now carry the client's upload configuration as X-UDC-* headers, built by the new UploadSettings default method getReportedPreferences(). Nothing about the user or their work is reported.
1 parent 6bb16d6 commit 3a7ed30

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

org.eclipse.epp.usagedata.recording/src/org/eclipse/epp/usagedata/internal/recording/settings/UploadSettings.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
*******************************************************************************/
1111
package org.eclipse.epp.usagedata.internal.recording.settings;
1212

13+
import java.util.Collections;
14+
import java.util.Map;
15+
1316
import org.eclipse.epp.usagedata.internal.recording.filtering.NullFilter;
1417
import org.eclipse.epp.usagedata.internal.recording.filtering.UsageDataEventFilter;
1518

@@ -49,4 +52,15 @@ public interface UploadSettings {
4952

5053
public abstract String getUserAgent();
5154

55+
/**
56+
* This method answers the settings that should travel with an upload, so
57+
* that a server can tell how the client that sent it was configured. Keys
58+
* become {@code X-UDC-<key>} headers. The default is to send nothing.
59+
*
60+
* @return the settings to report, never <code>null</code>.
61+
*/
62+
public default Map<String, String> getReportedPreferences() {
63+
return Collections.emptyMap();
64+
}
65+
5266
}

org.eclipse.epp.usagedata.recording/src/org/eclipse/epp/usagedata/internal/recording/settings/UsageDataRecordingSettings.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.io.Writer;
2020
import java.util.ArrayList;
2121
import java.util.Comparator;
22+
import java.util.LinkedHashMap;
2223
import java.util.List;
24+
import java.util.Map;
2325
import java.util.UUID;
2426
import java.util.concurrent.TimeUnit;
2527

@@ -509,6 +511,29 @@ private boolean hasExplicitValue(IPreferenceStore store, String key) {
509511
return store.contains(key) && !store.isDefault(key);
510512
}
511513

514+
/**
515+
* This method answers the settings that travel with an upload. It reports
516+
* how uploading is configured, never anything about the user or what they
517+
* were doing.
518+
*/
519+
public Map<String, String> getReportedPreferences() {
520+
Map<String, String> reported = new LinkedHashMap<String, String>();
521+
reported.put("upload-mode", uploadModeName(getUploadMode())); //$NON-NLS-1$
522+
reported.put("upload-period-days", String.valueOf(getPeriodBetweenUploads() / (24 * 60 * 60 * 1000))); //$NON-NLS-1$
523+
reported.put("filter-eclipse-only", String.valueOf(getPreferencesStore().getBoolean(FILTER_ECLIPSE_BUNDLES_ONLY_KEY))); //$NON-NLS-1$
524+
reported.put("filter-bundle-events", String.valueOf(getPreferencesStore().getBoolean(FILTER_BUNDLE_EVENTS_KEY))); //$NON-NLS-1$
525+
reported.put("retention-days", String.valueOf(UPLOAD_FILE_RETENTION_DAYS)); //$NON-NLS-1$
526+
return reported;
527+
}
528+
529+
private String uploadModeName(int mode) {
530+
switch (mode) {
531+
case UPLOAD_MODE_AUTOMATIC: return "automatic"; //$NON-NLS-1$
532+
case UPLOAD_MODE_MANUAL: return "manual"; //$NON-NLS-1$
533+
default: return "ask"; //$NON-NLS-1$
534+
}
535+
}
536+
512537
public void setUploadMode(int mode) {
513538
getPreferencesStore().setValue(UPLOAD_MODE_KEY, mode);
514539
UsageDataRecordingActivator.getDefault().savePluginPreferences();

org.eclipse.epp.usagedata.recording/src/org/eclipse/epp/usagedata/internal/recording/uploading/BasicUploader.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.time.Duration;
3535
import java.util.ArrayList;
3636
import java.util.List;
37+
import java.util.Map;
3738
import java.util.UUID;
3839

3940
import org.eclipse.core.runtime.IProgressMonitor;
@@ -82,6 +83,12 @@ public class BasicUploader extends AbstractUploader {
8283

8384
private static final String USER_AGENT = "User-Agent"; //$NON-NLS-1$
8485

86+
/**
87+
* The prefix for the headers that report how the client is configured, one
88+
* header per entry of {@link UploadSettings#getReportedPreferences()}.
89+
*/
90+
private static final String PREFERENCE_HEADER_PREFIX = "X-UDC-"; //$NON-NLS-1$
91+
8592
private boolean uploadInProgress = false;
8693

8794
private ListenerList responseListeners = new ListenerList();
@@ -203,6 +210,10 @@ UploadResult doUpload(IProgressMonitor monitor) throws Exception {
203210
.timeout(Duration.ofMillis(getSocketTimeout()))
204211
.POST(BodyPublishers.ofByteArray(multipartBody));
205212

213+
for (Map.Entry<String, String> preference : getSettings().getReportedPreferences().entrySet()) {
214+
requestBuilder.header(PREFERENCE_HEADER_PREFIX + preference.getKey(), preference.getValue());
215+
}
216+
206217
boolean loggingServerActivity = getSettings().isLoggingServerActivity();
207218
if (loggingServerActivity) {
208219
requestBuilder.header("LOGGING", "true"); //$NON-NLS-1$ //$NON-NLS-2$

0 commit comments

Comments
 (0)