Delete unused Url class.
Bug: webrtc:6424 Change-Id: I191d8d6a0bb88b6cfbfc95015386c4451000d2c6 Reviewed-on: https://webrtc-review.googlesource.com/100800 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24794}
This commit is contained in:
parent
e5aadba6e3
commit
74e3742635
@ -787,7 +787,6 @@ rtc_static_library("rtc_base_generic") {
|
||||
"gunit_prod.h",
|
||||
"helpers.cc",
|
||||
"helpers.h",
|
||||
"httpcommon-inl.h",
|
||||
"httpcommon.cc",
|
||||
"httpcommon.h",
|
||||
"ipaddress.cc",
|
||||
|
||||
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef RTC_BASE_HTTPCOMMON_INL_H_
|
||||
#define RTC_BASE_HTTPCOMMON_INL_H_
|
||||
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/httpcommon.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Url
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class CTYPE>
|
||||
void Url<CTYPE>::do_set_url(const CTYPE* val, size_t len) {
|
||||
if (ascnicmp(val, "http://", 7) == 0) {
|
||||
val += 7;
|
||||
len -= 7;
|
||||
secure_ = false;
|
||||
} else if (ascnicmp(val, "https://", 8) == 0) {
|
||||
val += 8;
|
||||
len -= 8;
|
||||
secure_ = true;
|
||||
} else {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
const CTYPE* path = strchrn(val, len, static_cast<CTYPE>('/'));
|
||||
if (!path) {
|
||||
path = val + len;
|
||||
}
|
||||
size_t address_length = (path - val);
|
||||
do_set_address(val, address_length);
|
||||
do_set_full_path(path, len - address_length);
|
||||
}
|
||||
|
||||
template <class CTYPE>
|
||||
void Url<CTYPE>::do_set_address(const CTYPE* val, size_t len) {
|
||||
if (const CTYPE* at = strchrn(val, len, static_cast<CTYPE>('@'))) {
|
||||
// Everything before the @ is a user:password combo, so skip it.
|
||||
len -= at - val + 1;
|
||||
val = at + 1;
|
||||
}
|
||||
if (const CTYPE* colon = strchrn(val, len, static_cast<CTYPE>(':'))) {
|
||||
host_.assign(val, colon - val);
|
||||
// Note: In every case, we're guaranteed that colon is followed by a null,
|
||||
// or non-numeric character.
|
||||
port_ = static_cast<uint16_t>(::strtoul(colon + 1, nullptr, 10));
|
||||
// TODO: Consider checking for invalid data following port number.
|
||||
} else {
|
||||
host_.assign(val, len);
|
||||
port_ = HttpDefaultPort(secure_);
|
||||
}
|
||||
}
|
||||
|
||||
template <class CTYPE>
|
||||
void Url<CTYPE>::do_set_full_path(const CTYPE* val, size_t len) {
|
||||
const CTYPE* query = strchrn(val, len, static_cast<CTYPE>('?'));
|
||||
if (!query) {
|
||||
query = val + len;
|
||||
}
|
||||
size_t path_length = (query - val);
|
||||
if (0 == path_length) {
|
||||
// TODO: consider failing in this case.
|
||||
path_.assign(1, static_cast<CTYPE>('/'));
|
||||
} else {
|
||||
RTC_DCHECK(val[0] == static_cast<CTYPE>('/'));
|
||||
path_.assign(val, path_length);
|
||||
}
|
||||
query_.assign(query, len - path_length);
|
||||
}
|
||||
|
||||
template <class CTYPE>
|
||||
void Url<CTYPE>::do_get_url(string* val) const {
|
||||
CTYPE protocol[9];
|
||||
asccpyn(protocol, arraysize(protocol), secure_ ? "https://" : "http://");
|
||||
val->append(protocol);
|
||||
do_get_address(val);
|
||||
do_get_full_path(val);
|
||||
}
|
||||
|
||||
template <class CTYPE>
|
||||
void Url<CTYPE>::do_get_address(string* val) const {
|
||||
val->append(host_);
|
||||
if (port_ != HttpDefaultPort(secure_)) {
|
||||
CTYPE format[5], port[32];
|
||||
asccpyn(format, arraysize(format), ":%hu");
|
||||
sprintfn(port, arraysize(port), format, port_);
|
||||
val->append(port);
|
||||
}
|
||||
}
|
||||
|
||||
template <class CTYPE>
|
||||
void Url<CTYPE>::do_get_full_path(string* val) const {
|
||||
val->append(path_);
|
||||
val->append(query_);
|
||||
}
|
||||
|
||||
template <class CTYPE>
|
||||
bool Url<CTYPE>::get_attribute(const string& name, string* value) const {
|
||||
if (query_.empty())
|
||||
return false;
|
||||
|
||||
std::string::size_type pos = query_.find(name, 1);
|
||||
if (std::string::npos == pos)
|
||||
return false;
|
||||
|
||||
pos += name.length() + 1;
|
||||
if ((pos > query_.length()) || (static_cast<CTYPE>('=') != query_[pos - 1]))
|
||||
return false;
|
||||
|
||||
std::string::size_type end = query_.find(static_cast<CTYPE>('&'), pos);
|
||||
if (std::string::npos == end) {
|
||||
end = query_.length();
|
||||
}
|
||||
value->assign(query_.substr(pos, end - pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_HTTPCOMMON_INL_H_
|
||||
@ -23,7 +23,6 @@
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/cryptstring.h"
|
||||
#include "rtc_base/httpcommon-inl.h"
|
||||
#include "rtc_base/httpcommon.h"
|
||||
#include "rtc_base/messagedigest.h"
|
||||
#include "rtc_base/socketaddress.h"
|
||||
@ -552,35 +551,6 @@ HttpError HttpRequestData::parseLeader(const char* line, size_t len) {
|
||||
return HE_NONE;
|
||||
}
|
||||
|
||||
bool HttpRequestData::getAbsoluteUri(std::string* uri) const {
|
||||
Url<char> url(path);
|
||||
if (url.valid()) {
|
||||
uri->assign(path);
|
||||
return true;
|
||||
}
|
||||
std::string host;
|
||||
if (!hasHeader(HH_HOST, &host))
|
||||
return false;
|
||||
url.set_address(host);
|
||||
url.set_full_path(path);
|
||||
uri->assign(url.url());
|
||||
return url.valid();
|
||||
}
|
||||
|
||||
bool HttpRequestData::getRelativeUri(std::string* host,
|
||||
std::string* path) const {
|
||||
Url<char> url(this->path);
|
||||
if (url.valid()) {
|
||||
host->assign(url.address());
|
||||
path->assign(url.full_path());
|
||||
return true;
|
||||
}
|
||||
if (!hasHeader(HH_HOST, host))
|
||||
return false;
|
||||
path->assign(this->path);
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// HttpResponseData
|
||||
//
|
||||
|
||||
@ -136,102 +136,6 @@ struct iless {
|
||||
// put quotes around a string and escape any quotes inside it
|
||||
std::string quote(const std::string& str);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Url
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class CTYPE>
|
||||
class Url {
|
||||
public:
|
||||
typedef typename Traits<CTYPE>::string string;
|
||||
|
||||
// TODO: Implement Encode/Decode
|
||||
static int Encode(const CTYPE* source, CTYPE* destination, size_t len);
|
||||
static int Encode(const string& source, string& destination);
|
||||
static int Decode(const CTYPE* source, CTYPE* destination, size_t len);
|
||||
static int Decode(const string& source, string& destination);
|
||||
|
||||
Url(const string& url) { do_set_url(url.c_str(), url.size()); }
|
||||
Url(const string& path, const string& host, uint16_t port = HTTP_DEFAULT_PORT)
|
||||
: host_(host), port_(port), secure_(HTTP_SECURE_PORT == port) {
|
||||
set_full_path(path);
|
||||
}
|
||||
|
||||
bool valid() const { return !host_.empty(); }
|
||||
void clear() {
|
||||
host_.clear();
|
||||
port_ = HTTP_DEFAULT_PORT;
|
||||
secure_ = false;
|
||||
path_.assign(1, static_cast<CTYPE>('/'));
|
||||
query_.clear();
|
||||
}
|
||||
|
||||
void set_url(const string& val) { do_set_url(val.c_str(), val.size()); }
|
||||
string url() const {
|
||||
string val;
|
||||
do_get_url(&val);
|
||||
return val;
|
||||
}
|
||||
|
||||
void set_address(const string& val) {
|
||||
do_set_address(val.c_str(), val.size());
|
||||
}
|
||||
string address() const {
|
||||
string val;
|
||||
do_get_address(&val);
|
||||
return val;
|
||||
}
|
||||
|
||||
void set_full_path(const string& val) {
|
||||
do_set_full_path(val.c_str(), val.size());
|
||||
}
|
||||
string full_path() const {
|
||||
string val;
|
||||
do_get_full_path(&val);
|
||||
return val;
|
||||
}
|
||||
|
||||
void set_host(const string& val) { host_ = val; }
|
||||
const string& host() const { return host_; }
|
||||
|
||||
void set_port(uint16_t val) { port_ = val; }
|
||||
uint16_t port() const { return port_; }
|
||||
|
||||
void set_secure(bool val) { secure_ = val; }
|
||||
bool secure() const { return secure_; }
|
||||
|
||||
void set_path(const string& val) {
|
||||
if (val.empty()) {
|
||||
path_.assign(1, static_cast<CTYPE>('/'));
|
||||
} else {
|
||||
RTC_DCHECK(val[0] == static_cast<CTYPE>('/'));
|
||||
path_ = val;
|
||||
}
|
||||
}
|
||||
const string& path() const { return path_; }
|
||||
|
||||
void set_query(const string& val) {
|
||||
RTC_DCHECK(val.empty() || (val[0] == static_cast<CTYPE>('?')));
|
||||
query_ = val;
|
||||
}
|
||||
const string& query() const { return query_; }
|
||||
|
||||
bool get_attribute(const string& name, string* value) const;
|
||||
|
||||
private:
|
||||
void do_set_url(const CTYPE* val, size_t len);
|
||||
void do_set_address(const CTYPE* val, size_t len);
|
||||
void do_set_full_path(const CTYPE* val, size_t len);
|
||||
|
||||
void do_get_url(string* val) const;
|
||||
void do_get_address(string* val) const;
|
||||
void do_get_full_path(string* val) const;
|
||||
|
||||
string host_, path_, query_;
|
||||
uint16_t port_;
|
||||
bool secure_;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// HttpData
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -338,9 +242,6 @@ struct HttpRequestData : public HttpData {
|
||||
|
||||
size_t formatLeader(char* buffer, size_t size) const override;
|
||||
HttpError parseLeader(const char* line, size_t len) override;
|
||||
|
||||
bool getAbsoluteUri(std::string* uri) const;
|
||||
bool getRelativeUri(std::string* host, std::string* path) const;
|
||||
};
|
||||
|
||||
struct HttpResponseData : public HttpData {
|
||||
|
||||
@ -10,115 +10,9 @@
|
||||
|
||||
#include "rtc_base/httpcommon.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/httpcommon-inl.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
#define TEST_PROTOCOL "http://"
|
||||
#define TEST_HOST "www.google.com"
|
||||
#define TEST_PATH "/folder/file.html"
|
||||
#define TEST_QUERY "?query=x&attr=y"
|
||||
#define TEST_URL TEST_PROTOCOL TEST_HOST TEST_PATH TEST_QUERY
|
||||
|
||||
TEST(Url, DecomposesUrls) {
|
||||
Url<char> url(TEST_URL);
|
||||
EXPECT_TRUE(url.valid());
|
||||
EXPECT_FALSE(url.secure());
|
||||
EXPECT_STREQ(TEST_HOST, url.host().c_str());
|
||||
EXPECT_EQ(80, url.port());
|
||||
EXPECT_STREQ(TEST_PATH, url.path().c_str());
|
||||
EXPECT_STREQ(TEST_QUERY, url.query().c_str());
|
||||
EXPECT_STREQ(TEST_HOST, url.address().c_str());
|
||||
EXPECT_STREQ(TEST_PATH TEST_QUERY, url.full_path().c_str());
|
||||
EXPECT_STREQ(TEST_URL, url.url().c_str());
|
||||
}
|
||||
|
||||
TEST(Url, ComposesUrls) {
|
||||
// Set in constructor
|
||||
Url<char> url(TEST_PATH TEST_QUERY, TEST_HOST, 80);
|
||||
EXPECT_TRUE(url.valid());
|
||||
EXPECT_FALSE(url.secure());
|
||||
EXPECT_STREQ(TEST_HOST, url.host().c_str());
|
||||
EXPECT_EQ(80, url.port());
|
||||
EXPECT_STREQ(TEST_PATH, url.path().c_str());
|
||||
EXPECT_STREQ(TEST_QUERY, url.query().c_str());
|
||||
EXPECT_STREQ(TEST_HOST, url.address().c_str());
|
||||
EXPECT_STREQ(TEST_PATH TEST_QUERY, url.full_path().c_str());
|
||||
EXPECT_STREQ(TEST_URL, url.url().c_str());
|
||||
|
||||
url.clear();
|
||||
EXPECT_FALSE(url.valid());
|
||||
EXPECT_FALSE(url.secure());
|
||||
EXPECT_STREQ("", url.host().c_str());
|
||||
EXPECT_EQ(80, url.port());
|
||||
EXPECT_STREQ("/", url.path().c_str());
|
||||
EXPECT_STREQ("", url.query().c_str());
|
||||
|
||||
// Set component-wise
|
||||
url.set_host(TEST_HOST);
|
||||
url.set_port(80);
|
||||
url.set_path(TEST_PATH);
|
||||
url.set_query(TEST_QUERY);
|
||||
EXPECT_TRUE(url.valid());
|
||||
EXPECT_FALSE(url.secure());
|
||||
EXPECT_STREQ(TEST_HOST, url.host().c_str());
|
||||
EXPECT_EQ(80, url.port());
|
||||
EXPECT_STREQ(TEST_PATH, url.path().c_str());
|
||||
EXPECT_STREQ(TEST_QUERY, url.query().c_str());
|
||||
EXPECT_STREQ(TEST_HOST, url.address().c_str());
|
||||
EXPECT_STREQ(TEST_PATH TEST_QUERY, url.full_path().c_str());
|
||||
EXPECT_STREQ(TEST_URL, url.url().c_str());
|
||||
}
|
||||
|
||||
TEST(Url, EnsuresNonEmptyPath) {
|
||||
Url<char> url(TEST_PROTOCOL TEST_HOST);
|
||||
EXPECT_TRUE(url.valid());
|
||||
EXPECT_STREQ("/", url.path().c_str());
|
||||
|
||||
url.clear();
|
||||
EXPECT_STREQ("/", url.path().c_str());
|
||||
url.set_path("");
|
||||
EXPECT_STREQ("/", url.path().c_str());
|
||||
|
||||
url.clear();
|
||||
EXPECT_STREQ("/", url.path().c_str());
|
||||
url.set_full_path("");
|
||||
EXPECT_STREQ("/", url.path().c_str());
|
||||
}
|
||||
|
||||
TEST(Url, GetQueryAttributes) {
|
||||
Url<char> url(TEST_URL);
|
||||
std::string value;
|
||||
EXPECT_TRUE(url.get_attribute("query", &value));
|
||||
EXPECT_STREQ("x", value.c_str());
|
||||
value.clear();
|
||||
EXPECT_TRUE(url.get_attribute("attr", &value));
|
||||
EXPECT_STREQ("y", value.c_str());
|
||||
value.clear();
|
||||
EXPECT_FALSE(url.get_attribute("Query", &value));
|
||||
EXPECT_TRUE(value.empty());
|
||||
}
|
||||
|
||||
TEST(Url, SkipsUserAndPassword) {
|
||||
Url<char> url("https://mail.google.com:pwd@badsite.com:12345/asdf");
|
||||
EXPECT_TRUE(url.valid());
|
||||
EXPECT_TRUE(url.secure());
|
||||
EXPECT_STREQ("badsite.com", url.host().c_str());
|
||||
EXPECT_EQ(12345, url.port());
|
||||
EXPECT_STREQ("/asdf", url.path().c_str());
|
||||
EXPECT_STREQ("badsite.com:12345", url.address().c_str());
|
||||
}
|
||||
|
||||
TEST(Url, SkipsUser) {
|
||||
Url<char> url("https://mail.google.com@badsite.com:12345/asdf");
|
||||
EXPECT_TRUE(url.valid());
|
||||
EXPECT_TRUE(url.secure());
|
||||
EXPECT_STREQ("badsite.com", url.host().c_str());
|
||||
EXPECT_EQ(12345, url.port());
|
||||
EXPECT_STREQ("/asdf", url.path().c_str());
|
||||
EXPECT_STREQ("badsite.com:12345", url.address().c_str());
|
||||
}
|
||||
|
||||
TEST(HttpResponseData, parseLeaderHttp1_0) {
|
||||
static const char kResponseString[] = "HTTP/1.0 200 OK";
|
||||
HttpResponseData response;
|
||||
|
||||
@ -10,8 +10,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "rtc_base/httpcommon-inl.h"
|
||||
|
||||
#include "rtc_base/asyncsocket.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/httpserver.h"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user