chromium/net/http/http_stream_parser.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 =;  // 16KB

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) {}

// Returns true if |error_code| is an error for which we give the server a
// chance to send a body containing error information, if the error was received
// while trying to upload a request body.
bool ShouldTryReadingOnUploadError(int error_code) {}

}  // namespace

// Similar to DrainableIOBuffer(), but this version comes with its own
// storage. The motivation is to avoid repeated allocations of
// DrainableIOBuffer.
//
// Example:
//
// scoped_refptr<SeekableIOBuffer> buf =
//     base::MakeRefCounted<SeekableIOBuffer>(1024);
// // capacity() == 1024. size() == BytesRemaining() == BytesConsumed() == 0.
// // data() points to the beginning of the buffer.
//
// // Read() takes an IOBuffer.
// int bytes_read = some_reader->Read(buf, buf->capacity());
// buf->DidAppend(bytes_read);
// // size() == BytesRemaining() == bytes_read. data() is unaffected.
//
// while (buf->BytesRemaining() > 0) {
//   // Write() takes an IOBuffer. If it takes const char*, we could
///  // simply use the regular IOBuffer like buf->data() + offset.
//   int bytes_written = Write(buf, buf->BytesRemaining());
//   buf->DidConsume(bytes_written);
// }
// // BytesRemaining() == 0. BytesConsumed() == size().
// // data() points to the end of the consumed bytes (exclusive).
//
// // If you want to reuse the buffer, be sure to clear the buffer.
// buf->Clear();
// // size() == BytesRemaining() == BytesConsumed() == 0.
// // data() points to the beginning of the buffer.
//
class HttpStreamParser::SeekableIOBuffer : public IOBufferWithSize {};

// 2 CRLFs + max of 8 hex chars.
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) {}

// static
bool HttpStreamParser::ShouldMergeRequestHeadersAndBody(
    const std::string& request_headers,
    const UploadDataStream* request_body) {}

bool HttpStreamParser::SendRequestBuffersEmpty() {}

}  // namespace net