Module: kamailio
Branch: master
Commit: 9a43631e1707490c0781f9d2d10055663ebcde44
URL:
https://github.com/kamailio/kamailio/commit/9a43631e1707490c0781f9d2d100556…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-04-10T08:07:30+02:00
nghttp2: store method in stream data
---
Modified: src/modules/nghttp2/nghttp2_server.c
Modified: src/modules/nghttp2/nghttp2_server.h
---
Diff:
https://github.com/kamailio/kamailio/commit/9a43631e1707490c0781f9d2d100556…
Patch:
https://github.com/kamailio/kamailio/commit/9a43631e1707490c0781f9d2d100556…
---
diff --git a/src/modules/nghttp2/nghttp2_server.c b/src/modules/nghttp2/nghttp2_server.c
index 38ae3673d46..dec339d7a15 100644
--- a/src/modules/nghttp2/nghttp2_server.c
+++ b/src/modules/nghttp2/nghttp2_server.c
@@ -179,6 +179,7 @@ static void delete_http2_stream_data(http2_stream_data *stream_data)
close(stream_data->fd);
}
free(stream_data->request_path);
+ free(stream_data->request_method);
free(stream_data);
}
@@ -436,6 +437,7 @@ static int on_header_callback(nghttp2_session *session,
{
http2_stream_data *stream_data;
const char PATH[] = ":path";
+ const char METHOD[] = ":method";
(void)flags;
(void)user_data;
@@ -446,15 +448,25 @@ static int on_header_callback(nghttp2_session *session,
}
stream_data = nghttp2_session_get_stream_user_data(
session, frame->hd.stream_id);
- if(!stream_data || stream_data->request_path) {
+ if(!stream_data) {
break;
}
if(namelen == sizeof(PATH) - 1
&& memcmp(PATH, name, namelen) == 0) {
size_t j;
+ if(stream_data->request_path) {
+ break;
+ }
for(j = 0; j < valuelen && value[j] != '?'; ++j)
;
stream_data->request_path = percent_decode(value, j);
+ } else if(namelen == sizeof(METHOD) - 1
+ && memcmp(METHOD, name, namelen) == 0) {
+ if(stream_data->request_method) {
+ break;
+ }
+ stream_data->request_method =
+ strndup((const char *)value, valuelen);
}
break;
}
@@ -497,8 +509,15 @@ static int on_request_recv(nghttp2_session *session,
_ksr_nghttp2_ctx.path.s = stream_data->request_path;
_ksr_nghttp2_ctx.path.len = strlen(_ksr_nghttp2_ctx.path.s);
- _ksr_nghttp2_ctx.srcip.s = session_data->client_addr;
- _ksr_nghttp2_ctx.srcip.len = strlen(_ksr_nghttp2_ctx.srcip.s);
+ if(stream_data->request_method) {
+ _ksr_nghttp2_ctx.method.s = stream_data->request_method;
+ _ksr_nghttp2_ctx.method.len = strlen(_ksr_nghttp2_ctx.method.s);
+ }
+
+ if(session_data->client_addr) {
+ _ksr_nghttp2_ctx.srcip.s = session_data->client_addr;
+ _ksr_nghttp2_ctx.srcip.len = strlen(_ksr_nghttp2_ctx.srcip.s);
+ }
ksr_event_route();
diff --git a/src/modules/nghttp2/nghttp2_server.h b/src/modules/nghttp2/nghttp2_server.h
index bb5e446631c..34e6155abfc 100644
--- a/src/modules/nghttp2/nghttp2_server.h
+++ b/src/modules/nghttp2/nghttp2_server.h
@@ -70,6 +70,7 @@ typedef struct http2_stream_data
{
struct http2_stream_data *prev, *next;
char *request_path;
+ char *request_method;
int32_t stream_id;
int fd;
} http2_stream_data;