question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

update socket class with missing address method

See original GitHub issue

Context

currently, I found nock and am trying to test out a http module flow. along the way, we require extracting the address() result object.

w/in the response, we have this event:

req.on( 'socket', ( socket ) => {
      console.log(socket);
      req[ '_socketAddr' ] = socket.address();
} );

What are you trying to do and how would you want to do it differently? Is it something you currently you cannot do? Is this related to an issue/problem?

In the case of our tests, because the method doesn’t exist, the test throws an exception/error, which causes the test to fail.

Alternatives I’d love to know of alternatives: like could I assign a mock/stub socket to contain that address method?

Can you achieve the same result doing it in an alternative way? Is the alternative considerable?

Currently I know no way to make this happen

Has the feature been requested before?

I do no think so

If the feature request is accepted, would you be willing to submit a PR?

Yes, I can give it a whirl 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mastermattcommented, Jul 24, 2019

The options param is meant to take the same values as http.request, which already (optionally) takes a port and family. But I have mixed feelings about adding new options like address. Would it be wrong to just hardcode 127.0.0.1?

Off the top of my head, something like this?

constructor(options) {
  // ... existing stuff
  this.remotePort = parseInt(options.port) || this.authorized ? 443 : 80
  this.remoteFamily = options.family === 6 ? 'IPv6' : 'IPv4'
  this.remoteAddress = options.family === 6 ? '::1' :  '127.0.0.1'
}

address() {
  return {
    port: this.remotePort,
    family: this.remoteFamily,
    address: this.remoteAddress
  }
}

Docs for the new attrs too.

0reactions
nockbotcommented, Oct 31, 2019

🎉 This issue has been resolved in version 11.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

Socket (Java Platform SE 7 ) - Oracle Help Center
This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines.
Read more >
Java Socket Program and symbol cant find in ... - Stack Overflow
1 Answer 1 ... You need to declare the socket outside the try block: Socket socket = null; try{ ... while(true) { socket...
Read more >
Socket Class (System.Net.Sockets) | Microsoft Learn
The Socket class provides a rich set of methods and properties for ... Initializes a new instance of the Socket class using the...
Read more >
socket — Low-level networking interface — Python 3.11.1 ...
Create a new socket using the given address family, socket type and protocol number. The address family should be AF_INET (the default), AF_INET6...
Read more >
A Guide to Java Sockets - Baeldung
We'll create the server application in a class called GreetServer.java with the following code. We'll include the main method and the global ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found