# Extend http request node output for https requests

**URL:** https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956
**Category:** Feature Requests
**Tags:** http-request
**Created:** [7 October 2021 06:57 UTC](https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956 "2021-10-07T06:57:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mailsvb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mailsvb/32/49103_2.png) [@mailsvb](https://discourse.nodered.org/u/mailsvb)
#### Post date: [7 October 2021 06:57 UTC](https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956/1 "2021-10-07T06:57:42Z")

</div>

Hi,  
as per the contribution guidelines, I would like to raise this topic here.

I would like to suggest to extend the ouput of the http request node, when doing https requests, with the peer certificate information (which is provided in the socket object of the response).

Personally, I have a use case where I want to monitor the lifetime of a certificate, when sending requests to specific servers.

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [7 October 2021 09:20 UTC](https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956/2 "2021-10-07T09:20:56Z")

</div>

As a concept it sounds OK.

A couple of things we should probably work out up front would be what exactly would be exposed, where and if it should be optional.

- I think it should be optional, but not sure if it should be toggled in the http-request node or in the tls config node (this is shared with other nodes, but getting server details may apply to other nodes as well, but the implementation of the certificate retrieval would still have to be in each node.)
- An object msg.peerCertificate with the output of [TLSSocket.getPeerCertifiate()](https://nodejs.org/api/tls.html#tls_tlssocket_getpeercertificate_detailed)?

Having said all that a really quick test with the got library we use in the http-request node is not promising

```auto
const got = require('got')

got('https://www.hardill.me.uk',{})
.then( res => {
        console.log("good")
        console.log(res.socket.getPeerCertificate())
})
.catch(err => {
        console.log(err)
})

```

returns `null` implying that the socket has already been destroyed by the time it's passed to the response handler.

---

<div class="post-metadata">

### Author: ![mailsvb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mailsvb/32/49103_2.png) [@mailsvb](https://discourse.nodered.org/u/mailsvb)
#### Post date: [7 October 2021 13:44 UTC](https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956/3 "2021-10-07T13:44:49Z")

</div>

My suggestion would be to make it pure optional (not configurable). As you said, it would need to be introduced to all nodes that handle a TLS connection.  
We could simply add the object to msg.peerCertificate

In regards to how to get the information at all. I was having success when turning got to use the stream API. This way we get notified on the secureConnect event and can store the certificate data.

```auto
const got = require('got')

const g = got('https://www.hardill.me.uk',{ "isStream": true })
g.on('response', res => {
  console.log(res.statusCode)
});
g.on('socket', (socket) => {
  socket.on('secureConnect', () => console.log(socket.getPeerCertificate()))
})
g.on('error', err => {
  console.log(err)
});

```

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [7 October 2021 15:49 UTC](https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956/4 "2021-10-07T15:49:39Z")

</div>

This seems like a fairly specialist need and wouldn't likly be needed by everyone - wouldn't it be better as a separate node?

---

<div class="post-metadata">

### Author: ![mailsvb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mailsvb/32/49103_2.png) [@mailsvb](https://discourse.nodered.org/u/mailsvb)
#### Post date: [7 October 2021 21:12 UTC](https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956/5 "2021-10-07T21:12:52Z")

</div>

I did this a while ago. I used the http request node as a starting point and created a separate node ([node-red-contrib-https - npm](https://www.npmjs.com/package/node-red-contrib-https)). Since then, the http request node has evolved. I like the extended features and options the http request node has received.  
IMHO it would be simpler to extend the existing node. Especially, since it is only about information that is anyhow available already.

---

<div class="post-metadata">

### Author: ![mailsvb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mailsvb/32/49103_2.png) [@mailsvb](https://discourse.nodered.org/u/mailsvb)
#### Post date: [7 October 2021 21:35 UTC](https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956/6 "2021-10-07T21:35:09Z")

</div>

I have created a draft of the proposed changes:

> <https://github.com/node-red/node-red/pull/3174>
>
> \<!--
> \## Before you hit that Submit button....
> 
> Please read our \[contribution …guidelines\](https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md)
> before submitting a pull-request.
> 
> \## Types of changes
> 
> What types of changes does your code introduce?
> Put an \`x\` in the boxes that apply
> \--\>
> 
> \- \[\] Bugfix (non-breaking change which fixes an issue)
> \- \[\] New feature (non-breaking change which adds functionality)
> 
> \<!--
> If you want to raise a pull-request with a new feature, or a refactoring
> of existing code, it \*\*may well get rejected\*\* if it hasn't been discussed on
> the \[forum\](https://discourse.nodered.org) or
> \[slack team\](https://nodered.org/slack) first.
> 
> \--\>
> 
> \## Proposed changes
> 
> 
> 
> \## Checklist
> 
> 
> \- \[\] I have read the \[contribution guidelines\](https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md)
> \- \[\] For non-bugfix PRs, I have discussed this change on the forum/slack team.
> \- \[\] I have run \`grunt\` to verify the unit tests pass
> \- \[\] I have added suitable unit tests to cover the new/changed functionality

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [6 December 2021 21:35 UTC](https://discourse.nodered.org/t/extend-http-request-node-output-for-https-requests/51956/7 "2021-12-06T21:35:26Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
