mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-28 00:06:09 +03:00
Handle payload data immediately after HTTP headers
In HttpProxySocket there can be data immediately after HTTP headers, as in the case of fast HTTP CONNECT. Instead of reporting an error, handle this case by returning the data after HTTP headers in the next Read() call.
This commit is contained in:
parent
75c9bab359
commit
62e5e9cfff
@ -142,6 +142,19 @@ int HttpProxySocket::Read(IOBuffer* buf,
|
|||||||
DCHECK(!user_callback_);
|
DCHECK(!user_callback_);
|
||||||
DCHECK(callback);
|
DCHECK(callback);
|
||||||
|
|
||||||
|
if (!buffer_.empty()) {
|
||||||
|
int data_len = buffer_.size();
|
||||||
|
if (data_len <= buf_len) {
|
||||||
|
std::memcpy(buf->data(), buffer_.data(), data_len);
|
||||||
|
buffer_.clear();
|
||||||
|
} else {
|
||||||
|
std::memcpy(buf->data(), buffer_.data(), buf_len);
|
||||||
|
buffer_ = buffer_.substr(buf_len);
|
||||||
|
}
|
||||||
|
was_ever_used_ = true;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
int rv = transport_->Read(
|
int rv = transport_->Read(
|
||||||
buf, buf_len,
|
buf, buf_len,
|
||||||
base::BindOnce(&HttpProxySocket::OnReadWriteComplete,
|
base::BindOnce(&HttpProxySocket::OnReadWriteComplete,
|
||||||
@ -263,9 +276,6 @@ int HttpProxySocket::DoHeaderReadComplete(int result) {
|
|||||||
next_state_ = STATE_HEADER_READ;
|
next_state_ = STATE_HEADER_READ;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
if (header_end + 4 != buffer_.size()) {
|
|
||||||
return ERR_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// HttpProxyClientSocket uses CONNECT for all endpoints.
|
// HttpProxyClientSocket uses CONNECT for all endpoints.
|
||||||
auto first_line_end = buffer_.find("\r\n");
|
auto first_line_end = buffer_.find("\r\n");
|
||||||
@ -283,6 +293,8 @@ int HttpProxySocket::DoHeaderReadComplete(int result) {
|
|||||||
request_endpoint_ = HostPortPair::FromString(
|
request_endpoint_ = HostPortPair::FromString(
|
||||||
buffer_.substr(first_space + 1, second_space - (first_space + 1)));
|
buffer_.substr(first_space + 1, second_space - (first_space + 1)));
|
||||||
|
|
||||||
|
buffer_ = buffer_.substr(header_end + 4);
|
||||||
|
|
||||||
next_state_ = STATE_HEADER_WRITE;
|
next_state_ = STATE_HEADER_WRITE;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user