Skip to content

Commit

Permalink
Support HTTP headers with a size up to 8k
Browse files Browse the repository at this point in the history
  • Loading branch information
achouippe committed Oct 21, 2024
1 parent e38269e commit 53e7463
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion neurow/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ config :neurow,
public_api_preflight_max_age: String.to_integer(System.get_env("PREFLIGHT_MAX_AGE") || "86400"),
public_api_context_path: System.get_env("PUBLIC_API_CONTEXT_PATH") || "",
sse_timeout: String.to_integer(System.get_env("SSE_TIMEOUT") || "900000"),
sse_keepalive: String.to_integer(System.get_env("SSE_KEEPALIVE") || "600000")
sse_keepalive: String.to_integer(System.get_env("SSE_KEEPALIVE") || "600000"),
max_header_length: String.to_integer(System.get_env("MAX_HEADER_LENGTH") || "8192")

# Internal API configuration
config :neurow,
Expand Down
20 changes: 20 additions & 0 deletions neurow/integration_test/sse_livecycle_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ defmodule Neurow.IntegrationTest.SseLifecycleTest do
end
end

describe "header HTTP size" do
test "supports HTTP headers up to 8k with the default configuration", %{
cluster_state: %{
public_api_ports: [first_public_port | _other_ports]
}
} do
fake_cookie = String.duplicate("a", 8_000)

subscribe(
first_public_port,
"test_topic",
fn ->
assert_receive %HTTPoison.AsyncStatus{code: 200}
assert_receive %HTTPoison.AsyncHeaders{}
end,
cookie: fake_cookie
)
end
end

def override_timeout(timeout) do
{:ok, default_timeout} = Application.fetch_env(:neurow, :sse_timeout)
TestCluster.update_sse_timeout(timeout)
Expand Down
8 changes: 7 additions & 1 deletion neurow/lib/neurow/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Neurow.Application do
{:ok, ssl_keyfile} = Application.fetch_env(:neurow, :ssl_keyfile)
{:ok, ssl_certfile} = Application.fetch_env(:neurow, :ssl_certfile)
{:ok, history_min_duration} = Application.fetch_env(:neurow, :history_min_duration)
{:ok, max_header_length} = Application.fetch_env(:neurow, :max_header_length)

cluster_topologies =
Application.get_env(:neurow, :cluster_topologies, cluster_topologies_from_env_variables())
Expand All @@ -25,6 +26,7 @@ defmodule Neurow.Application do
internal_api_port: internal_api_port,
ssl_keyfile: ssl_keyfile,
ssl_certfile: ssl_certfile,
max_header_length: max_header_length,
history_min_duration: history_min_duration,
cluster_topologies: cluster_topologies
})
Expand All @@ -35,6 +37,7 @@ defmodule Neurow.Application do
internal_api_port: internal_api_port,
ssl_keyfile: ssl_keyfile,
ssl_certfile: ssl_certfile,
max_header_length: max_header_length,
history_min_duration: history_min_duration,
cluster_topologies: cluster_topologies
}) do
Expand All @@ -43,7 +46,10 @@ defmodule Neurow.Application do

base_public_api_http_config = [
port: public_api_port,
protocol_options: [idle_timeout: :infinity],
protocol_options: [
max_header_value_length: max_header_length,
idle_timeout: :infinity
],
transport_options: [max_connections: :infinity]
]

Expand Down

0 comments on commit 53e7463

Please sign in to comment.