diff --git a/config b/config index c1af5b12..b87a0473 100644 --- a/config +++ b/config @@ -30,3 +30,4 @@ # monitor_log_frequency = "5" # monitor_fullscan_frequency = "10" # sync_root_files = "false" +# user_agent = "" diff --git a/onedrive.1.in b/onedrive.1.in index 9a246698..26825e39 100644 --- a/onedrive.1.in +++ b/onedrive.1.in @@ -178,6 +178,11 @@ Only upload to OneDrive, do not sync changes from OneDrive locally .br Configuration file key: \fBupload_only\fP (default: \fBfalse\fP) .TP +\fB\-\-user\-agent\fP ARG +Set the used User Agent identifier +.br +Configuration file key: \fBuser_agent\fP (default: don't change) +.TP \fB\-v \-\-verbose\fP Print more details, useful for debugging. Given two times (or more) enables even more verbose debug statements. diff --git a/src/config.d b/src/config.d index 515cecaa..bb4bd3e4 100644 --- a/src/config.d +++ b/src/config.d @@ -37,6 +37,7 @@ final class Config stringValues["skip_dir"] = defaultSkipDir; stringValues["log_dir"] = "/var/log/onedrive/"; stringValues["drive_id"] = ""; + stringValues["user_agent"] = ""; boolValues["upload_only"] = false; boolValues["check_nomount"] = false; boolValues["check_nosync"] = false; @@ -292,6 +293,9 @@ final class Config "upload-only", "Only upload to OneDrive, do not sync changes from OneDrive locally", &boolValues["upload_only"], + "user-agent", + "Specify a User Agent string to the http client", + &stringValues["user_agent"], // duplicated from main.d to get full help output! "confdir", "Set the directory used to store the configuration files", @@ -430,7 +434,8 @@ void outputLongHelp(Option[] opt) "--single-directory", "--skip-file", "--source-directory", - "--syncdir" ]; + "--syncdir", + "--user-agent" ]; writeln(`OneDrive - a client for OneDrive Cloud Services Usage: diff --git a/src/onedrive.d b/src/onedrive.d index c087a56a..d48e98b0 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -98,7 +98,14 @@ final class OneDriveApi if (cfg.getValueBool("debug_https")) { http.verbose = true; .debugResponse = true; - } + } + + // Custom User Agent + if (cfg.getValueString("user_agent") != "") { + http.setUserAgent = cfg.getValueString("user_agent"); + } else { + http.setUserAgent = "OneDrive Client for Linux " ~ strip(import("version")); + } // What version of HTTP protocol do we use? // Curl >= 7.62.0 defaults to http2 for a significant number of operations