os11k created an issue (kamailio/kamailio#4369)

### Description

Can't get header in microhttpd, by using $mhttpd(h:header-name)

#### Reproduction

run kamailio with this kamaili.cfg:
```
#!KAMAILIO

####### Global Parameters #########
debug=3
log_stderror=yes

####### Modules Section ########
loadmodule "xlog.so"
loadmodule "microhttpd.so"

####### Module Parameters ########
modparam("microhttpd", "listen_port", 8280)

####### Event Routes ########
#event_route[microhttpd:request] {
#    xlog("L_INFO", "X-Test Header: $mhttpd(h:X-Test)\n");
#    mhttpd_reply("200", "OK", "text/plain", "Header received");
#}

event_route[microhttpd:request] {
      xlog("L_INFO", "Method: $mhttpd(method), URL: $mhttpd(url)\n");
      xlog("L_INFO", "Content-Type: $mhttpd(h:Content-Type)\n");
      xlog("L_INFO", "User-Agent: $mhttpd(h:User-Agent)\n");
      xlog("L_INFO", "X-Test: $mhttpd(h:X-Test)\n");
      mhttpd_reply("200", "OK", "text/plain", "Header received");
}
```

send curl request:
```
curl -H "X-Test: myvalue" http://localhost:8280/
```

Kamailio logs:
```
20(26) INFO: <script>: Method: GET, URL: /
20(26) INFO: <script>: Content-Type: <null>
20(26) INFO: <script>: User-Agent: <null>
20(26) INFO: <script>: X-Test: <null>
```

I expect to see `X-Test: myvalue` instead `X-Test: <null>`

### Possible Solutions
Cursor proposed this solution:
```
--- a/src/modules/microhttpd/microhttpd_mod.c
+++ b/src/modules/microhttpd/microhttpd_mod.c
@@ -270,6 +270,7 @@
 {
        struct sockaddr *srcaddr = NULL;
        const char *hdrval = NULL;
+       char hdrname[128];

        if(param == NULL) {
                return -1;
@@ -280,7 +281,13 @@
        }
        if(param->pvn.u.isname.type == PVT_HDR) {
+               int hdrlen = param->pvn.u.isname.name.s.len - 2;
+               if(hdrlen >= sizeof(hdrname)) {
+                       return pv_get_null(msg, param, res);
+               }
+               memcpy(hdrname, param->pvn.u.isname.name.s.s + 2, hdrlen);
+               hdrname[hdrlen] = '\0';
                hdrval = MHD_lookup_connection_value(_ksr_mhttpd_ctx.connection,
-                               MHD_HEADER_KIND, param->pvn.u.isname.name.s.s + 
2);
+                               MHD_HEADER_KIND, hdrname);
                if(hdrval == NULL) {
                        return pv_get_null(msg, param, res);
                }
```

with this solution I can see in logs:
```
20(26) INFO: <script>: Method: GET, URL: /
20(26) INFO: <script>: Content-Type: <null>
20(26) INFO: <script>: User-Agent: curl/8.5.0
20(26) INFO: <script>: X-Test: myvalue
```

### Additional Information

  * **Kamailio Version** - output of `kamailio -v`

```
version: kamailio 5.8.6 (x86_64/linux) 919575-dirty
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, 
USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, MEM_JOIN_FREE, Q_MALLOC, 
F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, 
USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES, 
TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_SEND_BUFFER_SIZE 
262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: 919575 -dirty
compiled on 17:45:55 Aug 15 2025 with gcc 12.2.0
```

* **Operating System**:

Debian Bookworm

```
uname -a
Linux kamailio 6.8.0-48-generic #48-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 
14:04:52 UTC 2024 x86_64 GNU/Linux
```


-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4369
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/issues/4...@github.com>
_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to