feat: tc_http dorequest support https

pull/261/head
ruanshudong 2022-10-26 21:18:20 +08:00
parent b0e2a89e4b
commit 019b0c914c
9 changed files with 5334 additions and 5559 deletions

View File

@ -30,6 +30,8 @@ namespace TestApp
{ throw std::runtime_error("callback_pushMsg() override incorrect."); }
virtual void callback_pushMsg_exception(tars::Int32 ret)
{ throw std::runtime_error("callback_pushMsg_exception() override incorrect."); }
virtual void callback_pushMsg(tars::Int32 ret, std::string&& sRsp)
{ callback_pushMsg(ret, sRsp); }
public:
virtual const map<std::string, std::string> & getResponseContext() const
@ -96,7 +98,7 @@ namespace TestApp
pCbtd->setResponseContext(_msg_->response->context);
callback_pushMsg(_ret, sRsp);
callback_pushMsg(_ret, std::move(sRsp));
pCbtd->delResponseContext();
@ -246,7 +248,7 @@ namespace TestApp
_is.read(sRsp, 1, true);
setResponseContext(_msg_->response->context);
callback_pushMsg(_ret, sRsp);
callback_pushMsg(_ret, std::move(sRsp));
}
catch(std::exception &ex)

File diff suppressed because it is too large Load Diff

View File

