| 1 |
NGHTTP2 Module |
| 2 |
|
| 3 |
Daniel-Constantin Mierla |
| 4 |
|
| 5 |
<[email protected]> |
| 6 |
|
| 7 |
Edited by |
| 8 |
|
| 9 |
Daniel-Constantin Mierla |
| 10 |
|
| 11 |
<[email protected]> |
| 12 |
|
| 13 |
Copyright © 2024 asipto.com |
| 14 |
__________________________________________________________________ |
| 15 |
|
| 16 |
Table of Contents |
| 17 |
|
| 18 |
1. Admin Guide |
| 19 |
|
| 20 |
1. Overview |
| 21 |
2. Dependencies |
| 22 |
|
| 23 |
2.1. Kamailio Modules |
| 24 |
2.2. External Libraries or Applications |
| 25 |
|
| 26 |
3. Parameters |
| 27 |
|
| 28 |
3.1. listen_addr (str) |
| 29 |
3.2. listen_port (str) |
| 30 |
3.3. event_callback (str) |
| 31 |
|
| 32 |
4. Functions |
| 33 |
|
| 34 |
4.1. nghttp2_reply(code, body) |
| 35 |
4.2. nghttp2_reply_header(name, value) |
| 36 |
|
| 37 |
5. Event Routes |
| 38 |
|
| 39 |
5.1. nghttp2:request |
| 40 |
|
| 41 |
List of Examples |
| 42 |
|
| 43 |
1.1. Set listen_addr parameter |
| 44 |
1.2. Set listen_port parameter |
| 45 |
1.3. Set event_callback parameter |
| 46 |
1.4. nghttp2_reply usage |
| 47 |
1.5. nghttp2_reply usage |
| 48 |
|
| 49 |
Chapter 1. Admin Guide |
| 50 |
|
| 51 |
Table of Contents |
| 52 |
|
| 53 |
1. Overview |
| 54 |
2. Dependencies |
| 55 |
|
| 56 |
2.1. Kamailio Modules |
| 57 |
2.2. External Libraries or Applications |
| 58 |
|
| 59 |
3. Parameters |
| 60 |
|
| 61 |
3.1. listen_addr (str) |
| 62 |
3.2. listen_port (str) |
| 63 |
3.3. event_callback (str) |
| 64 |
|
| 65 |
4. Functions |
| 66 |
|
| 67 |
4.1. nghttp2_reply(code, body) |
| 68 |
4.2. nghttp2_reply_header(name, value) |
| 69 |
|
| 70 |
5. Event Routes |
| 71 |
|
| 72 |
5.1. nghttp2:request |
| 73 |
|
| 74 |
1. Overview |
| 75 |
|
| 76 |
This module implements an embedded HTTP/2 server using nghttpd2 |
| 77 |
library. |
| 78 |
|
| 79 |
2. Dependencies |
| 80 |
|
| 81 |
2.1. Kamailio Modules |
| 82 |
2.2. External Libraries or Applications |
| 83 |
|
| 84 |
2.1. Kamailio Modules |
| 85 |
|
| 86 |
The following modules must be loaded before this module: |
| 87 |
* none. |
| 88 |
|
| 89 |
2.2. External Libraries or Applications |
| 90 |
|
| 91 |
The following libraries or applications must be installed before |
| 92 |
running Kamailio with this module loaded: |
| 93 |
* libnghttp2 - libnghttpd library (v1.43.0+) |
| 94 |
|
| 95 |
3. Parameters |
| 96 |
|
| 97 |
3.1. listen_addr (str) |
| 98 |
3.2. listen_port (str) |
| 99 |
3.3. event_callback (str) |
| 100 |
|
| 101 |
3.1. listen_addr (str) |
| 102 |
|
| 103 |
IPv4 address to listen for HTTP2 connection. If not set, then it |
| 104 |
listens on all local addresses (port has to be specified by listen_port |
| 105 |
parameter). |
| 106 |
|
| 107 |
Default value is "" (empty - not set). |
| 108 |
|
| 109 |
Example 1.1. Set listen_addr parameter |
| 110 |
... |
| 111 |
modparam("nghttp2", "listen_addr", "127.0.0.1") |
| 112 |
... |
| 113 |
|
| 114 |
3.2. listen_port (str) |
| 115 |
|
| 116 |
Port or service name to listen for HTTP2 connection. |
| 117 |
|
| 118 |
Default value is "8282". |
| 119 |
|
| 120 |
Example 1.2. Set listen_port parameter |
| 121 |
... |
| 122 |
modparam("nghttp2", "listen_port", "8284") |
| 123 |
... |
| 124 |
|
| 125 |
3.3. event_callback (str) |
| 126 |
|
| 127 |
The name of the function in the kemi configuration file (embedded |
| 128 |
scripting language such as Lua, Python, ...) to be executed instead of |
| 129 |
event_route[nghttp2:request] block. |
| 130 |
|
| 131 |
The function has one string parameter with the value "nghttp2:request". |
| 132 |
|
| 133 |
Default value is 'empty' (no function is executed for events). |
| 134 |
|
| 135 |
Example 1.3. Set event_callback parameter |
| 136 |
... |
| 137 |
modparam("nghttp2", "event_callback", "ksr_nghttp2_event") |
| 138 |
... |
| 139 |
-- event callback function implemented in Lua |
| 140 |
function ksr_nghttp2_event(evname) |
| 141 |
KSR.info("===== nghttp2 module triggered event: " .. evname .. "\n"); |
| 142 |
return 1; |
| 143 |
end |
| 144 |
... |
| 145 |
|
| 146 |
4. Functions |
| 147 |
|
| 148 |
4.1. nghttp2_reply(code, body) |
| 149 |
4.2. nghttp2_reply_header(name, value) |
| 150 |
|
| 151 |
4.1. nghttp2_reply(code, body) |
| 152 |
|
| 153 |
Send back a reply with body. The body can be empty string. Both |
| 154 |
parameters can contain variables. |
| 155 |
|
| 156 |
Example 1.4. nghttp2_reply usage |
| 157 |
... |
| 158 |
event_route[nghttp2:request] { |
| 159 |
nghttp2_reply("200", |
| 160 |
"<html><body>OK</body></html>"); |
| 161 |
} |
| 162 |
... |
| 163 |
|
| 164 |
4.2. nghttp2_reply_header(name, value) |
| 165 |
|
| 166 |
Set a header to be added to reply. There can be up to 15 headers. |
| 167 |
|
| 168 |
Example 1.5. nghttp2_reply usage |
| 169 |
... |
| 170 |
event_route[nghttp2:request] { |
| 171 |
nghttp2_reply_header("Content-Type", "text/html"); |
| 172 |
nghttp2_reply_header("My-Header", "xyz"); |
| 173 |
nghttp2_reply("200", |
| 174 |
"<html><body>OK</body></html>"); |
| 175 |
} |
| 176 |
... |
| 177 |
|
| 178 |
5. Event Routes |
| 179 |
|
| 180 |
5.1. nghttp2:request |
| 181 |
|
| 182 |
5.1. nghttp2:request |
| 183 |
|
| 184 |
The event route is executed when a new HTTP request is received. |
| 185 |
|
| 186 |
Inside it, the $nghttp2(...) group of variables is available, giving |
| 187 |
access to several attributes of the HTTP request, such as method, URL |
| 188 |
path, data (body) or headers. |
| 189 |
... |
| 190 |
... |
| 191 |
loadmodule "nghttp2.so |
| 192 |
... |
| 193 |
event_route[nghttp2:request] { |
| 194 |
xinfo("request: $nghttp2(method) - url: $nghttp2(path) - data: [$nghttp2(dat |
| 195 |
a)]\n"); |
| 196 |
nghttp2_reply("200", "OK", "text/html", |
| 197 |
"<html><body>OK</body></html>"); |
| 198 |
} |
| 199 |
... |