Skip to content
New issue

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

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

Already on GitHub? # to your account

add support for adding a custom http(s) agent #875

Merged
merged 1 commit into from
Oct 6, 2016

Conversation

jasisk
Copy link
Contributor

@jasisk jasisk commented Oct 6, 2016

Node, by default, uses a hardcoded list of CAs instead of the system CAs. In order to use a CA that is not on that list, you have to hack it into the list by patching the global https agent. Unfortunately, superagent explicitly turns off the global agent which makes patching it a no-op. So this PR adds the ability to supply the CA for superagent as an option.

@fehguy fehguy merged commit fe1cfbc into swagger-api:master Oct 6, 2016
@fehguy fehguy modified the milestone: v2.1.23 Oct 13, 2016
stanislav-polishchuk added a commit to stanislav-polishchuk/swagger-js that referenced this pull request Oct 17, 2016
…nt instance). For some resons implementation in previous pull request swagger-api#875, work only for first request, next ones don't use agent  and fails with 403
stanislav-polishchuk added a commit to stanislav-polishchuk/swagger-js that referenced this pull request Oct 17, 2016
…nt instance). For some resons implementation in previous pull request swagger-api#875, work only for first request, next ones don't use agent  and fails with 403
@stanislav-polishchuk
Copy link
Contributor

Hi @jasisk, i have some problem with your implementation of custom agent. It basically work only for first request to remote petstore. So i have implemented it in slightly different way (passing not agent instance but just options object for supergent), and it start working for me.

My question is how do you use your implementation? Because problem might be not in implementation itself, in a way that i am use it.

return new Swagger({
            url: "http://petstore.swagger.io/v2/swagger.json",
            usePromise: true,
            connectionAgent: {
                 rejectUnauthorized: false,
                 key: "/certs/example.key",
                 cert: "/certs/example.pem",
                 ca: ["/certs/example.ca.pem"]
            }})
            .then(_client => {
                //working with client
            })
            .catch(error => {
                const errMsg = `Unable to configure swagger models for ${prefix}. ${error.message}`;
                logger.error(errMsg);
            });

and the output is following:

    superagent GET https://localhost:8080/api-docs +0ms
    superagent GET https://localhost:8080/api-docs -> 200 +3s
    superagent GET https://localhost:8080/api-docs/one +12ms
    superagent GET https://localhost:8080/api-docs/two +2ms
    superagent GET https://localhost:8080/api-docs/three +1ms
    superagent GET https://localhost:8080/api-docs/one -> 403 +614ms
    superagent GET https://localhost:8080/api-docs/two -> 403 +11ms
    superagent GET https://localhost:8080/api-docs/three -> 403 +2ms

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants