From 2b312a1ec5178718aa393d2c346a7cb6d1b61429 Mon Sep 17 00:00:00 2001 From: Sunghyun Kim Date: Mon, 21 Jul 2025 13:05:23 +0900 Subject: [PATCH] feat: Add configurable max_request_line_size to handle long URLs This commit adds a new configuration option `max_request_line_size` that allows users to increase the HTTP request line size limit. This is particularly useful for handling very long continuation tokens that can cause 414 (URI Too Long) errors. Changes: - Add `max_request_line_size` property to Config class - Configure Kemal server to use the custom limit if specified - Document the option in config.example.yml with recommendations - Add examples in docker-compose.yml for both YAML and env var configuration The default behavior remains unchanged (8KB limit) unless explicitly configured. This provides a solution for users experiencing 414 errors without affecting existing installations. --- config/config.example.yml | 14 ++++++++++++++ docker-compose.yml | 2 ++ src/invidious.cr | 5 +++++ src/invidious/config.cr | 2 ++ 4 files changed, 23 insertions(+) diff --git a/config/config.example.yml b/config/config.example.yml index 8d3e6212..42024708 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -191,6 +191,20 @@ https_only: false # path: /tmp/invidious.sock # permissions: 777 +## +## Maximum size of the HTTP request line (in bytes). +## Increase this value if you encounter 414 errors when using URLs with long +## query parameters (e.g., very long continuation tokens). +## +## Note: This directly sets the HTTP server's max_request_line_size. +## Be cautious when increasing this value on public instances. +## +## Accepted values: integer (size in bytes) +## Default: 8192 (8KB, Crystal's default) +## Recommended: 16384 (16KB) if experiencing 414 errors +## +#max_request_line_size: 16384 + # ----------------------------- # Network (outbound) diff --git a/docker-compose.yml b/docker-compose.yml index afda8726..d4a9a9a9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,8 @@ services: # Please read the following file for a comprehensive list of all available # configuration options and their associated syntax: # https://github.com/iv-org/invidious/blob/master/config/config.example.yml + # Uncomment to increase max request line size (if you get 414 errors): + # INVIDIOUS_MAX_REQUEST_LINE_SIZE: 16384 INVIDIOUS_CONFIG: | db: dbname: invidious diff --git a/src/invidious.cr b/src/invidious.cr index 69f8a26c..74a167b7 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -252,6 +252,11 @@ Kemal.config.app_name = "Invidious" {% end %} Kemal.run do |config| + # Set max request line size if configured + if max_size = CONFIG.max_request_line_size + config.server.not_nil!.max_request_line_size = max_size + end + if socket_binding = CONFIG.socket_binding File.delete?(socket_binding.path) # Create a socket and set its desired permissions diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 4d69854c..e697f1bc 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -157,6 +157,8 @@ class Config property host_binding : String = "0.0.0.0" # Path and permissions to make Invidious listen on a UNIX socket instead of a TCP port property socket_binding : SocketBindingConfig? = nil + # Maximum size of request line (in bytes), increase if you get 414 errors with long URLs + property max_request_line_size : Int32? = nil # Pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool of `pool_size`) property pool_size : Int32 = 100 # HTTP Proxy configuration