-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
request: Replace deprecated request module with net.request. #993
Conversation
Also, for the record, |
Let’s move discussion about (But to answer your questions in short: yes, we should eliminate |
4db9ce3
to
03cd989
Compare
e2b73ea
to
23405ae
Compare
The original functionality remains intact for me after the migration. Further, now we don't need certificate-util, I tested adding certificates to Chrome store and using |
Going with this approach, I think it will handle two dialog boxes. |
Let's keep getProxy for now? I feel it completes the the utility of a file like |
Disagree. There’s no point in keeping around code that won’t be used with |
I agree it won't be used with electron.net, however I disagree that keeping it could be worse. I disagree also that we should fire to anything that burns, houses, cars everything burns, I don't suppose we should set fire to them. Just because anything burns, we shouldn't burn them. |
Uh…unused code is not a house or a car. Unused code is a readability complication, a maintenance burden, a potential attack surface, and an all around waste of time and space. There are rare cases where unused code is useful for API symmetry or to help the type checker or something, but this isn’t one of them. This code should just go away. |
Yeah I was going for this, so that a util could have a set and get function. Since, we don't have it as an API explicitly, we could let it go then. One can always re-add it later if required. We can keep the commit that removes it :) |
We don’t have a set function and a get function here. A get function should return exactly the data that you put into a set function—symmetry. This |
65244fd
to
6c855f8
Compare
@andersk Can you review this for merging? |
app/main/request.ts
Outdated
session: Session | ||
}; | ||
|
||
return new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s try to extract the raw Promise
logic into minimal shared helper functions and lean on async
/await
as much as possible. With a small fix to the Electron typings in typings.d.ts
(justified by the documentation: “IncomingMessage
implements the Readable Stream interface”):
declare module 'electron' {
interface IncomingMessage extends NodeJS.ReadableStream {}
}
we can do this:
import getStream from 'get-stream';
async function fetchResponse(request: ClientRequest): Promise<IncomingMessage> {
return new Promise((resolve, reject) => {
request.on("response", resolve);
request.on("abort", reject);
request.on("error", reject);
request.end();
});
}
export async function _getServerSettings(…): Promise<ServerConf> {
const response = await fetchResponse(net.request({
url: domain + '/api/v1/server_settings',
session,
}));
if (response.statusCode !== 200) {
throw response; // maybe we want this to be an actual Error?
}
const {realm_name, realm_uri, realm_icon} = JSON.parse(await getStream.buffer(response));
…
}
app/main/request.ts
Outdated
return `${dir}/${hash >>> 0}${extension}`; | ||
}; | ||
|
||
export const _getServerSettings = async (domain: string, Session: Electron.session): Promise<ServerConf> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t capitalize the variable Session
.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This also seems to trigger an extremely unfortunate bug where one of the renderer processes goes into a 100% CPU loop that eventually consumes all available memory. I’m trying to debug this… |
The request module has been deprecated by electron and this commit replaces the same with net.request. The net api is a main process api and thus the functions have been moved for convention. Fixes: zulip#886 Co-authored-by: Anders Kaseorg <anders@zulip.com> Signed-off-by: Anders Kaseorg <anders@zulip.com>
net.request handles proxy by itself and moving away from request module makes request-util unused.
The function is now not used upon migration to electron's native net.request and thus is being removed
The bug had something to do with trying to serialize an entire |
Thanks @andersk. Though,
I didn't get this totally. Can you please explain it to me? |
Thanks, everyone 🤝 |
Version 5.4.0 and later use electron.net for all network requests (zulip#993), so custom certificates can now be configured in the same system certificate store that Chrome uses. https://zulip.com/help/custom-certificates#desktop Signed-off-by: Anders Kaseorg <anders@zulip.com>
Version 5.4.0 and later uses electron.net for all network requests (zulip#993), so custom certificates can now be configured in the same system certificate store that Chrome uses. https://zulip.com/help/custom-certificates#desktop Signed-off-by: Anders Kaseorg <anders@zulip.com>
Version 5.4.0 and later uses electron.net for all network requests (zulip#993), so custom certificates can now be configured in the same system certificate store that Chrome uses. https://zulip.com/help/custom-certificates#desktop Signed-off-by: Anders Kaseorg <anders@zulip.com>
Any background context you want to provide?
Fixes: #886
You have tested this PR on:
Checklist
We may think of a more appropriate and suitable name of the new added request.ts