Repository: electron
Issue: [Feature Request]: Add stream closed emitter to request parameter in registerStreamProtocol
Labels: enhancement :sparkles:

### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.

### Problem Description

Hello, I am writing a program that can cause a many number of local file requests and be canceled according to the user's input. So I used protocol's method in the main process and passed the file to the renderer process in the stream. The problem is that the main process does not close the stream when the request is canceled by the renderer process. The following error occurs: `EMFILE: too many open files`. The problem is that the open stream will not be closed over time and the file stream will not be opened on the next request. The error occurred in `Windows 10`, `Windows 11`, and `macOS Monterey 12.2`. [The Electron Fiddle project](https://github.com/lowfront/electron-protocol-stream-issue) where this error occurs.

Another way I tried was to open the Express server in the main process and provide the file as a stream. It seemed to work well, but over time, the open stream increased, and eventually the above error. So I manually closed the stream when a close event occurred in the request object of Express, and the problem of not closing unused streams was solved.
```js
const fileReadStream = fs.createReadStream(filePath);
req.on('close', () => fileReadStream .close());
```
I looked at the request object of registerStreamProtocol to apply the same method as Express to Electron, but I couldn't find a method to receive an event such as `on`. Shouldn't we add a method to detect events in the request to close the canceled stream?

### Proposed Solution

Any method that detects the closing of a request, as in the example of code in Express described above, is acceptable.
For example:
```js
protocol.registerStreamProtocol('img-stream', (request, callback) => {
  const stream = fs.createReadStream('c:/bigfile.gif');
  // 1
  request.on('close', () => stream.close());
  // 2
  request.onClose(() => stream.close());

  callback(stream);
});
```

If possible, I think it is better to provide a field where Electron can access the `http.ClientRequest` object in Node.js in `Electron.ProtocolRequest`.

### Alternatives Considered

Currently, I can't solve this problem only with Electron, so I put the stream in a queue of a set size every time I received a request, and I took the stream out of the queue and closed it manually whenever the number was exceeded. This method seems to have no problem using the program I create, but depending on the size of the queue I use, there is a problem that several unclosed streams may be wasting memory. If I use Express, I can close it exactly when the request is canceled, but I didn't want to open one more server. 

### Additional Information

Test os: Windows 10, macOS Monterey 12.2, Parallels Windows 11
Problem Reproduction: [link](https://github.com/lowfront/electron-protocol-stream-issue)
MacOS and Windows differ greatly in the maximum number of file streams that can be opened. Both have the same problem, but it is recommended to test it on Windows for quick problem identification.