Make user-agent string a configuration option (#673)

* Make user-agent string a configuration option
* Set default User-Agent to OneDrive Client for Linux v{version}
* Add 'user_agent' to default config file
This commit is contained in:
abraunegg 2019-09-24 16:42:40 +10:00 committed by GitHub
parent a1f4fec3cf
commit ca9a6b6ac0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 2 deletions

1
config
View file

@ -30,3 +30,4 @@
# monitor_log_frequency = "5" # monitor_log_frequency = "5"
# monitor_fullscan_frequency = "10" # monitor_fullscan_frequency = "10"
# sync_root_files = "false" # sync_root_files = "false"
# user_agent = ""

View file

@ -178,6 +178,11 @@ Only upload to OneDrive, do not sync changes from OneDrive locally
.br .br
Configuration file key: \fBupload_only\fP (default: \fBfalse\fP) Configuration file key: \fBupload_only\fP (default: \fBfalse\fP)
.TP .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 \fB\-v \-\-verbose\fP
Print more details, useful for debugging. Given two times (or more) Print more details, useful for debugging. Given two times (or more)
enables even more verbose debug statements. enables even more verbose debug statements.

View file

@ -37,6 +37,7 @@ final class Config
stringValues["skip_dir"] = defaultSkipDir; stringValues["skip_dir"] = defaultSkipDir;
stringValues["log_dir"] = "/var/log/onedrive/"; stringValues["log_dir"] = "/var/log/onedrive/";
stringValues["drive_id"] = ""; stringValues["drive_id"] = "";
stringValues["user_agent"] = "";
boolValues["upload_only"] = false; boolValues["upload_only"] = false;
boolValues["check_nomount"] = false; boolValues["check_nomount"] = false;
boolValues["check_nosync"] = false; boolValues["check_nosync"] = false;
@ -292,6 +293,9 @@ final class Config
"upload-only", "upload-only",
"Only upload to OneDrive, do not sync changes from OneDrive locally", "Only upload to OneDrive, do not sync changes from OneDrive locally",
&boolValues["upload_only"], &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! // duplicated from main.d to get full help output!
"confdir", "confdir",
"Set the directory used to store the configuration files", "Set the directory used to store the configuration files",
@ -430,7 +434,8 @@ void outputLongHelp(Option[] opt)
"--single-directory", "--single-directory",
"--skip-file", "--skip-file",
"--source-directory", "--source-directory",
"--syncdir" ]; "--syncdir",
"--user-agent" ];
writeln(`OneDrive - a client for OneDrive Cloud Services writeln(`OneDrive - a client for OneDrive Cloud Services
Usage: Usage:

View file

@ -100,6 +100,13 @@ final class OneDriveApi
.debugResponse = 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? // What version of HTTP protocol do we use?
// Curl >= 7.62.0 defaults to http2 for a significant number of operations // Curl >= 7.62.0 defaults to http2 for a significant number of operations
if (cfg.getValueBool("force_http_2")) { if (cfg.getValueBool("force_http_2")) {