mirror of
https://github.com/RubyMetric/chsrc
synced 2025-09-08 07:34:42 +08:00
feat: custom_user_agent
This commit is contained in:
parent
1ea20097ad
commit
f2a50d0963
9
lib/xy.h
9
lib/xy.h
@ -696,7 +696,7 @@ _xy_log_brkt (int level, const char *prompt1, const char *prompt2, const char *c
|
||||
* 由于目标行会被返回出来,所以 iter_func() 并不执行目标行,只会执行遍历过的行
|
||||
*/
|
||||
static char *
|
||||
xy_run_iter (const char *cmd, unsigned long n, void (*iter_func) (const char *))
|
||||
xy_run_iter (const char *cmd, unsigned long n, bool (*iter_func) (const char *))
|
||||
{
|
||||
const int size = 512;
|
||||
char *buf = (char *) malloc (size);
|
||||
@ -722,7 +722,10 @@ xy_run_iter (const char *cmd, unsigned long n, void (*iter_func) (const char *
|
||||
break;
|
||||
if (iter_func)
|
||||
{
|
||||
iter_func (buf);
|
||||
if (iter_func (buf)) {
|
||||
pclose (stream);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -927,4 +930,4 @@ xy_parent_dir (const char *path)
|
||||
return dir;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -80,7 +80,6 @@ bool chsrc_in_no_color_mode(){return ProgMode.NoColorMode;}
|
||||
static bool in_measure_mode(){return ProgMode.MeasureMode;}
|
||||
static bool in_ipv6_mode(){return ProgMode.Ipv6Mode;}
|
||||
static bool in_dry_run_mode(){return ProgMode.DryRunMode;}
|
||||
static bool in_custom_user_agent_mode(){return false;}
|
||||
|
||||
/**
|
||||
* Target Group mode (相反则称为 standalone mode)
|
||||
@ -132,7 +131,8 @@ ProgStatus =
|
||||
{
|
||||
.leader_selected_index = -1,
|
||||
.chgtype = ChgType_Auto,
|
||||
.chsrc_run_faas = false
|
||||
.chsrc_run_faas = false,
|
||||
.user_agent = user_agent
|
||||
};
|
||||
|
||||
|
||||
@ -603,15 +603,6 @@ measure_speed_for_url (void *url)
|
||||
ipv6 = "--ipv6";
|
||||
}
|
||||
|
||||
char *user_agent = NULL;
|
||||
if (in_custom_user_agent_mode())
|
||||
{
|
||||
user_agent = strdup("maven/3.9.11");
|
||||
}
|
||||
else
|
||||
{
|
||||
user_agent = xy_2strjoin("chsrc/", Chsrc_Version);
|
||||
}
|
||||
char *os_devnull = xy_os_devnull;
|
||||
|
||||
/**
|
||||
@ -620,11 +611,10 @@ measure_speed_for_url (void *url)
|
||||
char *curl_cmd = xy_strjoin (10, "curl -qsL ", ipv6,
|
||||
" -o ", os_devnull,
|
||||
" -w \"%{http_code} %{speed_download}\" -m", time_sec,
|
||||
" -A ", user_agent, " ", url);
|
||||
" -A ", ProgStatus.user_agent, " ", url);
|
||||
|
||||
// chsrc_info (xy_2strjoin ("测速命令 ", curl_cmd));
|
||||
char *curl_buf = xy_run (curl_cmd, 0);
|
||||
free(user_agent);
|
||||
return curl_buf;
|
||||
}
|
||||
|
||||
@ -1077,7 +1067,11 @@ chsrc_determine_chgtype (ChgType_t type)
|
||||
ProgStatus.chgtype = chsrc_in_reset_mode() ? ChgType_Reset : type;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
chsrc_custom_user_agent (*char user_agent)
|
||||
{
|
||||
ProgStatus.user_agent = user_agent;
|
||||
}
|
||||
|
||||
#define MSG_EN_PUBLIC_URL "If the URL you specify is a public service, you are invited to contribute: chsrc issue"
|
||||
#define MSG_CN_PUBLIC_URL "若您指定的URL为公有服务,邀您参与贡献: chsrc issue"
|
||||
|
@ -104,6 +104,10 @@ pl_java_getsrc (char *option)
|
||||
}
|
||||
|
||||
|
||||
void use_custom_user_agent() {
|
||||
chsrc_custom_user_agent("Maven/3.9.11")
|
||||
}
|
||||
|
||||
/**
|
||||
* @consult https://developer.aliyun.com/mirror/maven
|
||||
*/
|
||||
@ -114,7 +118,7 @@ pl_java_setsrc (char *option)
|
||||
pl_java_check_cmd (&maven_exist, &gradle_exist, &maven_daemon_exist);
|
||||
|
||||
use_this_source(pl_java);
|
||||
|
||||
use_custom_user_agent();
|
||||
if (maven_exist)
|
||||
{
|
||||
char *file = xy_str_gsub (RAWSTR_pl_java_maven_config, "@1@", source.mirror->code);
|
||||
|
@ -52,7 +52,7 @@ pl_ruby_getsrc (char *option)
|
||||
chsrc_run ("bundle config get mirror.https://rubygems.org", RunOpt_Default);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
pl_ruby_remove_gem_source (const char *source)
|
||||
{
|
||||
char *cmd = NULL;
|
||||
@ -61,6 +61,7 @@ pl_ruby_remove_gem_source (const char *source)
|
||||
cmd = xy_2strjoin ("gem sources -r ", source);
|
||||
chsrc_run (cmd, RunOpt_Default);
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,4 +106,4 @@ void
|
||||
pl_ruby_resetsrc (char *option)
|
||||
{
|
||||
pl_ruby_setsrc (option);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user