forked from premiere/premiere-libtorrent
more http test fixes
This commit is contained in:
parent
cdf459dad5
commit
8154ca3c7c
|
@ -156,6 +156,8 @@ void start_proxy(int port, int proxy_type)
|
||||||
fprintf(stderr, "starting delegated proxy...\n");
|
fprintf(stderr, "starting delegated proxy...\n");
|
||||||
system(buf);
|
system(buf);
|
||||||
fprintf(stderr, "launched\n");
|
fprintf(stderr, "launched\n");
|
||||||
|
// apparently delegate takes a while to open its listen port
|
||||||
|
test_sleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
@ -383,12 +385,11 @@ void send_response(stream_socket& s, error_code& ec
|
||||||
char msg[400];
|
char msg[400];
|
||||||
int pkt_len = snprintf(msg, sizeof(msg), "HTTP/1.0 %d %s\r\n"
|
int pkt_len = snprintf(msg, sizeof(msg), "HTTP/1.0 %d %s\r\n"
|
||||||
"content-length: %d\r\n"
|
"content-length: %d\r\n"
|
||||||
"connection: close\r\n"
|
|
||||||
"%s"
|
"%s"
|
||||||
"\r\n"
|
"\r\n"
|
||||||
, code, status_message, len
|
, code, status_message, len
|
||||||
, extra_header ? extra_header : "");
|
, extra_header ? extra_header : "");
|
||||||
fprintf(stderr, ">> %s\n", msg);
|
// fprintf(stderr, ">> %s\n", msg);
|
||||||
write(s, boost::asio::buffer(msg, pkt_len), boost::asio::transfer_all(), ec);
|
write(s, boost::asio::buffer(msg, pkt_len), boost::asio::transfer_all(), ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,10 +522,12 @@ void web_server_thread(int port, bool ssl)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s", std::string(buf + offset, p.body_start()).c_str());
|
// fprintf(stderr, "%s", std::string(buf + offset, p.body_start()).c_str());
|
||||||
|
|
||||||
if (failed) break;
|
if (failed) break;
|
||||||
|
|
||||||
|
offset += p.body_start() + p.content_length();
|
||||||
|
|
||||||
if (p.method() != "get" && p.method() != "post")
|
if (p.method() != "get" && p.method() != "post")
|
||||||
{
|
{
|
||||||
fprintf(stderr, "incorrect method: %s\n", p.method().c_str());
|
fprintf(stderr, "incorrect method: %s\n", p.method().c_str());
|
||||||
|
@ -535,23 +538,23 @@ void web_server_thread(int port, bool ssl)
|
||||||
|
|
||||||
if (path == "/redirect")
|
if (path == "/redirect")
|
||||||
{
|
{
|
||||||
send_response(s, ec, 301, "Moved Permanently", "Location: /test_file", 0);
|
send_response(s, ec, 301, "Moved Permanently", "Location: /test_file\r\n", 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path == "/infinite_redirect")
|
if (path == "/infinite_redirect")
|
||||||
{
|
{
|
||||||
send_response(s, ec, 301, "Moved Permanently", "Location: /infinite_redirect", 0);
|
send_response(s, ec, 301, "Moved Permanently", "Location: /infinite_redirect\r\n", 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path == "/relative/redirect")
|
if (path == "/relative/redirect")
|
||||||
{
|
{
|
||||||
send_response(s, ec, 301, "Moved Permanently", "Location: ../test_file", 0);
|
send_response(s, ec, 301, "Moved Permanently", "Location: ../test_file\r\n", 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, ">> serving file %s\n", path.c_str());
|
// fprintf(stderr, ">> serving file %s\n", path.c_str());
|
||||||
std::vector<char> file_buf;
|
std::vector<char> file_buf;
|
||||||
// remove the / from the path
|
// remove the / from the path
|
||||||
path = path.substr(1);
|
path = path.substr(1);
|
||||||
|
@ -588,15 +591,14 @@ void web_server_thread(int port, bool ssl)
|
||||||
, extra_header ? extra_header : "", start, end);
|
, extra_header ? extra_header : "", start, end);
|
||||||
send_response(s, ec, 206, "Partial", eh, end - start + 1);
|
send_response(s, ec, 206, "Partial", eh, end - start + 1);
|
||||||
write(s, boost::asio::buffer(&file_buf[0] + start, end - start + 1), boost::asio::transfer_all(), ec);
|
write(s, boost::asio::buffer(&file_buf[0] + start, end - start + 1), boost::asio::transfer_all(), ec);
|
||||||
fprintf(stderr, "send %d bytes of payload\n", end - start + 1);
|
// fprintf(stderr, "send %d bytes of payload\n", end - start + 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
send_response(s, ec, 200, "OK", extra_header, file_buf.size());
|
send_response(s, ec, 200, "OK", extra_header, file_buf.size());
|
||||||
write(s, boost::asio::buffer(&file_buf[0], file_buf.size()), boost::asio::transfer_all(), ec);
|
write(s, boost::asio::buffer(&file_buf[0], file_buf.size()), boost::asio::transfer_all(), ec);
|
||||||
}
|
}
|
||||||
offset += p.body_start() + p.content_length();
|
// fprintf(stderr, "%d bytes left in receive buffer. offset: %d\n", len - offset, offset);
|
||||||
fprintf(stderr, "%d bytes left in receive buffer. offset: %d\n", len - offset, offset);
|
|
||||||
} while (offset < len);
|
} while (offset < len);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "exiting web server thread\n");
|
fprintf(stderr, "exiting web server thread\n");
|
||||||
|
|
Loading…
Reference in New Issue