Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http_server: component addition #8570

Merged
merged 24 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dcf0562
lib: nghttp2: new library introduction
leonardo-albertovich Mar 12, 2024
4fc07a9
http_client: structure renamed to prevent conflict
leonardo-albertovich Mar 12, 2024
dfb2c8d
tests: http_client structure name updated to match the new one
leonardo-albertovich Mar 12, 2024
943e440
tls: added alpn support for server sessions
leonardo-albertovich Mar 12, 2024
267e653
http_server: initial commit of the http server component
leonardo-albertovich Mar 12, 2024
0e52a21
in_http: added http2 support
leonardo-albertovich Mar 12, 2024
dd28875
in_elasticsearch: added http2 support
leonardo-albertovich Mar 12, 2024
e32ef3a
in_splunk: added http2 support
leonardo-albertovich Mar 12, 2024
9dfb20b
in_opentelemetry: added http2 and grpc support
leonardo-albertovich Mar 12, 2024
73ac296
in_elasticsearch: fixed the usage of the wrong config destructor
leonardo-albertovich Mar 13, 2024
49a4c6f
in_splunk: fixed an error related to error handling
leonardo-albertovich Mar 13, 2024
0e2488b
http_server: fixed cleanup errors
leonardo-albertovich Mar 13, 2024
bbe4136
in_elasticsearch: added missing cleanup code
leonardo-albertovich Mar 13, 2024
0036121
in_opentelemetry: added missing cleanup code
leonardo-albertovich Mar 13, 2024
e1c62f0
in_splunk: added missing cleanup code
leonardo-albertovich Mar 13, 2024
cf158f7
http_server: removed problematic macro
leonardo-albertovich Mar 13, 2024
bc9e90f
in_splunk: removed unused code
leonardo-albertovich Mar 13, 2024
0440c47
in_elasticsearch: removed unused code
leonardo-albertovich Mar 13, 2024
627741c
in_opentelemetry: removed unused code
leonardo-albertovich Mar 13, 2024
edd0c72
in_http: removed unused code
leonardo-albertovich Mar 13, 2024
6581ed8
tls: added compatibility macro
leonardo-albertovich Mar 13, 2024
cc27061
build: fixed nghttp2 related linkage issues
leonardo-albertovich Mar 13, 2024
f208a72
build: attempted to fix nghttp2 related linkage issues again
leonardo-albertovich Mar 13, 2024
0e707d0
build: attempted to fix nghttp2 related additional linkage issues
leonardo-albertovich Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,15 @@ add_subdirectory(${FLB_PATH_LIB_CMETRICS} EXCLUDE_FROM_ALL)
# CTraces
add_subdirectory(${FLB_PATH_LIB_CTRACES} EXCLUDE_FROM_ALL)

# Nghttp2 options
FLB_OPTION(ENABLE_LIB_ONLY ON)
FLB_OPTION(ENABLE_STATIC_LIB ON)
FLB_OPTION(ENABLE_SHARED_LIB OFF)

FLB_DEFINITION(NGHTTP2_STATICLIB)

add_subdirectory(${FLB_PATH_LIB_NGHTTP2} EXCLUDE_FROM_ALL)

# C-Ares (DNS library)
FLB_OPTION(CARES_STATIC ON)
FLB_OPTION(CARES_SHARED OFF)
Expand Down
4 changes: 4 additions & 0 deletions cmake/headers.cmake
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ include_directories(

${CMAKE_CURRENT_BINARY_DIR}/lib/monkey/include/
${CMAKE_CURRENT_BINARY_DIR}/lib/monkey/include/monkey/

${CMAKE_CURRENT_BINARY_DIR}/lib/nghttp2
${CMAKE_CURRENT_BINARY_DIR}/lib/nghttp2/lib/includes/
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_NGHTTP2}/lib/includes/
)

if(FLB_IN_KAFKA OR FLB_OUT_KAFKA)
Expand Down
1 change: 1 addition & 0 deletions cmake/libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(FLB_PATH_LIB_CTRACES "lib/ctraces")
set(FLB_PATH_LIB_CO "lib/flb_libco")
set(FLB_PATH_LIB_RBTREE "lib/rbtree")
set(FLB_PATH_LIB_MSGPACK "lib/msgpack-c")
set(FLB_PATH_LIB_NGHTTP2 "lib/nghttp2")
set(FLB_PATH_LIB_AVRO "lib/avro")
set(FLB_PATH_LIB_CHUNKIO "lib/chunkio")
set(FLB_PATH_LIB_LUAJIT "lib/luajit-3065c9")
Expand Down
4 changes: 2 additions & 2 deletions include/fluent-bit/flb_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#define FLB_HTTP_HEADER_CONNECTION "Connection"
#define FLB_HTTP_HEADER_KA "keep-alive"

