mirror of https://gitee.com/bigwinds/arangodb
fixed server gone reconnet
This commit is contained in:
parent
cefba69ab5
commit
ff199b60eb
|
@ -106,26 +106,32 @@ namespace triagens {
|
||||||
/// @brief send out a request, creating a new HttpResult object
|
/// @brief send out a request, creating a new HttpResult object
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SimpleHttpResult* SimpleHttpClient::request (rest::HttpRequest::HttpRequestType method,
|
SimpleHttpResult* SimpleHttpClient::request (
|
||||||
std::string const& location,
|
rest::HttpRequest::HttpRequestType method,
|
||||||
char const* body,
|
std::string const& location,
|
||||||
size_t bodyLength,
|
char const* body,
|
||||||
std::map<std::string, std::string> const& headerFields) {
|
size_t bodyLength,
|
||||||
|
std::map<std::string, std::string> const& headerFields) {
|
||||||
|
|
||||||
// ensure connection has not yet been invalidated
|
// ensure connection has not yet been invalidated
|
||||||
TRI_ASSERT(_connection != nullptr);
|
TRI_ASSERT(_connection != nullptr);
|
||||||
|
|
||||||
|
// ensure that result is empty
|
||||||
TRI_ASSERT(_result == nullptr);
|
TRI_ASSERT(_result == nullptr);
|
||||||
|
|
||||||
|
// create a new result
|
||||||
_result = new SimpleHttpResult;
|
_result = new SimpleHttpResult;
|
||||||
|
|
||||||
|
// reset error message
|
||||||
_errorMessage = "";
|
_errorMessage = "";
|
||||||
|
|
||||||
// set body
|
// set body
|
||||||
setRequest(method, rewriteLocation(location), body, bodyLength, headerFields);
|
setRequest(method, rewriteLocation(location), body, bodyLength, headerFields);
|
||||||
|
|
||||||
|
// ensure state
|
||||||
TRI_ASSERT(_state == IN_CONNECT || _state == IN_WRITE);
|
TRI_ASSERT(_state == IN_CONNECT || _state == IN_WRITE);
|
||||||
|
|
||||||
|
// respect timeout
|
||||||
double endTime = now() + _requestTimeout;
|
double endTime = now() + _requestTimeout;
|
||||||
double remainingTime = _requestTimeout;
|
double remainingTime = _requestTimeout;
|
||||||
|
|
||||||
|
@ -161,6 +167,7 @@ namespace triagens {
|
||||||
_state = IN_READ_HEADER;
|
_state = IN_READ_HEADER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +188,13 @@ namespace triagens {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! progress) {
|
if (! progress) {
|
||||||
if (_state == IN_READ_BODY && ! _result->hasContentLength()) {
|
// write might succeed even if the server has closed the connection
|
||||||
|
if (_state == IN_READ_HEADER && 0 == _readBuffer.length()) {
|
||||||
|
this->close();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (_state == IN_READ_BODY && ! _result->hasContentLength()) {
|
||||||
_result->setContentLength(_readBuffer.length() - _readBufferOffset);
|
_result->setContentLength(_readBuffer.length() - _readBufferOffset);
|
||||||
readBody();
|
readBody();
|
||||||
|
|
||||||
|
@ -192,6 +205,11 @@ namespace triagens {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
this->close();
|
||||||
|
_state = DEAD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we made progress
|
// we made progress
|
||||||
|
@ -328,9 +346,11 @@ namespace triagens {
|
||||||
char const* body,
|
char const* body,
|
||||||
size_t bodyLength,
|
size_t bodyLength,
|
||||||
std::map<std::string, std::string> const& headerFields) {
|
std::map<std::string, std::string> const& headerFields) {
|
||||||
|
// clear read-buffer (no pipeling!)
|
||||||
_readBufferOffset = 0;
|
_readBufferOffset = 0;
|
||||||
_readBuffer.reset();
|
_readBuffer.reset();
|
||||||
|
|
||||||
|
// set HTTP method
|
||||||
_method = method;
|
_method = method;
|
||||||
|
|
||||||
// now fill the write buffer
|
// now fill the write buffer
|
||||||
|
@ -375,8 +395,10 @@ namespace triagens {
|
||||||
string foundPrefix;
|
string foundPrefix;
|
||||||
string foundValue;
|
string foundValue;
|
||||||
std::vector<std::pair<std::string, std::string>>::iterator i = _pathToBasicAuth.begin();
|
std::vector<std::pair<std::string, std::string>>::iterator i = _pathToBasicAuth.begin();
|
||||||
|
|
||||||
for (; i != _pathToBasicAuth.end(); ++i) {
|
for (; i != _pathToBasicAuth.end(); ++i) {
|
||||||
string& f = i->first;
|
string& f = i->first;
|
||||||
|
|
||||||
if (l.find(f) == 0) {
|
if (l.find(f) == 0) {
|
||||||
// f is prefix of l
|
// f is prefix of l
|
||||||
if (f.length() > foundPrefix.length()) {
|
if (f.length() > foundPrefix.length()) {
|
||||||
|
@ -385,6 +407,7 @@ namespace triagens {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! foundValue.empty()) {
|
if (! foundValue.empty()) {
|
||||||
_writeBuffer.appendText("Authorization: Basic ");
|
_writeBuffer.appendText("Authorization: Basic ");
|
||||||
_writeBuffer.appendText(foundValue);
|
_writeBuffer.appendText(foundValue);
|
||||||
|
@ -421,25 +444,25 @@ namespace triagens {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// close connection to reset all read and write buffers
|
||||||
if (_state != FINISHED) {
|
if (_state != FINISHED) {
|
||||||
// close connection to reset all read and write buffers
|
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we are connected, start with writing
|
||||||
if (_connection->isConnected()) {
|
if (_connection->isConnected()) {
|
||||||
// we are connected, start with writing
|
|
||||||
_state = IN_WRITE;
|
_state = IN_WRITE;
|
||||||
_written = 0;
|
_written = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// connect to server
|
||||||
else {
|
else {
|
||||||
// connect to server
|
|
||||||
_state = IN_CONNECT;
|
_state = IN_CONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_ASSERT(_state == IN_CONNECT || _state == IN_WRITE);
|
TRI_ASSERT(_state == IN_CONNECT || _state == IN_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// private methods
|
// private methods
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue