Commit 61f42550 authored by octal's avatar octal

Client will now detect when the remote closes the connection

parent 0c3af626
...@@ -94,6 +94,7 @@ struct Connection : public std::enable_shared_from_this<Connection> { ...@@ -94,6 +94,7 @@ struct Connection : public std::enable_shared_from_this<Connection> {
Fd fd; Fd fd;
void handleResponsePacket(const char* buffer, size_t totalBytes); void handleResponsePacket(const char* buffer, size_t totalBytes);
void handleError(const char* error);
void handleTimeout(); void handleTimeout();
std::string dump() const; std::string dump() const;
......
...@@ -42,7 +42,7 @@ splitUrl(const std::string& url) { ...@@ -42,7 +42,7 @@ splitUrl(const std::string& url) {
match_literal('.', cursor); match_literal('.', cursor);
StreamCursor::Token hostToken(cursor); StreamCursor::Token hostToken(cursor);
match_until('/', cursor); match_until({ '?', '/' }, cursor);
StringView host(hostToken.rawText(), hostToken.size()); StringView host(hostToken.rawText(), hostToken.size());
StringView page(cursor.offset(), buf.endptr()); StringView page(cursor.offset(), buf.endptr());
...@@ -114,8 +114,12 @@ namespace { ...@@ -114,8 +114,12 @@ namespace {
auto host = s.first; auto host = s.first;
auto path = s.second; auto path = s.second;
auto pathStr = path.toString();
OUT(os << request.method() << " "); OUT(os << request.method() << " ");
OUT(os << path.toString()); if (pathStr[0] != '/')
OUT(os << '/');
OUT(os << pathStr);
OUT(os << " HTTP/1.1" << crlf); OUT(os << " HTTP/1.1" << crlf);
if (!writeCookies(request.cookies(), buf)) return false; if (!writeCookies(request.cookies(), buf)) return false;
...@@ -322,17 +326,15 @@ Transport::handleIncoming(const std::shared_ptr<Connection>& connection) { ...@@ -322,17 +326,15 @@ Transport::handleIncoming(const std::shared_ptr<Connection>& connection) {
handleResponsePacket(connection, buffer, totalBytes); handleResponsePacket(connection, buffer, totalBytes);
} }
} else { } else {
if (errno == ECONNRESET) { connection->handleError(strerror(errno));
}
else {
throw std::runtime_error(strerror(errno));
}
} }
break; break;
} }
else if (bytes == 0) { else if (bytes == 0) {
if (totalBytes > 0) { if (totalBytes > 0) {
handleResponsePacket(connection, buffer, totalBytes); handleResponsePacket(connection, buffer, totalBytes);
} else {
connection->handleError("Remote closed connection");
} }
connections.erase(connection->fd); connections.erase(connection->fd);
connection->close(); connection->close();
...@@ -462,6 +464,18 @@ Connection::handleResponsePacket(const char* buffer, size_t bytes) { ...@@ -462,6 +464,18 @@ Connection::handleResponsePacket(const char* buffer, size_t bytes) {
} }
} }
void
Connection::handleError(const char* error) {
auto req = std::move(inflightRequests.front());
if (req.timer) {
req.timer->disarm();
timerPool_.releaseTimer(req.timer);
}
req.reject(Net::Error(error));
req.onDone();
}
void void
Connection::handleTimeout() { Connection::handleTimeout() {
auto req = std::move(inflightRequests.front()); auto req = std::move(inflightRequests.front());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment