Skip to content

Commit 086538a

Browse files
add support of CA for superagent as and options object (not https.Agent instance). For some resons implementation in previous pull request #875, work only for first request, next ones don't use agent and fails with 403
1 parent e4cb88d commit 086538a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,29 @@ var client = new SwaggerClient({
299299
});
300300
```
301301

302+
### Using custom http(s) agent
303+
In case if you need to sign all requests to petstore with custom certificate
304+
305+
```js
306+
var connectionAgent = {
307+
rejectUnauthorized: false,
308+
key: "/certs/example.key",
309+
cert: "/certs/example.pem",
310+
ca: ["/certs/example.ca.pem"]
311+
}
312+
313+
var client = new SwaggerClient({
314+
url: "http://petstore.swagger.io/v2/swagger.json",
315+
connectionAgent: connectionAgent,
316+
success: function() {
317+
// upon connect, fetch a pet and set contents to element "mydata"
318+
client.pet.getPetById({petId:1},{responseContentType: 'application/json'}, function(data) {
319+
document.getElementById("mydata").innerHTML = JSON.stringify(data.obj);
320+
});
321+
}
322+
});
323+
```
324+
302325
### How does it work?
303326
The swagger javascript client reads the swagger api definition directly from the server. As it does, it constructs a client based on the api definition, which means it is completely dynamic. It even reads the api text descriptions (which are intended for humans!) and provides help if you need it:
304327

lib/http.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ SuperagentHttpClient.prototype.execute = function (obj) {
215215
method = 'del';
216216
}
217217
var headers = obj.headers || {};
218-
var r = request[method](obj.url);
219218

220219
if (connectionAgent) {
221-
r.agent(connectionAgent);
220+
request = request.agent(connectionAgent);
222221
}
222+
223+
var r = request[method](obj.url);
223224

224225
if (timeout) {
225226
r.timeout(timeout);

0 commit comments

Comments
 (0)