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

[WIP] use llhttp as default HTTP parser #9033

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions bazel/external/llhttp.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
licenses(["notice"]) # Apache 2

cc_library(
name = "llhttp",
srcs = [
"src/api.c",
"src/http.c",
"src/llhttp.c",
],
hdrs = ["include/llhttp.h"],
includes = ["include"],
visibility = ["//visibility:public"],
)
11 changes: 11 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def envoy_dependencies(skip_targets = []):
_com_github_luajit_luajit()
_com_github_nghttp2_nghttp2()
_com_github_nodejs_http_parser()
_com_github_nodejs_llhttp()
_com_github_tencent_rapidjson()
_com_google_absl()
_com_google_googletest()
Expand Down Expand Up @@ -407,6 +408,16 @@ def _com_github_nodejs_http_parser():
actual = "@com_github_nodejs_http_parser//:http_parser",
)

def _com_github_nodejs_llhttp():
_repository_impl(
name = "com_github_nodejs_llhttp",
build_file = "@envoy//bazel/external:llhttp.BUILD",
)
native.bind(
name = "llhttp",
actual = "@com_github_nodejs_llhttp//:llhttp",
)

def _com_google_googletest():
_repository_impl("com_google_googletest")
native.bind(
Expand Down
5 changes: 5 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "http-parser-2.9.0",
urls = ["https://github.com/nodejs/http-parser/archive/v2.9.0.tar.gz"],
),
com_github_nodejs_llhttp = dict(
sha256 = "76100c5b7948c8e49e8afa8c658e2a477bcb831e18854cf134aa3bfd44a5c669",
strip_prefix = "llhttp-release-v2.0.1",
urls = ["https://github.com/nodejs/llhttp/archive/release/v2.0.1.tar.gz"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llhttp 2.0.4 was just released - https://github.com/nodejs/llhttp/releases/tag/v2.0.4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

),
com_github_pallets_jinja = dict(
sha256 = "db49236731373e4f3118af880eb91bb0aa6978bc0cf8b35760f6a026f1a9ffc4",
strip_prefix = "jinja-2.10.3",
Expand Down
1 change: 1 addition & 0 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Version history
* health check: gRPC health checker sets the gRPC deadline to the configured timeout duration.
* http: added the ability to sanitize headers nominated by the Connection header. This new behavior is guarded by envoy.reloadable_features.connection_header_sanitization which defaults to true.
* http: support :ref:`auto_host_rewrite_header<envoy_api_field_config.filter.http.dynamic_forward_proxy.v2alpha.PerRouteConfig.auto_host_rewrite_header>` in the dynamic forward proxy.
* http: use llhttp as default http parser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive by comment as you clean things up, I wouldn't default this on until we've had some fuzzing aimed at it.
I'd be inclined to land default off, make sure we have comparable fuzzing coverage, encourage folks to smoke test it on, fuzz for a few weeks, and then switch the default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will flip this off-by-default for now

* jwt_authn: added :ref:`bypass_cors_preflight<envoy_api_field_config.filter.http.jwt_authn.v2alpha.JwtAuthentication.bypass_cors_preflight>` to allow bypassing the CORS preflight request.
* lb_subset_config: new fallback policy for selectors: :ref:`KEYS_SUBSET<envoy_api_enum_value_Cluster.LbSubsetConfig.LbSubsetSelector.LbSubsetSelectorFallbackPolicy.KEYS_SUBSET>`
* logger: added :ref:`--log-format-escaped <operations_cli>` command line option to escape newline characters in application logs.
Expand Down
5 changes: 5 additions & 0 deletions include/envoy/server/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ class Options {
*/
virtual bool fakeSymbolTableEnabled() const PURE;

/**
* @return whether to use the legacy HTTP/1.x parser.
*/
virtual bool legacyHttpParserEnabled() const PURE;

/**
* @return bool indicating whether cpuset size should determine the number of worker threads.
*/
Expand Down
45 changes: 44 additions & 1 deletion source/common/http/http1/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ envoy_cc_library(
name = "codec_lib",
srcs = ["codec_impl.cc"],
hdrs = ["codec_impl.h"],
external_deps = ["http_parser"],
deps = [
":parser_factory_lib",
":parser_interface",
"//include/envoy/buffer:buffer_interface",
"//include/envoy/http:codec_interface",
"//include/envoy/http:header_map_interface",
Expand Down Expand Up @@ -71,3 +72,45 @@ envoy_cc_library(
"//source/common/upstream:upstream_lib",
],
)

envoy_cc_library(
name = "parser_interface",
hdrs = ["parser.h"],
)

envoy_cc_library(
name = "llhttp_lib",
srcs = ["llhttp_parser.cc"],
hdrs = ["llhttp_parser.h"],
external_deps = [
"llhttp",
],
deps = [
":parser_interface",
"//source/common/common:assert_lib",
],
)

envoy_cc_library(
name = "legacy_http_parser_lib",
srcs = ["legacy_http_parser.cc"],
hdrs = ["legacy_http_parser.h"],
external_deps = [
"http_parser",
],
deps = [
":parser_interface",
"//source/common/common:assert_lib",
],
)

envoy_cc_library(
name = "parser_factory_lib",
srcs = ["parser_factory.cc"],
hdrs = ["parser_factory.h"],
deps = [
":legacy_http_parser_lib",
":llhttp_lib",
":parser_interface",
],
)