Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling iface.httpAgent() multiple times breaks http requests #350

Closed
mStirner opened this issue Dec 16, 2023 · 0 comments
Closed

Calling iface.httpAgent() multiple times breaks http requests #350

mStirner opened this issue Dec 16, 2023 · 0 comments
Labels
bug Something that should not be like that component:devices

Comments

@mStirner
Copy link
Member

let iface = ...;
let {host, port} = iface.settings;
let agent1 = iface.httpAgent();
let agent2 = iface.httpAgent();

request(`http://${host}:${port}/shelly`, {
    agent1
}, (err, result) => {
    console.log("HTTP REquest /shelly", err || result.body);
});


request(`http://${host}:${port}/settings`, {
    agent2
}, (err, result) => {
    console.log("HTTP REquest /settings", err || result.body);
});

This breaks http requests. A quick fix in the class.interface.js:

let agentCreated = null;

...

    httpAgent(options = {}) {

        if (agentCreated) {
            return agentCreated;
        }

        ...

        agentCreated = agent;
        return agent;

    }

Solves it.

Is there a better way?

@mStirner mStirner added component:devices bug Something that should not be like that labels Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that should not be like that component:devices
Projects
None yet
Development

No branches or pull requests

1 participant