Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 401699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:03:28+00:00 2026-05-12T17:03:28+00:00

What is the easiest way (without opening a shell to curl and reading from

  • 0

What is the easiest way (without opening a shell to curl and reading from stdin) in Perl to stream from another HTTP resource? I’m assuming here that the HTTP resource I’m reading from is a potentially infinite stream (or just really, really long)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:03:29+00:00Added an answer on May 12, 2026 at 5:03 pm

    HTTP::Lite‘s request method allows you to specify a callback.

    The $data_callback parameter, if used, is a way to filter the data as it is received or to handle large transfers. It must be a function reference, and will be passed: a reference to the instance of the http request making the callback, a reference to the current block of data about to be added to the body, and the $cbargs parameter (which may be anything). It must return either a reference to the data to add to the body of the document, or undef.

    However, looking at the source, there seems to be a bug in sub request in that it seems to ignore the passed callback. It seems safer to use set_callback:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use HTTP::Lite;
    
    my $http = HTTP::Lite->new;
    $http->set_callback(\&process_http_stream);
    $http->http11_mode(1);
    
    $http->request('http://www.example.com/');
    
    sub process_http_stream {
        my ($self, $phase, $dataref, $cbargs) = @_;
        warn $phase, "\n";
        return;
    }
    

    Output:

    C:\Temp> ht
    connect
    content-length
    done-headers
    content
    content-done
    data
    done
    

    It looks like a callback passed to the request method is treated differently:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use HTTP::Lite;
    
    my $http = HTTP::Lite->new;
    $http->http11_mode(1);
    
    my $count = 0;
    $http->request('http://www.example.com/',
        \&process_http_stream,
        \$count,
    );
    
    sub process_http_stream {
        my ($self, $data, $times) = @_;
        ++$$times;
        print "$$times====\n$$data\n===\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would be the easiest way to separate the directory name from the file
What's the easiest way to convert a percentage to a color ranging from Green
What is the easiest way to merge XML from two distinct DOM Documents? Is
What's the easiest way to discover (without access to the source project) whether a
What is the easiest way vertically stack two HTML buttons without a table?
What's the easiest way to get all input fields inside a div without using
The easiest way to think of my question is to think of a single,
In TFS whats the easiest way of linking a backlog item to a large
Whats the best/easiest way to obtain a count of items within an IEnumerable collection
What would be the easiest way to be able to send and receive raw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.