Skip to content

Commit 2976d02

Browse files
committed
moving server
1 parent ed90a1c commit 2976d02

5 files changed

Lines changed: 97 additions & 36 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.0.2

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "retunnel"
7-
version = "2.0.1"
7+
version = "2.0.2"
88
description = "ReTunnel - Securely expose local servers to the internet"
99
authors = [{name = "ReTunnel Team", email = "support@retunnel.com"}]
1010
license = {text = "MIT"}
@@ -148,6 +148,9 @@ dev = [
148148
"build>=1.2.2.post1",
149149
"flake8>=7.2.0",
150150
"isort>=6.0.1",
151+
"mypy>=1.16.0",
151152
"pytest>=8.4.0",
152153
"twine>=6.1.0",
154+
"types-aiofiles>=24.1.0.20250606",
155+
"types-pyyaml>=6.0.12.20250516",
153156
]

retunnel/client/high_performance_model.py

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ async def connect(self) -> None:
296296
async with ReTunnelAPIClient(api_url) as api:
297297
try:
298298
# First try to reactivate the existing token
299-
result = await api.reactivate_token(old_token)
299+
if old_token:
300+
result = await api.reactivate_token(old_token)
301+
else:
302+
result = await api.register_user()
300303
self.auth_token = result.get("auth_token")
301304
if self.auth_token:
302305
await config_manager.set_auth_token(
@@ -610,12 +613,18 @@ async def _handle_proxy_connection(
610613

611614
if not tunnel:
612615
self.logger.error(f"No tunnel found for URL: {url}")
613-
self.logger.error(f"Available tunnels: {list(self.tunnels.keys())}")
616+
self.logger.error(
617+
f"Available tunnels: {list(self.tunnels.keys())}"
618+
)
614619
for tid, t in self.tunnels.items():
615-
self.logger.error(f" Tunnel {tid}: tunnel_id={t.tunnel_id}, url={t.url}")
620+
self.logger.error(
621+
f" Tunnel {tid}: tunnel_id={t.tunnel_id}, url={t.url}"
622+
)
616623
break
617624
else:
618-
self.logger.info(f"Found tunnel for URL {url}: tunnel_id={tunnel.tunnel_id}, tunnel.url={tunnel.url}")
625+
self.logger.info(
626+
f"Found tunnel for URL {url}: tunnel_id={tunnel.tunnel_id}, tunnel.url={tunnel.url}"
627+
)
619628

620629
# Connect to local service
621630
local_reader, local_writer = await asyncio.open_connection(
@@ -636,8 +645,10 @@ async def _handle_proxy_connection(
636645
query = http_req.get("query", "")
637646
headers = http_req.get("headers", {})
638647
body = http_req.get("body", b"")
639-
640-
self.logger.info(f"Incoming request: {method} {path}{'?' + query if query else ''}")
648+
649+
self.logger.info(
650+
f"Incoming request: {method} {path}{'?' + query if query else ''}"
651+
)
641652

642653
# Build request line
643654
if query:
@@ -736,13 +747,19 @@ async def _handle_proxy_connection(
736747
break
737748

738749
# Log response details for debugging
739-
self.logger.debug(f"Response status: {status_code}")
740-
self.logger.debug(f"Response headers: {response_headers}")
750+
self.logger.debug(
751+
f"Response status: {status_code}"
752+
)
753+
self.logger.debug(
754+
f"Response headers: {response_headers}"
755+
)
741756

742757
# Handle redirects (301, 302, 303, 307, 308)
743758
if status_code in [301, 302, 303, 307, 308]:
744-
self.logger.info(f"Processing redirect with status {status_code}")
745-
759+
self.logger.info(
760+
f"Processing redirect with status {status_code}"
761+
)
762+
746763
# Check for Location header (case-insensitive)
747764
location_key = None
748765
location_value = None
@@ -751,41 +768,76 @@ async def _handle_proxy_connection(
751768
location_key = key
752769
location_value = value
753770
break
754-
755-
if location_value and tunnel:
756-
self.logger.info(f"Original Location header: {location_value}")
757-
771+
772+
if location_value and tunnel and location_key:
773+
self.logger.info(
774+
f"Original Location header: {location_value}"
775+
)
776+
758777
# Parse the location URL
759778
if location_value.startswith("/"):
760779
# Relative URL - prepend tunnel URL
761780
# Remove trailing slash from tunnel URL if present
762781
base_url = tunnel.url.rstrip("/")
763-
new_location = f"{base_url}{location_value}"
764-
response_headers[location_key] = new_location
765-
self.logger.info(f"Rewritten relative redirect to: {new_location}")
766-
elif location_value.startswith("http://localhost") or location_value.startswith("http://127.0.0.1") or location_value.startswith("https://localhost") or location_value.startswith("https://127.0.0.1"):
782+
new_location = (
783+
f"{base_url}{location_value}"
784+
)
785+
response_headers[location_key] = (
786+
new_location
787+
)
788+
self.logger.info(
789+
f"Rewritten relative redirect to: {new_location}"
790+
)
791+
elif (
792+
location_value.startswith(
793+
"http://localhost"
794+
)
795+
or location_value.startswith(
796+
"http://127.0.0.1"
797+
)
798+
or location_value.startswith(
799+
"https://localhost"
800+
)
801+
or location_value.startswith(
802+
"https://127.0.0.1"
803+
)
804+
):
767805
# Absolute URL pointing to localhost (with or without port)
768806
# Extract the path and query
769807
try:
770808
parsed = urlparse(location_value)
771809
# Reconstruct with tunnel URL
772-
tunnel_parsed = urlparse(tunnel.url)
773-
new_location = urlunparse((
774-
tunnel_parsed.scheme,
775-
tunnel_parsed.netloc,
776-
parsed.path,
777-
parsed.params,
778-
parsed.query,
779-
parsed.fragment
780-
))
781-
response_headers[location_key] = new_location
782-
self.logger.info(f"Rewritten absolute localhost redirect to: {new_location}")
810+
tunnel_parsed = urlparse(
811+
tunnel.url
812+
)
813+
new_location = urlunparse(
814+
(
815+
tunnel_parsed.scheme,
816+
tunnel_parsed.netloc,
817+
parsed.path,
818+
parsed.params,
819+
parsed.query,
820+
parsed.fragment,
821+
)
822+
)
823+
response_headers[location_key] = (
824+
new_location
825+
)
826+
self.logger.info(
827+
f"Rewritten absolute localhost redirect to: {new_location}"
828+
)
783829
except Exception as e:
784-
self.logger.error(f"Error parsing redirect URL: {e}")
830+
self.logger.error(
831+
f"Error parsing redirect URL: {e}"
832+
)
785833
else:
786-
self.logger.info(f"Not rewriting external redirect: {location_value}")
834+
self.logger.info(
835+
f"Not rewriting external redirect: {location_value}"
836+
)
787837
else:
788-
self.logger.warning(f"Redirect response but no Location header found. Headers: {response_headers}")
838+
self.logger.warning(
839+
f"Redirect response but no Location header found. Headers: {response_headers}"
840+
)
789841

790842
# Send response back
791843
response_meta = {

retunnel/core/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dataclasses import dataclass, field
66
from typing import Any, Dict, Optional
77

8-
import msgpack
8+
import msgpack # type: ignore[import-untyped]
99

1010

1111
@dataclass

uv.lock

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)