使用 Search::Elasticsearch 时如何设置 HTTP User-Agent?
How do I set the HTTP User-Agent when using Search::Elasticsearch?
我正在使用 Search::Elasticsearch to query MetaCPAN。
my $es = Search::Elasticsearch->new(
cxn_pool => 'Static::NoPing',
nodes => 'api.metacpan.org:80',
);
my $scroller = $es->scroll_helper(
index => 'v0',
type => 'release',
search_type => 'scan',
scroll => '2m',
size => $size,
body => {
fields => [qw(author archive date)],
query => { range => { date => { gte => $date } } },
},
);
这工作正常,但我想将 HTTP User-Agent header 设置为自定义值,以便在出现问题时识别我的请求。我如何用 Search::Elasticsearch 做到这一点?
您可以使用 handle_args
. So for the default HTTP::Tiny
将参数传递给 handle
构造函数,您将使用 agent
:
my $es = Search::Elasticsearch->new(
cxn_pool => 'Static::NoPing',
nodes => 'api.metacpan.org:80',
handle_args => { agent => "youragent/0.1" },
);
我正在使用 Search::Elasticsearch to query MetaCPAN。
my $es = Search::Elasticsearch->new(
cxn_pool => 'Static::NoPing',
nodes => 'api.metacpan.org:80',
);
my $scroller = $es->scroll_helper(
index => 'v0',
type => 'release',
search_type => 'scan',
scroll => '2m',
size => $size,
body => {
fields => [qw(author archive date)],
query => { range => { date => { gte => $date } } },
},
);
这工作正常,但我想将 HTTP User-Agent header 设置为自定义值,以便在出现问题时识别我的请求。我如何用 Search::Elasticsearch 做到这一点?
您可以使用 handle_args
. So for the default HTTP::Tiny
将参数传递给 handle
构造函数,您将使用 agent
:
my $es = Search::Elasticsearch->new(
cxn_pool => 'Static::NoPing',
nodes => 'api.metacpan.org:80',
handle_args => { agent => "youragent/0.1" },
);