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 4005706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:25:34+00:00 2026-05-20T08:25:34+00:00

I am trying to make a proxy server that gets a page from www.xxx.com

  • 0

I am trying to make a proxy server that gets a page from www.xxx.com for example, cache the response, and then send it to the requesting browser.

To do so, on the server I create an HTTP client that requests the page from xxx.com. The response is returned in the form of chunks (Buffers). Then, since the number of chunks is different according to the webpage, I put the chunks in an array of buffers. Then I send the elements of the array.

My problem is not all the chunks are sent successfully. Is there any other way I can cache the data before sending it? (I know that I can send the data directly, but I need to send the cache instead since I want to send it to more than one browser)

To save the chunks I use:

function getURL(u) {
     u = url.parse(u);
     var client = http.createClient(u.port || 80, u.hostname);
     var request = client.request('GET', '/', {
                            'Host': u.hostname,
                         });
     var cache ={ };
     cache.data = [];

     request.end();
     request.on('response', function(response) {
          cache.statusCode = response.statusCode;
          cache.headers = response.headers;

          response.on('data', function(chunk) {
               cache.data.push(chunk);
     }
}

to send the cache, i use:

function sendCache(response, cache) {
    var writeSuccess = [];
    response.writeHead(cache.statusCose, cache.headers);
    for (var i in cache.data) {
        // don't encode the data, leave it as it is
        writeSuccess[i] = response.write(cache.data[i], "binary");
        console.log("chunk " + i + " is of length " 
            + cache.data[i].length + ". Response success: " + writeSuccess[i]);
    }
}

Here I log the returned value of the response.write to check if it is successful or not. In the node.js API, it is not explained if this function returns something or not, but I just tried it out.

What I noticed, the response.write was sometimes true and then false for other chunks of the cache whereas if I directly send the response without caching, response.write of all chunks is true.

If anyone notices something wrong I am doing or does know a better way to cache the data (preferably in binary so that all non-ASCII characters will be cached to).

  • 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-20T08:25:35+00:00Added an answer on May 20, 2026 at 8:25 am

    In the latest release of Node.js (v 0.4.0), the issue of writing a response from buffer was solved. So by just updating to this version my problem was solved.

    However, one has to know that response.write may still give false, but this doesn’t mean that it is not sent, but not sent directly (leaky bucket concept). This is what I was able to conclude from the comment inside the node.js library (I hope I am correct).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a proxy server for logging and shaping traffic from sites
I'm trying make some stuff in jQuery using ASP.NET. But the ID from runat=server
I am trying to make a proof of concept ExtJS datagrid en route to
I'm trying to write milt-threaded HTTP proxy for learning C++/socket/HTTP I'm looking for a
I'm trying to use the Domain Auth Plugin to assign the Membership role to
I'm trying to model a request submission/ approval /completion scenario. I'm using a flowchart
I need to create a proxy class so i can communicate with a Java
Using lazy=true in my classes causes my application to work perfectly, but the performance
I've search the jquery site for this ...and I just can't find it. I'm

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.