#include "net/http/http_stream_parser.h"
#include <algorithm>
#include <memory>
#include <string_view>
#include <utility>
#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/containers/span_writer.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/clamped_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "net/base/features.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
#include "net/base/upload_data_stream.h"
#include "net/http/http_chunked_decoder.h"
#include "net/http/http_connection_info.h"
#include "net/http/http_log_util.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.h"
#include "net/log/net_log_event_type.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/stream_socket.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_info.h"
#include "url/gurl.h"
#include "url/url_canon.h"
namespace net {
namespace {
const uint64_t kMaxMergedHeaderAndBodySize = …;
const size_t kRequestBodyBufferSize = …;
std::string GetResponseHeaderLines(const HttpResponseHeaders& headers) { … }
base::Value::Dict NetLogSendRequestBodyParams(uint64_t length,
bool is_chunked,
bool did_merge) { … }
void NetLogSendRequestBody(const NetLogWithSource& net_log,
uint64_t length,
bool is_chunked,
bool did_merge) { … }
bool ShouldTryReadingOnUploadError(int error_code) { … }
}
class HttpStreamParser::SeekableIOBuffer : public IOBufferWithSize { … };
const size_t HttpStreamParser::kChunkHeaderFooterSize = …;
HttpStreamParser::HttpStreamParser(StreamSocket* stream_socket,
bool connection_is_reused,
const GURL& url,
const std::string& method,
UploadDataStream* upload_data_stream,
GrowableIOBuffer* read_buffer,
const NetLogWithSource& net_log)
: … { … }
HttpStreamParser::~HttpStreamParser() = default;
int HttpStreamParser::SendRequest(
const std::string& request_line,
const HttpRequestHeaders& headers,
const NetworkTrafficAnnotationTag& traffic_annotation,
HttpResponseInfo* response,
CompletionOnceCallback callback) { … }
int HttpStreamParser::ConfirmHandshake(CompletionOnceCallback callback) { … }
int HttpStreamParser::ReadResponseHeaders(CompletionOnceCallback callback) { … }
int HttpStreamParser::ReadResponseBody(IOBuffer* buf,
int buf_len,
CompletionOnceCallback callback) { … }
void HttpStreamParser::OnIOComplete(int result) { … }
int HttpStreamParser::DoLoop(int result) { … }
int HttpStreamParser::DoSendHeaders() { … }
int HttpStreamParser::DoSendHeadersComplete(int result) { … }
int HttpStreamParser::DoSendBody() { … }
int HttpStreamParser::DoSendBodyComplete(int result) { … }
int HttpStreamParser::DoSendRequestReadBodyComplete(int result) { … }
int HttpStreamParser::DoSendRequestComplete(int result) { … }
int HttpStreamParser::DoReadHeaders() { … }
int HttpStreamParser::DoReadHeadersComplete(int result) { … }
int HttpStreamParser::DoReadBody() { … }
int HttpStreamParser::DoReadBodyComplete(int result) { … }
int HttpStreamParser::HandleReadHeaderResult(int result) { … }
void HttpStreamParser::RunConfirmHandshakeCallback(int rv) { … }
int HttpStreamParser::FindAndParseResponseHeaders(int new_bytes) { … }
int HttpStreamParser::ParseResponseHeaders(size_t end_offset) { … }
void HttpStreamParser::CalculateResponseBodySize() { … }
bool HttpStreamParser::IsResponseBodyComplete() const { … }
bool HttpStreamParser::CanFindEndOfResponse() const { … }
bool HttpStreamParser::IsMoreDataBuffered() const { … }
bool HttpStreamParser::CanReuseConnection() const { … }
void HttpStreamParser::OnConnectionClose() { … }
int HttpStreamParser::EncodeChunk(std::string_view payload,
base::span<uint8_t> output) { … }
bool HttpStreamParser::ShouldMergeRequestHeadersAndBody(
const std::string& request_headers,
const UploadDataStream* request_body) { … }
bool HttpStreamParser::SendRequestBuffersEmpty() { … }
}