Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the HTTP User-Agent when using Search::Elasticsearch?

I'm using 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 } } },
  },
);

This works ok, but I'd like to set the HTTP User-Agent header to a custom value so my requests can be identified if there's a problem. How do I do that with Search::Elasticsearch?

like image 865
cjm Avatar asked Nov 20 '25 00:11

cjm


1 Answers

You can pass arguments to the handle constructor using handle_args. So for the default HTTP::Tiny you would use agent:

my $es = Search::Elasticsearch->new(
  cxn_pool => 'Static::NoPing',
  nodes    => 'api.metacpan.org:80',
  handle_args => { agent => "youragent/0.1" },
);
like image 118
Ben Grimm Avatar answered Nov 22 '25 16:11

Ben Grimm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!