Source release 17.1.2
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "http_socket.h"
|
||||
@@ -21,6 +22,7 @@ const int kReadBufferSize = 1024;
|
||||
const int kConnectTimeoutMs = 15000;
|
||||
const int kWriteTimeoutMs = 12000;
|
||||
const int kReadTimeoutMs = 12000;
|
||||
constexpr int kHttpOk = 200;
|
||||
|
||||
const std::string kGoogleHeaderUpper("X-Google");
|
||||
const std::string kGoogleHeaderLower("x-google");
|
||||
@@ -92,7 +94,7 @@ void UrlRequest::Reconnect() {
|
||||
is_connected_ = true;
|
||||
} else {
|
||||
LOGE("Failed to connect: url = %s, port = %d, attempt = %u",
|
||||
socket_.domain_name().c_str(), socket_.port(), i);
|
||||
socket_.url().c_str(), socket_.port(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,12 +121,20 @@ bool UrlRequest::GetResponse(std::string* message) {
|
||||
}
|
||||
|
||||
ConcatenateChunkedResponse(response, message);
|
||||
LOGV("HTTP response from %s://%s:%d%s: (%zu): %s", socket_.scheme().c_str(),
|
||||
socket_.domain_name().c_str(), socket_.port(),
|
||||
socket_.resource_path().c_str(), message->size(), message->c_str());
|
||||
LOGV("HTTP response from %s: (%zu): %s", socket_.url().c_str(),
|
||||
message->size(), message->c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void UrlRequest::AssertOkResponse(std::string* message) {
|
||||
ASSERT_TRUE(message);
|
||||
ASSERT_TRUE(GetResponse(message));
|
||||
const int status_code = GetStatusCode(*message);
|
||||
ASSERT_EQ(kHttpOk, status_code) << "HTTP response from " << socket_.url()
|
||||
<< ": (" << message->size() << ") :\n"
|
||||
<< *message;
|
||||
}
|
||||
|
||||
// static
|
||||
int UrlRequest::GetStatusCode(const std::string& response) {
|
||||
const std::string kHttpVersion("HTTP/1.1 ");
|
||||
@@ -191,6 +201,7 @@ bool UrlRequest::PostRequestWithPath(const std::string& path,
|
||||
|
||||
request.append("Connection: close\r\n");
|
||||
request.append("User-Agent: Widevine CDM v1.0\r\n");
|
||||
request.append("X-Return-Encrypted-Headers: request_and_response\r\n");
|
||||
|
||||
// buffer to store length of data as a string
|
||||
char data_size_buffer[32] = {0};
|
||||
@@ -206,8 +217,8 @@ bool UrlRequest::PostRequestWithPath(const std::string& path,
|
||||
|
||||
const int ret = socket_.WriteAndLogErrors(
|
||||
request.c_str(), static_cast<int>(request.size()), kWriteTimeoutMs);
|
||||
LOGV("HTTP request: (%zu): %s", request.size(),
|
||||
wvutil::b2a_hex(request).c_str());
|
||||
LOGV("HTTP request: (%zu): %s", request.size(), request.c_str());
|
||||
LOGV("HTTP request hex: %s", wvutil::b2a_hex(request).c_str());
|
||||
return ret != -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user