Skip to content

Commit

Permalink
nghttp2: new module for supporting direct http2 connections
Browse files Browse the repository at this point in the history
- initial import version
  • Loading branch information
miconda committed Apr 8, 2024
1 parent d55cd7e commit 5ba76f6
Show file tree
Hide file tree
Showing 8 changed files with 1,856 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/modules/nghttp2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# WARNING: do not run this directly, it should be run by the main Makefile

include ../../Makefile.defs
auto_gen=
NAME=nghttp2.so

ifeq ($(CROSS_COMPILE),)
LNGHTTP2_BUILDER=$(shell \
if pkg-config --exists libnghttp2; then \
echo 'pkg-config libnghttp2'; \
else \
which curl-config; \
fi)
endif

ifneq ($(LNGHTTP2_BUILDER),)
LNGHTTP2DEFS = $(shell $(LNGHTTP2_BUILDER) --cflags)
LNGHTTP2LIBS = $(shell $(LNGHTTP2_BUILDER) --libs)
else
LNGHTTP2DEFS = -I$(LOCALBASE)/include -I$(SYSBASE)/include
LNGHTTP2LIBS = -L$(LOCALBASE)/lib -L$(SYSBASE)/lib -lnghttp2 -levent
endif


ifeq ($(CROSS_COMPILE),)
LEVENT_BUILDER = $(shell \
if pkg-config --exists libevent; then \
echo 'pkg-config libevent'; \
fi)
endif

ifeq ($(LEVENT_BUILDER),)
LEVENTDEFS=-I$(LOCALBASE)/include -I$(SYSBASE)/include
LEVENTLIBS=-L$(LOCALBASE)/lib -levent
else
LEVENTDEFS = $(shell $(LEVENT_BUILDER) --cflags)
LEVENTLIBS = $(shell $(LEVENT_BUILDER) --libs)
endif

DEFS+=$(LNGHTTP2DEFS) $(LEVENTDEFS)
LIBS=$(LNGHTTP2LIBS) $(LEVENTLIBS)

include ../../Makefile.modules
180 changes: 180 additions & 0 deletions src/modules/nghttp2/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
NGHTTP2 Module

Daniel-Constantin Mierla

<miconda@gmail.com>

Edited by

Daniel-Constantin Mierla

<miconda@gmail.com>

Copyright © 2024 asipto.com
__________________________________________________________________

Table of Contents

1. Admin Guide

1. Overview
2. Dependencies

2.1. Kamailio Modules
2.2. External Libraries or Applications

3. Parameters

3.1. listen_addr (str)
3.2. listen_port (str)
3.3. event_callback (str)

4. Functions

4.1. nghttp2_reply(code, reason, ctype, body)

5. Event Routes

5.1. nghttp2:request

List of Examples

1.1. Set listen_addr parameter
1.2. Set listen_port parameter
1.3. Set event_callback parameter
1.4. nghttp2_reply usage

Chapter 1. Admin Guide

Table of Contents

1. Overview
2. Dependencies

2.1. Kamailio Modules
2.2. External Libraries or Applications

3. Parameters

3.1. listen_addr (str)
3.2. listen_port (str)
3.3. event_callback (str)

4. Functions

4.1. nghttp2_reply(code, reason, ctype, body)

5. Event Routes

5.1. nghttp2:request

1. Overview

This module implements an embedded HTTP/2 server using nghttpd2
library.

2. Dependencies

2.1. Kamailio Modules
2.2. External Libraries or Applications

2.1. Kamailio Modules

The following modules must be loaded before this module:
* none.

2.2. External Libraries or Applications

The following libraries or applications must be installed before
running Kamailio with this module loaded:
* libnghttp2 - libnghttpd library (v1.61.0+)

3. Parameters

3.1. listen_addr (str)
3.2. listen_port (str)
3.3. event_callback (str)

3.1. listen_addr (str)

IPv4 address to listen for HTTP2 connection. If not set, then it
listens on all local addresses (port has to be specified by listen_port
parameter).

Default value is "" (empty - not set).

Example 1.1. Set listen_addr parameter
...
modparam("nghttp2", "listen_addr", "127.0.0.1")
...

3.2. listen_port (str)

Port or service name to listen for HTTP2 connection.

Default value is "8282".

Example 1.2. Set listen_port parameter
...
modparam("nghttp2", "listen_port", "8284")
...

3.3. event_callback (str)

The name of the function in the kemi configuration file (embedded
scripting language such as Lua, Python, ...) to be executed instead of
event_route[nghttp2:request] block.

The function has one string parameter with the value "nghttp2:request".

Default value is 'empty' (no function is executed for events).

Example 1.3. Set event_callback parameter
...
modparam("nghttp2", "event_callback", "ksr_nghttp2_event")
...
-- event callback function implemented in Lua
function ksr_nghttp2_event(evname)
KSR.info("===== nghttp2 module triggered event: " .. evname .. "\n");
return 1;
end
...

4. Functions

4.1. nghttp2_reply(code, reason, ctype, body)

4.1. nghttp2_reply(code, reason, ctype, body)

Send back a reply with content-type and body.

Example 1.4. nghttp2_reply usage
...
event_route[nghttp2:request] {
nghttp2_reply("200", "OK", "text/html",
"<html><body>OK</body></html>");
}
...

5. Event Routes

5.1. nghttp2:request

5.1. nghttp2:request

The event route is executed when a new HTTP request is received.

Inside it, the $nghttp2(...) group of variables is available, giving
access to several attributes of the HTTP request, such as method, URL,
data (body) or headers.
...
...
loadmodule "nghttp2.so
...
event_route[nghttp2:request] {
xinfo("request: $nghttp2(method) - url: $nghttp2(url) - data: [$nghttp2(data
)]\n");
nghttp2_reply("200", "OK", "text/html",
"<html><body>OK</body></html>");
}
...
4 changes: 4 additions & 0 deletions src/modules/nghttp2/doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docs = nghttp2.xml

docbook_dir = ../../../../doc/docbook
include $(docbook_dir)/Makefile.module
36 changes: 36 additions & 0 deletions src/modules/nghttp2/doc/nghttp2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [

<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
%docentities;

]>

<book xmlns:xi="http://www.w3.org/2001/XInclude">
<bookinfo>
<title>NGHTTP2 Module</title>
<productname class="trade">kamailio.org</productname>
<authorgroup>
<author>
<firstname>Daniel-Constantin</firstname>
<surname>Mierla</surname>
<email>miconda@gmail.com</email>
</author>
<editor>
<firstname>Daniel-Constantin</firstname>
<surname>Mierla</surname>
<email>miconda@gmail.com</email>
</editor>
</authorgroup>
<copyright>
<year>2024</year>
<holder>asipto.com</holder>
</copyright>
</bookinfo>
<toc></toc>

<xi:include href="nghttp2_admin.xml"/>

</book>

0 comments on commit 5ba76f6

Please sign in to comment.