Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#51738] Enable HTTPX persistent connections.

Pavel Balashou95476f616425
diff --git a/lib/open_project.rb b/lib/open_project.rb
index 21f2371dd65..31cb5245df1 100644
--- a/lib/open_project.rb
+++ b/lib/open_project.rb
@@ -44,4 +44,11 @@ module OpenProject
def self.logger
::OpenProject::Logging::LogDelegator
end
+
+ def self.httpx
+ HTTPX
+ .plugin(:persistent)
+ .plugin(:basic_auth)
+ .plugin(:webdav)
+ end
end
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
index 047e028946e..1c0a841b744 100644
--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
@@ -43,7 +43,7 @@ module Storages
util = ::Storages::Peripherals::StorageInteraction::Nextcloud::Util
authorization_check_wrapper do
- HTTPX.get(
+ OpenProject.httpx.get(
util.join_uri_path(@uri, '/ocs/v1.php/cloud/user'),
headers: {
'Authorization' => "Bearer #{token}",
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
index efc48d2599d..462d1c24c5d 100644
--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
@@ -47,7 +47,7 @@ module Storages
util = ::Storages::Peripherals::StorageInteraction::OneDrive::Util
authorization_check_wrapper do
- HTTPX.get(
+ OpenProject.httpx.get(
util.join_uri_path(@uri, '/v1.0/me'),
headers: { 'Authorization' => "Bearer #{access_token}", 'Accept' => 'application/json' }
).status
@@ -57,7 +57,7 @@ module Storages
def extract_origin_user_id(rack_access_token)
util = ::Storages::Peripherals::StorageInteraction::OneDrive::Util
- HTTPX.get(
+ OpenProject.httpx.get(
util.join_uri_path(@uri, '/v1.0/me'),
headers: { 'Authorization' => "Bearer #{rack_access_token.access_token}", 'Accept' => 'application/json' }
).raise_for_status.json['id']
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb
index 47bac702ae2..8a03142d9b5 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/add_user_to_group_command.rb
@@ -43,7 +43,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
end
def call(user:, group: @group)
- response = Util
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.with(headers: { 'OCS-APIRequest' => 'true' })
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb
index 4fa9b23b21f..7ee9dd5a864 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/copy_template_folder_command.rb
@@ -79,7 +79,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
def validate_destination
->(urls) do
- response = Util
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.head(urls[:destination_url])
@@ -99,7 +99,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
def copy_folder
->(urls) do
- response = Util
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.request("COPY",
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb
index 1724f7697e1..c1ec835743e 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/create_folder_command.rb
@@ -44,7 +44,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
# rubocop:disable Metrics/AbcSize
def call(folder_path:)
- response = Util
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.mkcol(
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
index 0184867923a..3f657a54a0e 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/download_link_query.rb
@@ -45,7 +45,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
def call(user:, file_link:)
result = Util.token(user:, configuration: @configuration) do |token|
service_result = begin
- response = Util
+ response = OpenProject
.httpx
.post(
Util.join_uri_path(@uri, '/ocs/v2.php/apps/dav/api/v1/direct'),
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb
index 77df6fb0705..58849d70b34 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_info_query.rb
@@ -52,7 +52,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
private
def file_info(file_id, token)
- response = Util
+ response = OpenProject
.httpx
.with(headers: { 'Authorization' => "Bearer #{token.access_token}",
'Accept' => 'application/json',
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb
index 8d9017a4998..37560dbc1a0 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_info_query.rb
@@ -60,7 +60,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
private
def files_info(file_ids, token)
- response = Util
+ response = OpenProject
.httpx
.with(headers: { 'Authorization' => "Bearer #{token.access_token}",
'Accept' => 'application/json',
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
index 4e96c42d7e0..e083270ad89 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
@@ -41,7 +41,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
result = Util.token(user:, configuration: @configuration) do |token|
@location_prefix = Util.join_uri_path(@uri.path, "remote.php/dav/files", token.origin_user_id.gsub(' ', '%20'))
- response = Util
+ response = OpenProject
.httpx
.request(
"PROPFIND",
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb
index 1450e2e4153..e4556e87e39 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb
@@ -44,7 +44,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
# rubocop:disable Metrics/AbcSize
def call(group:)
- response = Util
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.with(headers: {'OCS-APIRequest' => 'true'})
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb
index 2c848aeb040..c903a7901d7 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/delete_entity_command.rb
@@ -41,7 +41,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Internal
end
def call(location:)
- response = UTIL
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.delete(UTIL.join_uri_path(@uri,
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb
index cd37e9eea16..3c64fbd2c61 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query.rb
@@ -90,7 +90,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Internal
end
end.to_xml
- response = UTIL
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.with(headers: { "Depth" => depth})
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb
index 1fc5f256b62..44d53baa7d9 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/remove_user_from_group_command.rb
@@ -43,7 +43,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
# rubocop:disable Metrics/AbcSize
def call(user:, group: @group)
- response = Util
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.with(headers: { 'OCS-APIRequest' => 'true' })
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb
index 3a84be73ae7..1c22a09034e 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/rename_file_command.rb
@@ -44,7 +44,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
end
def call(source:, target:)
- response = Util
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.request(
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
index e856b0b965f..3ad8751b4cc 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/set_permissions_command.rb
@@ -79,7 +79,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
end
end.to_xml
- response = Util
+ response = OpenProject
.httpx
.basic_auth(@username, @password)
.request(
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
index 71f7c258ba0..7b6e6aea72d 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb
@@ -66,7 +66,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud
private
def outbound_response(method:, relative_path:, payload:, token:)
- response = Util
+ response = OpenProject
.httpx
.with(headers: { 'Authorization' => "Bearer #{token.access_token}",
'Accept' => 'application/json',
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb
index 9f87ba73fed..c41aa76ffed 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb
@@ -73,10 +73,6 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Util
)
end
- def httpx
- HTTPX.plugin(:basic_auth).plugin(:webdav)
- end
-
def error_text_from_response(response)
Nokogiri::XML(response.body).xpath("//s:message").text
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb
index ea1ec7ac2e5..05ceec46c45 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/download_link_query.rb
@@ -44,7 +44,7 @@ module Storages
def call(user:, file_link:)
Util.using_user_token(@storage, user) do |token|
- response = HTTPX.get(
+ response = OpenProject.httpx.get(
Util.join_uri_path(
@uri,
uri_path_for(file_link.origin_id)
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb
index 972db4b0024..ae8131ed2d6 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_query.rb
@@ -48,7 +48,7 @@ module Storages
def call(user:, folder:)
result = Util.using_user_token(@storage, user) do |token|
- response = HTTPX.get(
+ response = OpenProject.httpx.get(
Util.join_uri_path(@uri, children_uri_path_for(folder) + FIELDS),
headers: { 'Authorization' => "Bearer #{token.access_token}" }
)
@@ -108,7 +108,7 @@ module Storages
def empty_response(user, folder)
result = Util.using_user_token(@storage, user) do |token|
- response = HTTPX.get(
+ response = OpenProject.httpx.get(
Util.join_uri_path(@uri, location_uri_path_for(folder) + FIELDS),
headers: { 'Authorization' => "Bearer #{token.access_token}" }
)
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rb
index 4bbc974e7c9..ba5d730c5ba 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/internal/drive_item_query.rb
@@ -60,7 +60,7 @@ module Storages
private
def make_file_request(drive_item_id, token, select_url_query)
- response = HTTPX.get(
+ response = OpenProject.httpx.get(
UTIL.join_uri_path(@uri, uri_path_for(drive_item_id) + select_url_query),
headers: { 'Authorization' => "Bearer #{token.access_token}" }
)
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb
index 6d60844943c..5245e358821 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb
@@ -51,7 +51,7 @@ module Storages
private
def request_drive(token)
- response = HTTPX.get(
+ response = OpenProject.httpx.get(
Util.join_uri_path(@uri, drive_uri_path),
headers: { 'Authorization' => "Bearer #{token.access_token}" }
)
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
index b0600baf03a..1c778689343 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/upload_link_query.rb
@@ -46,7 +46,7 @@ module Storages
folder, filename = data.slice('parent', 'file_name').values
Util.using_user_token(@storage, user) do |token|
- response = HTTPX
+ response = OpenProject.httpx
.with(headers: { 'Authorization' => "Bearer #{token.access_token}",
'Content-Type' => 'application/json' })
.post(
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb
index 9b51c67d185..27c3eaabcc5 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/util.rb
@@ -73,7 +73,7 @@ module Storages::Peripherals::StorageInteraction::OneDrive::Util
oauth_client.access_token!(scope: 'https://graph.microsoft.com/.default')
end
- yield HTTPX.with(
+ yield OpenProject.httpx.with(
origin: storage.uri,
headers: {
authorization: "Bearer #{token.access_token}", accept: "application/json", 'content-type': 'application/json'
diff --git a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb b/modules/storages/app/validator/nextcloud_application_credentials_validator.rb
index cfff7a3a5fc..b4fc0f24c56 100644
--- a/modules/storages/app/validator/nextcloud_application_credentials_validator.rb
+++ b/modules/storages/app/validator/nextcloud_application_credentials_validator.rb
@@ -38,7 +38,7 @@ class NextcloudApplicationCredentialsValidator
def call
return unless contract.model.password_changed?
- response = UTIL
+ response = OpenProject
.httpx
.basic_auth(contract.username, contract.password)
.head(UTIL.join_uri_path(uri, "remote.php/dav"))
diff --git a/modules/storages/app/validator/nextcloud_compatible_host_validator.rb b/modules/storages/app/validator/nextcloud_compatible_host_validator.rb
index 8c53bc2c03c..53881af9c1f 100644
--- a/modules/storages/app/validator/nextcloud_compatible_host_validator.rb
+++ b/modules/storages/app/validator/nextcloud_compatible_host_validator.rb
@@ -29,8 +29,7 @@ class NextcloudCompatibleHostValidator < ActiveModel::EachValidator
MINIMAL_NEXTCLOUD_VERSION = 22
AUTHORIZATION_HEADER = "Bearer TESTBEARERTOKEN".freeze
- HTTPX_TIMEOUT_SETTINGS = { timeout: { connect_timeout: 5, read_timeout: 3 } }
-
+ HTTPX_TIMEOUT_SETTINGS = { timeout: { connect_timeout: 5, read_timeout: 3 } }.freeze
def validate_each(contract, attribute, value)
return if contract.model.changed_attributes.exclude?(attribute)
@@ -46,7 +45,7 @@ class NextcloudCompatibleHostValidator < ActiveModel::EachValidator
response =
begin
- HTTPX
+ OpenProject.httpx
.with(HTTPX_TIMEOUT_SETTINGS)
.get(uri, headers: { "Ocs-Apirequest" => "true", "Accept" => "application/json" })
rescue StandardError => e
@@ -78,7 +77,7 @@ class NextcloudCompatibleHostValidator < ActiveModel::EachValidator
uri = URI.parse(File.join(value, 'index.php/apps/integration_openproject/check-config'))
response =
begin
- HTTPX
+ OpenProject.httpx
.with(HTTPX_TIMEOUT_SETTINGS)
.get(uri, headers: { "Authorization" => AUTHORIZATION_HEADER })
rescue StandardError => e