@ -511,7 +511,7 @@ int yy_flex_debug = 0;
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 1 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
/**
* Tencent is pleased to support the open source community by making Tars available.
*
@ -527,7 +527,7 @@ char *yytext;
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#line 20 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 20 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
#include <map>
#include <string>
#include <sstream>
@ -776,7 +776,7 @@ YY_DECL
}
{
#line 67 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 67 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
#line 782 "tars.lex.cpp"
@ -848,12 +848,12 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 69 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 69 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{ BEGIN(INCL); }
YY_BREAK
case 2:
YY_RULE_SETUP
#line 71 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 71 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
if ( include_file_stack_ptr >= MAX_INCLUDE_DEPTH )
{
@ -886,7 +886,7 @@ YY_RULE_SETUP
YY_BREAK
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(INCL):
#line 101 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 101 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
--include_file_stack_ptr;
if ( include_file_stack_ptr < 0 )
@ -905,14 +905,14 @@ case YY_STATE_EOF(INCL):
YY_BREAK
case 3:
YY_RULE_SETUP
#line 117 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 117 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
return TARS_SCOPE_DELIMITER;
}
YY_BREAK
case 4:
YY_RULE_SETUP
#line 121 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 121 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
// C++ comment
bool e = false;
@ -933,7 +933,7 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
#line 139 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 139 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
// C comment
bool e = false;
@ -984,7 +984,7 @@ YY_RULE_SETUP
YY_BREAK
case 6:
YY_RULE_SETUP
#line 187 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 187 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
StringGrammarPtr ident = new StringGrammar;
ident->v = yytext;
@ -995,7 +995,7 @@ YY_RULE_SETUP
case 7:
/* rule 7 can match eol */
YY_RULE_SETUP
#line 194 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 194 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
StringGrammarPtr ident = new StringGrammar;
ident->v = yytext;
@ -1008,7 +1008,7 @@ YY_RULE_SETUP
YY_BREAK
case 8:
YY_RULE_SETUP
#line 204 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 204 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
StringGrammarPtr str = new StringGrammar;
bool e = false;
@ -1123,7 +1123,7 @@ YY_RULE_SETUP
YY_BREAK
case 9:
YY_RULE_SETUP
#line 316 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 316 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
errno = 0;
IntergerGrammarPtr ptr = new IntergerGrammar;
@ -1148,7 +1148,7 @@ YY_RULE_SETUP
YY_BREAK
case 10:
YY_RULE_SETUP
#line 338 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 338 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
errno = 0;
FloatGrammarPtr ptr = new FloatGrammar;
@ -1183,7 +1183,7 @@ YY_RULE_SETUP
case 11:
/* rule 11 can match eol */
YY_RULE_SETUP
#line 369 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 369 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
if(yytext[0] == '\n')
{
@ -1193,7 +1193,7 @@ YY_RULE_SETUP
YY_BREAK
case 12:
YY_RULE_SETUP
#line 376 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 376 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
{
if(yytext[0] < 32 || yytext[0] > 126)
{
@ -1212,7 +1212,7 @@ YY_RULE_SETUP
YY_BREAK
case 13:
YY_RULE_SETUP
#line 392 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 392 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"
ECHO;
YY_BREAK
#line 1218 "tars.lex.cpp"
@ -2230,7 +2230,7 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 392 "/Volumes/MyData/centos/Tars/framework/tarscpp/tools/tarsgrammar/tars.l"
#line 392 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l"

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,14 @@
/* A Bison parser, made by GNU Bison 2.3. */
/* A Bison parser, made by GNU Bison 3.7.6. */
/* Skeleton interface for Bison's Yacc-like parsers in C
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
Inc.
This program is free software; you can redistribute it and/or modify
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -16,9 +16,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
@ -33,87 +31,74 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_YY_TARS_TAB_HPP_INCLUDED
# define YY_YY_TARS_TAB_HPP_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token kinds. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
TARS_VOID = 258,
TARS_STRUCT = 259,
TARS_BOOL = 260,
TARS_BYTE = 261,
TARS_SHORT = 262,
TARS_INT = 263,
TARS_DOUBLE = 264,
TARS_FLOAT = 265,
TARS_LONG = 266,
TARS_STRING = 267,
TARS_VECTOR = 268,
TARS_MAP = 269,
TARS_NAMESPACE = 270,
TARS_INTERFACE = 271,
TARS_IDENTIFIER = 272,
TARS_OUT = 273,
TARS_OP = 274,
TARS_KEY = 275,
TARS_ROUTE_KEY = 276,
TARS_REQUIRE = 277,
TARS_OPTIONAL = 278,
TARS_CONST_INTEGER = 279,
TARS_CONST_FLOAT = 280,
TARS_FALSE = 281,
TARS_TRUE = 282,
TARS_STRING_LITERAL = 283,
TARS_SCOPE_DELIMITER = 284,
TARS_CONST = 285,
TARS_ENUM = 286,
TARS_UNSIGNED = 287,
BAD_CHAR = 288
};
enum yytokentype
{
YYEMPTY = -2,
YYEOF = 0, /* "end of file" */
YYerror = 256, /* error */
YYUNDEF = 257, /* "invalid token" */
TARS_VOID = 258, /* TARS_VOID */
TARS_STRUCT = 259, /* TARS_STRUCT */
TARS_BOOL = 260, /* TARS_BOOL */
TARS_BYTE = 261, /* TARS_BYTE */
TARS_SHORT = 262, /* TARS_SHORT */
TARS_INT = 263, /* TARS_INT */
TARS_DOUBLE = 264, /* TARS_DOUBLE */
TARS_FLOAT = 265, /* TARS_FLOAT */
TARS_LONG = 266, /* TARS_LONG */
TARS_STRING = 267, /* TARS_STRING */
TARS_VECTOR = 268, /* TARS_VECTOR */
TARS_MAP = 269, /* TARS_MAP */
TARS_NAMESPACE = 270, /* TARS_NAMESPACE */
TARS_INTERFACE = 271, /* TARS_INTERFACE */
TARS_IDENTIFIER = 272, /* TARS_IDENTIFIER */
TARS_OUT = 273, /* TARS_OUT */
TARS_OP = 274, /* TARS_OP */
TARS_KEY = 275, /* TARS_KEY */
TARS_ROUTE_KEY = 276, /* TARS_ROUTE_KEY */
TARS_REQUIRE = 277, /* TARS_REQUIRE */
TARS_OPTIONAL = 278, /* TARS_OPTIONAL */
TARS_CONST_INTEGER = 279, /* TARS_CONST_INTEGER */
TARS_CONST_FLOAT = 280, /* TARS_CONST_FLOAT */
TARS_FALSE = 281, /* TARS_FALSE */
TARS_TRUE = 282, /* TARS_TRUE */
TARS_STRING_LITERAL = 283, /* TARS_STRING_LITERAL */
TARS_SCOPE_DELIMITER = 284, /* TARS_SCOPE_DELIMITER */
TARS_CONST = 285, /* TARS_CONST */
TARS_ENUM = 286, /* TARS_ENUM */
TARS_UNSIGNED = 287, /* TARS_UNSIGNED */
BAD_CHAR = 288 /* BAD_CHAR */
};
typedef enum yytokentype yytoken_kind_t;
#endif
/* Tokens. */
#define TARS_VOID 258
#define TARS_STRUCT 259
#define TARS_BOOL 260
#define TARS_BYTE 261
#define TARS_SHORT 262
#define TARS_INT 263
#define TARS_DOUBLE 264
#define TARS_FLOAT 265
#define TARS_LONG 266
#define TARS_STRING 267
#define TARS_VECTOR 268
#define TARS_MAP 269
#define TARS_NAMESPACE 270
#define TARS_INTERFACE 271
#define TARS_IDENTIFIER 272
#define TARS_OUT 273
#define TARS_OP 274
#define TARS_KEY 275
#define TARS_ROUTE_KEY 276
#define TARS_REQUIRE 277
#define TARS_OPTIONAL 278
#define TARS_CONST_INTEGER 279
#define TARS_CONST_FLOAT 280
#define TARS_FALSE 281
#define TARS_TRUE 282
#define TARS_STRING_LITERAL 283
#define TARS_SCOPE_DELIMITER 284
#define TARS_CONST 285
#define TARS_ENUM 286
#define TARS_UNSIGNED 287
#define BAD_CHAR 288
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_TARS_TAB_HPP_INCLUDED */

View File

@ -887,4 +887,26 @@ TEST_F(UtilHttpTest, testIncrementDecode3)
// ASSERT_TRUE(flag);
ASSERT_TRUE(rsp.getContent() == data);
}
}
TEST_F(UtilHttpTest, testBaidus) //此时使用的是TEST_F宏
{
string url = "https://www.baidu.com";
TC_HttpRequest stHttpReq;
stHttpReq.setUserAgent("E71/SymbianOS/9.1 Series60/3.0");
stHttpReq.setHeader("Connection", "Close");
stHttpReq.setAcceptEncoding("gzip, deflate, br");
stHttpReq.setGetRequest(url);
string sSendBuffer = stHttpReq.encode();
TC_HttpResponse stHttpRsp;
int iRet = stHttpReq.doRequest(stHttpRsp, 5000);
LOG_CONSOLE_DEBUG << TC_Common::tostr(stHttpRsp.getHeaders().begin(), stHttpRsp.getHeaders().end(), " ") << endl;
ASSERT_TRUE(iRet == 0);
ASSERT_TRUE(stHttpRsp.getHeaders().size() > 5);
ASSERT_TRUE(stHttpRsp.getContentLength() == stHttpRsp.getContent().length());
}

View File

@ -542,7 +542,9 @@ public:
/**EM_CONNECT:Server Connection Failed**/
EM_CONNECT = -6, /** EM_CONNECT : 服务器连接失败*/
/**EM_SOCKET : SOCKET Initialize Failed**/
EM_SOCKET = -7 /**EM_SOCKET : SOCKET初始化失败*/
EM_SOCKET = -7, /**EM_SOCKET : SOCKET初始化失败*/
/**EM_HTTPS : HTTPS send Failed**/
EM_HTTPS = -8 /**EM_HTTPS : 发送https请求失败*/
};
protected:

View File

@ -1753,6 +1753,23 @@ protected:
* @brief Resolve URL
*/
void parseURL(const string& sUrl);
/**
*
* @param in
* @param tcpClient
* @return
*/
int sendNetBuffer(TC_NetWorkBuffer &in, TC_TCPClient &tcpClient);
/**
* http
* @param sendBuffer
* @param tcpClient
* @param stHttpRep
* @param iTimeout
* @return
*/
int doRequest(const string &sendBuffer, TC_TCPClient &tcpClient, TC_HttpResponse &stHttpRep);
protected:

File diff suppressed because it is too large Load Diff