Skip to content

Commit b46cf7c

Browse files
committed
Fix lfs generate correct server URL for SSL connections
1 parent bab6682 commit b46cf7c

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

‎httpd/include/httpd/lfs.hpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ template <typename Stream>
158158
inline awaitable_void lfs_batch_session(
159159
Stream& stream,
160160
http::request<http::dynamic_body>& req,
161-
int64_t connection_id)
161+
int64_t connection_id,
162+
bool is_ssl = false)
162163
{
163164
boost::system::error_code ec;
164165

@@ -224,8 +225,8 @@ inline awaitable_void lfs_batch_session(
224225
}
225226

226227
// 构建响应.
227-
// 从 Host 头获取服务器地址.
228-
std::string server_url = "http://";
228+
// 根据当前连接是否使用 SSL 来决定协议前缀.
229+
std::string server_url = is_ssl ? "https://" : "http://";
229230
auto host_it = req.find(http::field::host);
230231
if (host_it != req.end())
231232
server_url += host_it->value();

‎httpd/src/main.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <string_view>
1616
#include <chrono>
1717
#include <tuple>
18+
#include <type_traits>
1819

1920
#include <fmt/xchar.h>
2021
#include <fmt/format.h>
@@ -1487,7 +1488,8 @@ inline awaitable_void session(Stream stream)
14871488
dynamic_request req = parser.release();
14881489

14891490
co_await lfs_batch_session(
1490-
stream, req, connection_id);
1491+
stream, req, connection_id,
1492+
std::is_same_v<std::decay_t<Stream>, ssl_stream>);
14911493
co_return;
14921494
}
14931495

0 commit comments

Comments
 (0)