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

  • SEARCH
  • Home
  • 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 8433145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:18:24+00:00 2026-06-10T06:18:24+00:00

I have this in my Node script (simplified for this question): var http =

  • 0

I have this in my Node script (simplified for this question):

var http = require("http"),
    url = require("url"),
    options = url.parse("http://example.com/"),
    moreOptions = url.parse("http://example.net/"),
    callback,
    request,
    moreDifferentRequest;

callback = function( res ) {
    console.log(res.socket._httpMessage._headers.host);
}

request = http.request( options, callback );
request.end();

moreDifferentRequest = http.request( moreDifferentOptions, callback );
moreDifferentRequest.end();

I’m grabbing the hostname from res.socket._httpMessage._headers.host because it does not exist in res.headers.

But the underscores give me pause. They say to me, “Hey, this is to be treated like a private property for internal use only by socket, so don’t read it, because it might totally get changed around in a later version and we’re not going to tell you.”

If I am right to think that I’m Doing It Wrong here, what is the correct way to get the hostname inside the callback? Or am I just totally misinterpreting the underscores and what I’m doing is fine?

  • 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-06-10T06:18:25+00:00Added an answer on June 10, 2026 at 6:18 am

    Yes, that’s exactly what they are trying to say.
    The right way would of course be public, documented APIs if that’s possible. But if it’s not possible, then you must do this and realize it’s on you if something breaks.


    Since you are sending the request, you can get the host header from:

    options.host
    

    HTTP responses don’t have a host header, it’s the client (you) that sends the host header in a request.


    With wrapper function:

    var http = require("http"),
        opts = require("url").parse( "http://stackoverflow.com" );
    
    
    function wrapper( options, callback ) {
        return function() {
            args = [].slice.call(arguments);
            args.push( options );
            return callback.apply( this, args );
        }
    }
    
    request = http.request( opts, wrapper(opts, function(response, options){
        console.log( options.host );
    }));
    
    request.end();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with drupal. I have this page something.com/node/13. Inside I have this script
I have this simple script : var exec = require('child_process').exec; exec('coffee -cw my_file.coffee', function(error,
So I have this script that reads the xml, modifies the selected node value
i have this js piece of code: <script language=JavaScript type=text/javascript> var sendReq = getXmlHttpRequestObject();
I have this piece of code: <textarea id=test style=width: 400px; height: 100px></textarea> <script> var
I have this URL format: http://localhost/find_retailers/index.html?modelCode=ABCD1234 I have an XML file consisting of: <products>
I have this kind of node in my xml document: <parent ...> <a .../>
I have this TreeView: Main Node Header=Main Sub Node Header=Sub1 Final Node Header=Item1 Final
I have this function in C: static Node* newNode(void* e){ Node n={e,NULL,NULL}; return &n;
i have this problem to find a particular xml node l have post this

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.