This is an automated email from the ASF dual-hosted git repository.

jamesge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new b4c70ac  Rename URI.schema to scheme and calling schema/set_schema 
will be notified with deprecation
b4c70ac is described below

commit b4c70ac2b5f0eddf630030137df39df6f364a126
Author: jamesge <[email protected]>
AuthorDate: Tue Jan 7 16:09:51 2020 +0800

    Rename URI.schema to scheme and calling schema/set_schema will be notified 
with deprecation
---
 docs/cn/http_client.md                 |  2 +-
 docs/en/http_client.md                 |  2 +-
 src/brpc/details/http_parser.cpp       | 48 +++++++++++++++++-----------------
 src/brpc/details/http_parser.h         |  2 +-
 src/brpc/policy/http2_rpc_protocol.cpp |  4 +--
 src/brpc/policy/http_rpc_protocol.cpp  | 10 +++----
 src/brpc/uri.cpp                       | 34 ++++++++++++------------
 src/brpc/uri.h                         | 14 +++++-----
 test/brpc_uri_unittest.cpp             | 28 ++++++++++----------
 9 files changed, 73 insertions(+), 71 deletions(-)

diff --git a/docs/cn/http_client.md b/docs/cn/http_client.md
index f551ebc..90386b5 100644
--- a/docs/cn/http_client.md
+++ b/docs/cn/http_client.md
@@ -87,7 +87,7 @@ URL的一般形式如下图:
 //   |           |               |       |                |    |            |  
              |
 //   |       userinfo           host    port              |    |          
query          fragment
 //   |    \________________________________/\_____________|____|/ \__/        
\__/
-// schema                 |                          |    |    |    |          
|
+// scheme                 |                          |    |    |    |          
|
 //                    authority                      |    |    |    |          
|
 //                                                 path   |    |    
interpretable as keys
 //                                                        |    |
diff --git a/docs/en/http_client.md b/docs/en/http_client.md
index a350aa2..b8aab59 100644
--- a/docs/en/http_client.md
+++ b/docs/en/http_client.md
@@ -88,7 +88,7 @@ Genaral form of an URL:
 //   |           |               |       |                |    |            |  
              |
 //   |       userinfo           host    port              |    |          
query          fragment
 //   |    \________________________________/\_____________|____|/ \__/        
\__/
-// schema                 |                          |    |    |    |          
|
+// scheme                 |                          |    |    |    |          
|
 //                    authority                      |    |    |    |          
|
 //                                                 path   |    |    
interpretable as keys
 //                                                        |    |
diff --git a/src/brpc/details/http_parser.cpp b/src/brpc/details/http_parser.cpp
index 1c575f9..29e88fc 100644
--- a/src/brpc/details/http_parser.cpp
+++ b/src/brpc/details/http_parser.cpp
@@ -258,9 +258,9 @@ enum state
 
   , s_req_method
   , s_req_spaces_before_url
-  , s_req_schema
-  , s_req_schema_slash
-  , s_req_schema_slash_slash
+  , s_req_scheme
+  , s_req_scheme_slash
+  , s_req_scheme_slash_slash
   , s_req_server_start
   , s_req_server
   , s_req_server_with_at
@@ -343,9 +343,9 @@ const char* http_parser_state_name(unsigned int state) {
     case s_start_req: return "s_start_req";
     case s_req_method: return "s_req_method";
     case s_req_spaces_before_url: return "s_req_spaces_before_url";
-    case s_req_schema: return "s_req_schema";
-    case s_req_schema_slash: return "s_req_schema_slash";
-    case s_req_schema_slash_slash: return "s_req_schema_slash_slash";
+    case s_req_scheme: return "s_req_scheme";
+    case s_req_scheme_slash: return "s_req_scheme_slash";
+    case s_req_scheme_slash_slash: return "s_req_scheme_slash_slash";
     case s_req_server_start: return "s_req_server_start";
     case s_req_server: return "s_req_server";
     case s_req_server_with_at: return "s_req_server_with_at";
@@ -562,30 +562,30 @@ parse_url_char(enum state s, const char ch)
       }
 
       if (IS_ALPHA(ch)) {
-        return s_req_schema;
+        return s_req_scheme;
       }
 
       break;
 
-    case s_req_schema:
+    case s_req_scheme:
       if (IS_ALPHA(ch)) {
         return s;
       }
 
       if (ch == ':') {
-        return s_req_schema_slash;
+        return s_req_scheme_slash;
       }
 
       break;
 
