If endpoint ends with 1 client removes it

e.g. Watcher endpoint is "127.0.0.1:8081",
Watcher client sends http request to "127.0.0.1:808"

Closes-Bug: #2052779
Change-Id: I78631c8a13ff73a236f3bfadd7f4258b254b6113
This commit is contained in:
Mitya Eremeev
2024-02-09 13:04:48 +03:00
committed by Mitya_Eremeev
parent cd49282297
commit 5359e7b4ec
2 changed files with 7 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ import http.client
import io
import logging
import os
import re
import socket
import ssl
import textwrap
@@ -62,7 +63,7 @@ SUPPORTED_ENDPOINT_SCHEME = ('http', 'https')
def _trim_endpoint_api_version(url):
"""Trim API version and trailing slash from endpoint."""
return url.rstrip('/').rstrip(API_VERSION)
return re.sub(f'{API_VERSION}$', '', url.rstrip('/'))
def _extract_error_json(body):

View File

@@ -358,3 +358,8 @@ class ClientTest(utils.BaseTestCase):
client = httpclient.HTTPClient(endpoint)
conn_url = client._make_connection_url(url)
self.assertEqual(expected_url, conn_url)
def test_port_ends_with_one(self):
endpoint = "http://localhost:8081/"
http_client = httpclient.HTTPClient(endpoint)
self.assertEqual(endpoint, http_client._make_connection_url(""))