Simplify code

This commit is contained in:
halx99 2021-06-25 08:18:32 +08:00 committed by GitHub
parent 01f3c57e15
commit c7dd59b2ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 9 deletions

View File

@ -5,7 +5,7 @@
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2021 Bytedance Inc. Copyright (c) 2021 Bytedance Inc.
http://www.cocos2d-x.org https://adxe.org
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -108,7 +108,7 @@ HttpClient::HttpClient()
: _isInited(false) : _isInited(false)
, _dispatchOnWorkThread(false) , _dispatchOnWorkThread(false)
, _timeoutForConnect(30) , _timeoutForConnect(30)
, _timeoutForRead(10) , _timeoutForRead(60)
, _cookie(nullptr) , _cookie(nullptr)
, _clearResponsePredicate(nullptr) , _clearResponsePredicate(nullptr)
{ {
@ -132,7 +132,6 @@ HttpClient::~HttpClient()
CCLOG("HttpClient destructor"); CCLOG("HttpClient destructor");
} }
//Add a get task to queue
bool HttpClient::send(HttpRequest* request) bool HttpClient::send(HttpRequest* request)
{ {
if (!request) if (!request)
@ -154,7 +153,6 @@ int HttpClient::tryTakeAvailChannel() {
return -1; return -1;
} }
// Process Response
void HttpClient::processResponse(HttpResponse* response, const std::string& url) { void HttpClient::processResponse(HttpResponse* response, const std::string& url) {
auto channelIndex = tryTakeAvailChannel(); auto channelIndex = tryTakeAvailChannel();
response->retain(); response->retain();
@ -196,12 +194,11 @@ void HttpClient::handleNetworkEvent(yasio::io_event* event) {
case YEK_ON_OPEN: case YEK_ON_OPEN:
if (event->status() == 0) { if (event->status() == 0) {
obstream obs; obstream obs;
bool usePostData; bool usePostData = false;
auto request = response->getHttpRequest(); auto request = response->getHttpRequest();
switch (request->getRequestType()) { switch (request->getRequestType()) {
case HttpRequest::Type::GET: case HttpRequest::Type::GET:
obs.write_bytes("GET"); obs.write_bytes("GET");
usePostData = false;
break; break;
case HttpRequest::Type::POST: case HttpRequest::Type::POST:
obs.write_bytes("POST"); obs.write_bytes("POST");
@ -209,7 +206,6 @@ void HttpClient::handleNetworkEvent(yasio::io_event* event) {
break; break;
case HttpRequest::Type::DELETE: case HttpRequest::Type::DELETE:
obs.write_bytes("DELETE"); obs.write_bytes("DELETE");
usePostData = false;
break; break;
case HttpRequest::Type::PUT: case HttpRequest::Type::PUT:
obs.write_bytes("PUT"); obs.write_bytes("PUT");
@ -217,7 +213,6 @@ void HttpClient::handleNetworkEvent(yasio::io_event* event) {
break; break;
default: default:
obs.write_bytes("GET"); obs.write_bytes("GET");
usePostData = false;
break; break;
} }
obs.write_bytes(" "); obs.write_bytes(" ");
@ -393,4 +388,3 @@ const std::string& HttpClient::getSSLVerification()
NS_CC_END NS_CC_END