-    case s_req_schema_slash:
+    case s_req_scheme_slash:
       if (ch == '/') {
-        return s_req_schema_slash_slash;
+        return s_req_scheme_slash_slash;
       }
 
       break;
 
-    case s_req_schema_slash_slash:
+    case s_req_scheme_slash_slash:
       if (ch == '/') {
         return s_req_server_start;
       }
@@ -725,9 +725,9 @@ size_t http_parser_execute (http_parser *parser,
     header_value_mark = data;
   switch (parser->state) {
   case s_req_path:
-  case s_req_schema:
-  case s_req_schema_slash:
-  case s_req_schema_slash_slash:
+  case s_req_scheme:
+  case s_req_scheme_slash:
+  case s_req_scheme_slash_slash:
   case s_req_server_start:
   case s_req_server:
   case s_req_server_with_at:
@@ -1160,9 +1160,9 @@ size_t http_parser_execute (http_parser *parser,
         break;
       }
 
-      case s_req_schema:
-      case s_req_schema_slash:
-      case s_req_schema_slash_slash:
+      case s_req_scheme:
+      case s_req_scheme_slash:
+      case s_req_scheme_slash_slash:
       case s_req_server_start:
       {
         enum state new_state;
@@ -2254,15 +2254,15 @@ http_parser_parse_url(const char *buf, size_t buflen, 
int is_connect,
         return 1;
 
       /* Skip delimeters */
-      case s_req_schema_slash:
-      case s_req_schema_slash_slash:
+      case s_req_scheme_slash:
+      case s_req_scheme_slash_slash:
       case s_req_server_start:
       case s_req_query_string_start:
       case s_req_fragment_start:
         continue;
 
-      case s_req_schema:
-        uf = UF_SCHEMA;
+      case s_req_scheme:
+        uf = UF_SCHEME;
         break;
 
       case s_req_server_with_at:
@@ -2302,9 +2302,9 @@ http_parser_parse_url(const char *buf, size_t buflen, int 
is_connect,
     old_uf = uf;
   }
 
-  /* host must be present if there is a schema */
+  /* host must be present if there is a scheme */
   /* parsing http:///toto will fail */
-  if ((u->field_set & ((1 << UF_SCHEMA) | (1 << UF_HOST))) != 0) {
+  if ((u->field_set & ((1 << UF_SCHEME) | (1 << UF_HOST))) != 0) {
     if (http_parse_host(buf, u, found_at) != 0) {
       return 1;
     }
diff --git a/src/brpc/details/http_parser.h b/src/brpc/details/http_parser.h
index c586e22..cd4c5cc 100644
--- a/src/brpc/details/http_parser.h
+++ b/src/brpc/details/http_parser.h
@@ -236,7 +236,7 @@ struct http_parser_settings {
 
 
 enum http_parser_url_fields
-  { UF_SCHEMA           = 0
+  { UF_SCHEME           = 0
   , UF_HOST             = 1
   , UF_PORT             = 2
   , UF_PATH             = 3
diff --git a/src/brpc/policy/http2_rpc_protocol.cpp 
b/src/brpc/policy/http2_rpc_protocol.cpp
index 1bf4159..a5e89d0 100644
--- a/src/brpc/policy/http2_rpc_protocol.cpp
+++ b/src/brpc/policy/http2_rpc_protocol.cpp
@@ -1263,7 +1263,7 @@ int 
H2StreamContext::ConsumeHeaders(butil::IOBufBytesIterator& it) {
             case 's':
                 if (strcmp(name + 2, /*:s*/"cheme") == 0) {
                     matched = true;
-                    h.uri().set_schema(pair.value);
+                    h.uri().set_scheme(pair.value);
                 } else if (strcmp(name + 2, /*:s*/"tatus") == 0) {
                     matched = true;
                     char* endptr = NULL;
@@ -1408,7 +1408,7 @@ H2UnsentRequest* H2UnsentRequest::New(Controller* c) {
         msg->push(common->H2_METHOD) = HttpMethod2Str(h.method());
     }
     // :scheme
-    const std::string* scheme = &h.uri().schema();
+    const std::string* scheme = &h.uri().scheme();
     if (scheme->empty()) {
         scheme = (c->is_ssl() ? &common->H2_SCHEME_HTTPS :
                   &common->H2_SCHEME_HTTP);
diff --git a/src/brpc/policy/http_rpc_protocol.cpp 
b/src/brpc/policy/http_rpc_protocol.cpp
index 41a61c2..450e28b 100644
--- a/src/brpc/policy/http_rpc_protocol.cpp
+++ b/src/brpc/policy/http_rpc_protocol.cpp
@@ -1492,23 +1492,23 @@ void ProcessHttpRequest(InputMessageBase *msg) {
 }
 
 bool ParseHttpServerAddress(butil::EndPoint* point, const char* 
server_addr_and_port) {
-    std::string schema;
+    std::string scheme;
     std::string host;
     int port = -1;
-    if (ParseURL(server_addr_and_port, &schema, &host, &port) != 0) {
+    if (ParseURL(server_addr_and_port, &scheme, &host, &port) != 0) {
         LOG(ERROR) << "Invalid address=`" << server_addr_and_port << '\'';
         return false;
     }
-    if (schema.empty() || schema == "http") {
+    if (scheme.empty() || scheme == "http") {
         if (port < 0) {
             port = 80;
         }
-    } else if (schema == "https") {
+    } else if (scheme == "https") {
         if (port < 0) {
             port = 443;
         }
     } else {
-        LOG(ERROR) << "Invalid schema=`" << schema << '\'';
+        LOG(ERROR) << "Invalid scheme=`" << scheme << '\'';
         return false;
     }
     if (str2endpoint(host.c_str(), port, point) != 0 &&
diff --git a/src/brpc/uri.cpp b/src/brpc/uri.cpp
index 5003de8..15ca9e9 100644
--- a/src/brpc/uri.cpp
+++ b/src/brpc/uri.cpp
@@ -41,7 +41,7 @@ void URI::Clear() {
     _path.clear();
     _user_info.clear();
     _fragment.clear();
-    _schema.clear();
+    _scheme.clear();
     _query.clear();
     _query_map.clear();
 }
@@ -55,7 +55,7 @@ void URI::Swap(URI &rhs) {
     _path.swap(rhs._path);
     _user_info.swap(rhs._user_info);
     _fragment.swap(rhs._fragment);
-    _schema.swap(rhs._schema);
+    _scheme.swap(rhs._scheme);
     _query.swap(rhs._query);
     _query_map.swap(rhs._query_map);
 }
@@ -138,7 +138,7 @@ static const char* const g_url_parsing_fast_action_map =
     g_url_parsing_fast_action_map_raw + 128;
 
 // This implementation is faster than http_parser_parse_url() and allows
-// ignoring of schema("http://";)
+// ignoring of scheme("http://";)
 int URI::SetHttpURL(const char* url) {
     Clear();
     
@@ -148,8 +148,8 @@ int URI::SetHttpURL(const char* url) {
         for (++p; *p == ' '; ++p) {}
     }
     const char* start = p;
-    // Find end of host, locate schema and user_info during the searching
-    bool need_schema = true;
+    // Find end of host, locate scheme and user_info during the searching
+    bool need_scheme = true;
     bool need_user_info = true;
     for (; true; ++p) {
         const char action = g_url_parsing_fast_action_map[(int)*p];
@@ -160,9 +160,9 @@ int URI::SetHttpURL(const char* url) {
             break;
         }
         if (*p == ':') {
-            if (p[1] == '/' && p[2] == '/' && need_schema) {
-                need_schema = false;
-                _schema.assign(start, p - start);
+            if (p[1] == '/' && p[2] == '/' && need_scheme) {
+                need_scheme = false;
+                _scheme.assign(start, p - start);
                 p += 2;
                 start = p + 1;
             }
@@ -226,15 +226,15 @@ int URI::SetHttpURL(const char* url) {
 }
 
 int ParseURL(const char* url,
-             std::string* schema_out, std::string* host_out, int* port_out) {
+             std::string* scheme_out, std::string* host_out, int* port_out) {
     const char* p = url;
     // skip heading blanks
     if (*p == ' ') {
         for (++p; *p == ' '; ++p) {}
     }
     const char* start = p;
-    // Find end of host, locate schema and user_info during the searching
-    bool need_schema = true;
+    // Find end of host, locate scheme and user_info during the searching
+    bool need_scheme = true;
     bool need_user_info = true;
     for (; true; ++p) {
         const char action = g_url_parsing_fast_action_map[(int)*p];
@@ -245,10 +245,10 @@ int ParseURL(const char* url,
             break;
         }
         if (*p == ':') {
-            if (p[1] == '/' && p[2] == '/' && need_schema) {
-                need_schema = false;
-                if (schema_out) {
-                    schema_out->assign(start, p - start);
+            if (p[1] == '/' && p[2] == '/' && need_scheme) {
+                need_scheme = false;
+                if (scheme_out) {
+                    scheme_out->assign(start, p - start);
                 }
                 p += 2;
                 start = p + 1;
@@ -279,8 +279,8 @@ int ParseURL(const char* url,
 
 void URI::Print(std::ostream& os) const {
     if (!_host.empty()) {
-        if (!_schema.empty()) {
-            os << _schema << "://";
+        if (!_scheme.empty()) {
+            os << _scheme << "://";
         } else {
             os << "http://";;
         }
diff --git a/src/brpc/uri.h b/src/brpc/uri.h
index 42e8d0b..3fbb154 100644
--- a/src/brpc/uri.h
+++ b/src/brpc/uri.h
@@ -37,7 +37,7 @@ namespace brpc {
 //   |           |               |       |                |    |            |  
              |
 //   |       userinfo           host    port              |    |          
query          fragment
 //   |    \________________________________/\_____________|____|/ \__/        
\__/
-// schema                 |                          |    |    |    |          
|
+// scheme                 |                          |    |    |    |          
|
 //                    authority                      |    |    |    |          
|
 //                                                 path   |    |    
interpretable as keys
 //                                                        |    |
@@ -78,7 +78,8 @@ public:
     const butil::Status& status() const { return _st; }
 
     // Sub fields. Empty string if the field is not set.
-    const std::string& schema() const { return _schema; } // scheme in http2
+       const std::string& scheme() const { return _scheme; }
+    BAIDU_DEPRECATED const std::string& schema() const { return scheme(); }
     const std::string& host() const { return _host; }
     int port() const { return _port; } // -1 on unset.
     const std::string& path() const { return _path; }
@@ -92,7 +93,8 @@ public:
 
     // Overwrite parts of the URL.
     // NOTE: The input MUST be guaranteed to be valid.
-    void set_schema(const std::string& schema) { _schema = schema; }
+    void set_scheme(const std::string& scheme) { _scheme = scheme; }
+    BAIDU_DEPRECATED void set_schema(const std::string& s) { set_scheme(s); }
     void set_path(const std::string& path) { _path = path; }
     void set_host(const std::string& host) { _host = host; }
     void set_port(int port) { _port = port; }
@@ -151,14 +153,14 @@ friend class HttpMessage;
     std::string                             _path;
     std::string                             _user_info;
     std::string                             _fragment;
-    std::string                             _schema;
+    std::string                             _scheme;
     mutable std::string                     _query;
     mutable QueryMap _query_map;
 };
 
-// Parse host/port/schema from `url' if the corresponding parameter is not 
NULL.
+// Parse host/port/scheme from `url' if the corresponding parameter is not 
NULL.
 // Returns 0 on success, -1 otherwise.
-int ParseURL(const char* url, std::string* schema, std::string* host, int* 
port);
+int ParseURL(const char* url, std::string* scheme, std::string* host, int* 
port);
 
 inline void URI::SetQuery(const std::string& key, const std::string& value) {
     get_query_map()[key] = value;
diff --git a/test/brpc_uri_unittest.cpp b/test/brpc_uri_unittest.cpp
index 51508e6..178b34f 100644
--- a/test/brpc_uri_unittest.cpp
+++ b/test/brpc_uri_unittest.cpp
@@ -23,7 +23,7 @@ TEST(URITest, everything) {
     brpc::URI uri;
     std::string uri_str = " 
foobar://user:[email protected]:80/s?wd=uri#frag  ";
     ASSERT_EQ(0, uri.SetHttpURL(uri_str));
-    ASSERT_EQ("foobar", uri.schema());
+    ASSERT_EQ("foobar", uri.scheme());
     ASSERT_EQ(80, uri.port());
     ASSERT_EQ("www.baidu.com", uri.host());
     ASSERT_EQ("/s", uri.path());
@@ -33,11 +33,11 @@ TEST(URITest, everything) {
     ASSERT_EQ(*uri.GetQuery("wd"), "uri");
     ASSERT_FALSE(uri.GetQuery("nonkey"));
 
-    std::string schema;
+    std::string scheme;
     std::string host_out;
     int port_out = -1;
-    brpc::ParseURL(uri_str.c_str(), &schema, &host_out, &port_out);
-    ASSERT_EQ("foobar", schema);
+    brpc::ParseURL(uri_str.c_str(), &scheme, &host_out, &port_out);
+    ASSERT_EQ("foobar", scheme);
     ASSERT_EQ("www.baidu.com", host_out);
     ASSERT_EQ(80, port_out);
 }
@@ -45,7 +45,7 @@ TEST(URITest, everything) {
 TEST(URITest, only_host) {
     brpc::URI uri;
     ASSERT_EQ(0, uri.SetHttpURL("  foo1://www.baidu1.com?wd=uri2&nonkey=22 "));
-    ASSERT_EQ("foo1", uri.schema());
+    ASSERT_EQ("foo1", uri.scheme());
     ASSERT_EQ(-1, uri.port());
     ASSERT_EQ("www.baidu1.com", uri.host());
     ASSERT_EQ("", uri.path());
@@ -58,7 +58,7 @@ TEST(URITest, only_host) {
     ASSERT_EQ(*uri.GetQuery("nonkey"), "22");
 
     ASSERT_EQ(0, uri.SetHttpURL("foo2://www.baidu2.com:1234?wd=uri2&nonkey=22 
"));
-    ASSERT_EQ("foo2", uri.schema());
+    ASSERT_EQ("foo2", uri.scheme());
     ASSERT_EQ(1234, uri.port());
     ASSERT_EQ("www.baidu2.com", uri.host());
     ASSERT_EQ("", uri.path());
@@ -71,7 +71,7 @@ TEST(URITest, only_host) {
     ASSERT_EQ(*uri.GetQuery("nonkey"), "22");
 
     ASSERT_EQ(0, uri.SetHttpURL(" www.baidu3.com:4321 "));
-    ASSERT_EQ("", uri.schema());
+    ASSERT_EQ("", uri.scheme());
     ASSERT_EQ(4321, uri.port());
     ASSERT_EQ("www.baidu3.com", uri.host());
     ASSERT_EQ("", uri.path());
@@ -80,7 +80,7 @@ TEST(URITest, only_host) {
     ASSERT_EQ(0, uri.QueryCount());
     
     ASSERT_EQ(0, uri.SetHttpURL(" www.baidu4.com "));
-    ASSERT_EQ("", uri.schema());
+    ASSERT_EQ("", uri.scheme());
     ASSERT_EQ(-1, uri.port());
     ASSERT_EQ("www.baidu4.com", uri.host());
     ASSERT_EQ("", uri.path());
@@ -89,10 +89,10 @@ TEST(URITest, only_host) {
     ASSERT_EQ(0, uri.QueryCount());
 }
 
-TEST(URITest, no_schema) {
+TEST(URITest, no_scheme) {
     brpc::URI uri;
     ASSERT_EQ(0, uri.SetHttpURL(" 
user:[email protected]/s?wd=uri2&nonkey=22#frag "));
-    ASSERT_EQ("", uri.schema());
+    ASSERT_EQ("", uri.scheme());
     ASSERT_EQ(-1, uri.port());
     ASSERT_EQ("www.baidu1.com", uri.host());
     ASSERT_EQ("/s", uri.path());
@@ -104,10 +104,10 @@ TEST(URITest, no_schema) {
     ASSERT_EQ(*uri.GetQuery("nonkey"), "22");
 }
 
-TEST(URITest, no_schema_and_user_info) {
+TEST(URITest, no_scheme_and_user_info) {
     brpc::URI uri;
     ASSERT_EQ(0, uri.SetHttpURL(" www.baidu2.com/s?wd=uri2&nonkey=22#frag "));
-    ASSERT_EQ("", uri.schema());
+    ASSERT_EQ("", uri.scheme());
     ASSERT_EQ(-1, uri.port());
     ASSERT_EQ("www.baidu2.com", uri.host());
     ASSERT_EQ("/s", uri.path());
@@ -122,7 +122,7 @@ TEST(URITest, no_schema_and_user_info) {
 TEST(URITest, no_host) {
     brpc::URI uri;
     ASSERT_EQ(0, uri.SetHttpURL(" /sb?wd=uri3#frag2 ")) << uri.status();
-    ASSERT_EQ("", uri.schema());
+    ASSERT_EQ("", uri.scheme());
     ASSERT_EQ(-1, uri.port());
     ASSERT_EQ("", uri.host());
     ASSERT_EQ("/sb", uri.path());
@@ -134,7 +134,7 @@ TEST(URITest, no_host) {
 
     // set_path should do as its name says.
     uri.set_path("/x/y/z/");
-    ASSERT_EQ("", uri.schema());
+    ASSERT_EQ("", uri.scheme());
     ASSERT_EQ(-1, uri.port());
     ASSERT_EQ("", uri.host());
     ASSERT_EQ("/x/y/z/", uri.path());


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to