Fixed #456
This commit is contained in:
parent
8333340e2c
commit
08fc7085e5
12
httplib.h
12
httplib.h
@ -1515,8 +1515,8 @@ inline bool bind_ip_address(socket_t sock, const char *host) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string if2ip(const std::string &ifn) {
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
inline std::string if2ip(const std::string &ifn) {
|
||||||
struct ifaddrs *ifap;
|
struct ifaddrs *ifap;
|
||||||
getifaddrs(&ifap);
|
getifaddrs(&ifap);
|
||||||
for (auto ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
for (auto ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
||||||
@ -1532,9 +1532,9 @@ inline std::string if2ip(const std::string &ifn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
freeifaddrs(ifap);
|
freeifaddrs(ifap);
|
||||||
#endif
|
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
inline socket_t create_client_socket(const char *host, int port,
|
inline socket_t create_client_socket(const char *host, int port,
|
||||||
time_t timeout_sec,
|
time_t timeout_sec,
|
||||||
@ -1542,9 +1542,11 @@ inline socket_t create_client_socket(const char *host, int port,
|
|||||||
return create_socket(
|
return create_socket(
|
||||||
host, port, [&](socket_t sock, struct addrinfo &ai) -> bool {
|
host, port, [&](socket_t sock, struct addrinfo &ai) -> bool {
|
||||||
if (!intf.empty()) {
|
if (!intf.empty()) {
|
||||||
|
#ifndef _WIN32
|
||||||
auto ip = if2ip(intf);
|
auto ip = if2ip(intf);
|
||||||
if (ip.empty()) { ip = intf; }
|
if (ip.empty()) { ip = intf; }
|
||||||
if (!bind_ip_address(sock, ip.c_str())) { return false; }
|
if (!bind_ip_address(sock, ip.c_str())) { return false; }
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
set_nonblocking(sock, true);
|
set_nonblocking(sock, true);
|
||||||
@ -2849,11 +2851,11 @@ inline void Response::set_header(const char *key, const std::string &val) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Response::set_redirect(const char *url, int status) {
|
inline void Response::set_redirect(const char *url, int stat) {
|
||||||
if (!detail::has_crlf(url)) {
|
if (!detail::has_crlf(url)) {
|
||||||
set_header("Location", url);
|
set_header("Location", url);
|
||||||
if (300 <= status && status < 400) {
|
if (300 <= stat && stat < 400) {
|
||||||
this->status = status;
|
this->status = stat;
|
||||||
} else {
|
} else {
|
||||||
this->status = 302;
|
this->status = 302;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
|
||||||
@ -108,7 +108,7 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
|
||||||
@ -118,12 +118,12 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>Ws2_32.lib;AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
@ -144,7 +144,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user