Repository: louislam/uptime-kuma
File: server/model/monitor.js (JavaScript)

Code before:
                            tlsInfo = checkCertificate(tlsSocket);

                            tlsInfo.valid = tlsSocket.authorized || false;
                            await this.updateTlsInfo(tlsInfo);
                            this.prometheus?.update(null, tlsInfo);

                            if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
                                log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`);
                                await this.checkCertExpiryNotifications(tlsInfo);
                            }
                        });
                    });

                    log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
                    log.debug("monitor", `[${this.name}] Axios Request`);

                    // Make Request
                    let res = await this.makeAxiosRequest(options);

                    bean.msg = `${res.status} - ${res.statusText}`;
                    bean.ping = dayjs().valueOf() - startTime;

                    // fallback for if kelog event is not emitted, but we may still have tlsInfo,
                    // e.g. if the connection is made through a proxy
                    if (this.getUrl()?.protocol === "https:") {
                        if (tlsInfo.valid === undefined) {
                            const tlsSocket = res.request.res.socket;

                            if (tlsSocket) {
                                tlsInfo.valid = tlsSocket.authorized || false;
                                tlsInfo = checkCertificate(tlsSocket);
                                await this.updateTlsInfo(tlsInfo);

                                if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
                                    log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`);
                                    await this.checkCertExpiryNotifications(tlsInfo);
                                }
                            }
                        }
                    }

                    if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID === this.id) {
                        log.info("monitor", res.data);
                    }

                    if (this.type === "http") {
                        bean.status = UP;
                    } else if (this.type === "keyword") {

                        let data = res.data;


Review comment (suggestion):
nit: What do you think?
should we merge these two if statements into one line? (removing the one above which I can't comment on)

```suggestion
                    if (this.getUrl()?.protocol === "https:" && tlsInfo.valid === undefined) {
```

Code after:
                            tlsInfo = checkCertificate(tlsSocket);
                            tlsInfo.valid = tlsSocket.authorized || false;

                            await this.handleTlsInfo(tlsInfo);
                        });
                    });

                    log.debug("monitor", `[${this.name}] Axios Options: ${JSON.stringify(options)}`);
                    log.debug("monitor", `[${this.name}] Axios Request`);

                    // Make Request
                    let res = await this.makeAxiosRequest(options);

                    bean.msg = `${res.status} - ${res.statusText}`;
                    bean.ping = dayjs().valueOf() - startTime;

                    // fallback for if kelog event is not emitted, but we may still have tlsInfo,
                    // e.g. if the connection is made through a proxy
                    if (this.getUrl()?.protocol === "https:" && tlsInfo.valid === undefined) {
                        const tlsSocket = res.request.res.socket;

                        if (tlsSocket) {
                            tlsInfo = checkCertificate(tlsSocket);
                            tlsInfo.valid = tlsSocket.authorized || false;

                            await this.handleTlsInfo(tlsInfo);
                        }
                    }

                    if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID === this.id) {
                        log.info("monitor", res.data);
                    }

                    if (this.type === "http") {
                        bean.status = UP;
                    } else if (this.type === "keyword") {

                        let data = res.data;

                        // Convert to string for object/array
                        if (typeof data !== "string") {
                            data = JSON.stringify(data);
                        }

                        let keywordFound = data.includes(this.keyword);
                        if (keywordFound === !this.isInvertKeyword()) {
                            bean.msg += ", keyword " + (keywordFound ? "is" : "not") + " found";
                            bean.status = UP;
                        } else {
                            data = data.replace(/<[^>]*>?|[\n\r]|\s+/gm, " ").trim();
                            if (data.length > 50) {