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_fullscan_frequency = "10"
# sync_root_files = "false"
# user_agent = ""

View file

@ -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.

View file

@ -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:

View file

@ -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