struct flb_http_response {
struct flb_http_client_response {
int status; /* HTTP response status */
int content_length; /* Content length set by headers */
int chunked_encoding; /* Chunked transfer encoding ? */
Expand Down Expand Up @@ -131,7 +131,7 @@ struct flb_http_client {
struct flb_http_proxy proxy;

/* Response */
struct flb_http_response resp;
struct flb_http_client_response resp;

/* Reference to Callback context */
void *cb_ctx;
Expand Down
176 changes: 176 additions & 0 deletions include/fluent-bit/flb_http_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2022 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_HTTP_COMMON
#define FLB_HTTP_COMMON

#include <fluent-bit/flb_hash_table.h>

#include <cfl/cfl_list.h>
#include <cfl/cfl_sds.h>

/* These definitions are temporary and should be moved
* to monkey.
* This fallback has been added to be able to merge this
* feature with the current monkey version.
*/

#ifndef MK_HTTP_PROTOCOL_20
#define MK_HTTP_PROTOCOL_20 (20)
#endif

#ifndef MK_HTTP_PROTOCOL_20_STR
#define MK_HTTP_PROTOCOL_20_STR "HTTP/2"
#endif

#define HTTP_PROTOCOL_AUTODETECT -1
#define HTTP_PROTOCOL_HTTP0 0
#define HTTP_PROTOCOL_HTTP1 1
#define HTTP_PROTOCOL_HTTP2 2

#define HTTP_PROTOCOL_VERSION_09 MK_HTTP_PROTOCOL_09
#define HTTP_PROTOCOL_VERSION_10 MK_HTTP_PROTOCOL_10
#define HTTP_PROTOCOL_VERSION_11 MK_HTTP_PROTOCOL_11
#define HTTP_PROTOCOL_VERSION_20 MK_HTTP_PROTOCOL_20

#define HTTP_METHOD_GET MK_METHOD_GET
#define HTTP_METHOD_POST MK_METHOD_POST
#define HTTP_METHOD_HEAD MK_METHOD_HEAD
#define HTTP_METHOD_PUT MK_METHOD_PUT
#define HTTP_METHOD_DELETE MK_METHOD_DELETE
#define HTTP_METHOD_OPTIONS MK_METHOD_OPTIONS
#define HTTP_METHOD_UNKNOWN MK_METHOD_UNKNOWN

#define HTTP_STREAM_ROLE_SERVER 0
#define HTTP_STREAM_ROLE_CLIENT 1

#define HTTP_STREAM_STATUS_RECEIVING_HEADERS 0
#define HTTP_STREAM_STATUS_RECEIVING_DATA 1
#define HTTP_STREAM_STATUS_READY 2
#define HTTP_STREAM_STATUS_PROCESSING 3
#define HTTP_STREAM_STATUS_CLOSED 4
#define HTTP_STREAM_STATUS_ERROR 5

struct flb_http_stream;
struct flb_http_server_session;

struct flb_http_request {
int protocol_version;
int method;
cfl_sds_t path;
cfl_sds_t host;
cfl_sds_t query_string;
struct flb_hash_table *headers;
size_t content_length;
char *content_type;
cfl_sds_t body;

struct flb_http_stream *stream;

struct cfl_list _head;
};

struct flb_http_response {
int status;
cfl_sds_t message;
struct flb_hash_table *headers;
struct flb_hash_table *trailer_headers;
size_t content_length;
cfl_sds_t body;
size_t body_read_offset;

struct flb_http_stream *stream;
};

struct flb_http_stream {
int32_t id;
int role;
int status;

struct flb_http_request request;
struct flb_http_response response;

void *parent;
void *user_data;

int releasable;
struct cfl_list _head;
};

/* HTTP REQUEST */

int flb_http_request_init(struct flb_http_request *request);

void flb_http_request_destroy(struct flb_http_request *request);

char *flb_http_request_get_header(struct flb_http_request *request,
char *name);

int flb_http_request_set_header(struct flb_http_request *request,
char *name, size_t name_length,
char *value, size_t value_length);

int flb_http_request_unset_header(struct flb_http_request *request,
char *name);

/* HTTP RESPONSE */

int flb_http_response_init(struct flb_http_response *response);

void flb_http_response_destroy(struct flb_http_response *response);

struct flb_http_response *flb_http_response_begin(
struct flb_http_server_session *session,
void *stream);

int flb_http_response_commit(struct flb_http_response *response);

int flb_http_response_set_header(struct flb_http_response *response,
char *name, size_t name_length,
char *value, size_t value_length);

int flb_http_response_set_trailer_header(struct flb_http_response *response,
char *name, size_t name_length,
char *value, size_t value_length);

int flb_http_response_set_status(struct flb_http_response *response,
int status);

int flb_http_response_set_message(struct flb_http_response *response,
char *message);

int flb_http_response_set_body(struct flb_http_response *response,
unsigned char *body, size_t body_length);

/* HTTP STREAM */

int flb_http_stream_init(struct flb_http_stream *stream,
void *parent,
int32_t stream_id,
int role,
void *user_data);

struct flb_http_stream *flb_http_stream_create(void *parent,
int32_t stream_id,
int role,
void *user_data);

void flb_http_stream_destroy(struct flb_http_stream *stream);

#endif
141 changes: 141 additions & 0 deletions include/fluent-bit/http_server/flb_http_server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2022 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_HTTP_SERVER
#define FLB_HTTP_SERVER

#include <fluent-bit/flb_downstream.h>
#include <fluent-bit/flb_hash_table.h>
#include <fluent-bit/tls/flb_tls.h>
#include <fluent-bit/flb_network.h>
#include <fluent-bit/flb_config.h>
#include <fluent-bit/flb_engine.h>

#include <monkey/mk_core.h>

#include <cfl/cfl_list.h>
#include <cfl/cfl_sds.h>

#include <fluent-bit/flb_http_common.h>
#include <fluent-bit/http_server/flb_http_server_http1.h>
#include <fluent-bit/http_server/flb_http_server_http2.h>

#define HTTP_SERVER_INITIAL_BUFFER_SIZE (10 * 1024)
#define HTTP_SERVER_MAXIMUM_BUFFER_SIZE (10 * (1000 * 1024))

#define FLB_HTTP_SERVER_FLAG_KEEPALIVE (((uint64_t) 1) << 0)
#define FLB_HTTP_SERVER_FLAG_AUTO_INFLATE (((uint64_t) 1) << 1)

#define HTTP_SERVER_SUCCESS 0
#define HTTP_SERVER_PROVIDER_ERROR -1
#define HTTP_SERVER_ALLOCATION_ERROR -2

#define HTTP_SERVER_UNINITIALIZED 0
#define HTTP_SERVER_INITIALIZED 1
#define HTTP_SERVER_RUNNING 2
#define HTTP_SERVER_STOPPED 3

typedef int (*flb_http_server_request_processor_callback)(
struct flb_http_request *request,
struct flb_http_response *response);

struct flb_http_server {
/* Internal */
struct mk_event listener_event;
char *address;
unsigned short int port;
struct flb_tls *tls_provider;
int networking_flags;
struct flb_net_setup *networking_setup;
struct mk_event_loop *event_loop;
struct flb_config *system_context;
/* Internal */

uint64_t flags;
int status;
int protocol_version;
struct flb_downstream *downstream;
struct cfl_list clients;
flb_http_server_request_processor_callback
request_callback;
void *user_data;
};

struct flb_http_server_session {
struct flb_http1_server_session http1;
struct flb_http2_server_session http2;

int version;
struct cfl_list request_queue;

cfl_sds_t incoming_data;
cfl_sds_t outgoing_data;

int releasable;

struct flb_connection *connection;
struct flb_http_server *parent;
struct cfl_list _head;
};

/* COMMON */

char *flb_http_server_convert_string_to_lowercase(char *input_buffer,
size_t length);

int flb_http_server_strncasecmp(const uint8_t *first_buffer,
size_t first_length,
const char *second_buffer,
size_t second_length);

/* HTTP SERVER */

int flb_http_server_init(struct flb_http_server *session,
int protocol_version,
uint64_t flags,
flb_http_server_request_processor_callback
request_callback,
char *address,
unsigned short int port,
struct flb_tls *tls_provider,
int networking_flags,
struct flb_net_setup *networking_setup,
struct mk_event_loop *event_loop,
struct flb_config *system_context,
void *user_data);

int flb_http_server_start(struct flb_http_server *session);

int flb_http_server_stop(struct flb_http_server *session);

int flb_http_server_destroy(struct flb_http_server *session);

/* HTTP SESSION */

int flb_http_server_session_init(struct flb_http_server_session *session, int version);

struct flb_http_server_session *flb_http_server_session_create(int version);

void flb_http_server_session_destroy(struct flb_http_server_session *session);

int flb_http_server_session_ingest(struct flb_http_server_session *session,
unsigned char *buffer,
size_t length);

#endif
Loading
Loading