Skip to content

Commit 706eb20

Browse files
committed
replace https bool with flags bitmask in http_connection
Convert the `https` boolean field to a flags-based approach using HTTP_CON_FLAG_HTTPS. This provides better extensibility for future connection state flags while maintaining existing HTTPS functionality. Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
1 parent 4e01ffd commit 706eb20

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/http.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static void on_connected(int sock, void *arg)
224224

225225
conn->sock = sock;
226226

227-
if (conn->https) {
227+
if (conn->flags & HTTP_CON_FLAG_HTTPS) {
228228
#ifdef SSL_SUPPORT
229229
conn->ssl = ssl_session_new(rtty->ssl_ctx, sock);
230230
if (!conn->ssl) {
@@ -299,9 +299,11 @@ void http_request(struct rtty *rtty, int len)
299299

300300
conn = (struct http_connection *)calloc(1, sizeof(struct http_connection));
301301
conn->rtty = rtty;
302-
conn->https = https;
303302
conn->active = ev_now(rtty->loop);
304303

304+
if (https)
305+
conn->flags |= HTTP_CON_FLAG_HTTPS;
306+
305307
memcpy(conn->addr, addr, 18);
306308

307309
data = buffer_put(&conn->wb, len);

src/http.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
#include "rtty.h"
2929

30+
enum {
31+
HTTP_CON_FLAG_HTTPS = 1 << 0
32+
};
33+
3034
struct http_connection {
3135
struct list_head head;
3236
struct rtty *rtty;
@@ -38,7 +42,7 @@ struct http_connection {
3842
ev_tstamp active;
3943
int sock;
4044
uint8_t addr[18]; /* upstream connection address: [port ip] */
41-
bool https;
45+
uint8_t flags;
4246
#ifdef SSL_SUPPORT
4347
bool ssl_negotiated;
4448
void *ssl;

0 commit comments

Comments
 (0)