blob: af2ea4d368411d3a1f4c95e3519bf338073e144c [file] [log] [blame]
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_QUIC_CORE_SPDY_UTILS_H_
#define NET_QUIC_CORE_SPDY_UTILS_H_
#include <cstddef>
#include <cstdint>
#include "base/macros.h"
#include "net/quic/core/quic_header_list.h"
#include "net/quic/core/quic_packets.h"
#include "net/quic/platform/api/quic_export.h"
#include "net/quic/platform/api/quic_string.h"
#include "net/spdy/core/spdy_framer.h"
namespace net {
class QUIC_EXPORT_PRIVATE SpdyUtils {
public:
// Populate |content length| with the value of the content-length header.
// Returns true on success, false if parsing fails or content-length header is
// missing.
static bool ExtractContentLengthFromHeaders(int64_t* content_length,
SpdyHeaderBlock* headers);
// Copies a list of headers to a SpdyHeaderBlock.
static bool CopyAndValidateHeaders(const QuicHeaderList& header_list,
int64_t* content_length,
SpdyHeaderBlock* headers);
// Copies a list of headers to a SpdyHeaderBlock.
static bool CopyAndValidateTrailers(const QuicHeaderList& header_list,
size_t* final_byte_offset,
SpdyHeaderBlock* trailers);
// Returns a canonicalized URL composed from the :scheme, :authority, and
// :path headers of a PUSH_PROMISE. Returns empty string if the headers do not
// conform to HTTP/2 spec or if the ":method" header contains a forbidden
// method for PUSH_PROMISE.
static QuicString GetPromisedUrlFromHeaders(const SpdyHeaderBlock& headers);
// Returns hostname, or empty std::string if missing.
static QuicString GetPromisedHostNameFromHeaders(
const SpdyHeaderBlock& headers);
// Returns true if result of |GetPromisedUrlFromHeaders()| is non-empty
// and is a well-formed URL.
static bool PromisedUrlIsValid(const SpdyHeaderBlock& headers);
// Populates the fields of |headers| to make a GET request of |url|,
// which must be fully-qualified.
static bool PopulateHeaderBlockFromUrl(const QuicString url,
SpdyHeaderBlock* headers);
private:
DISALLOW_COPY_AND_ASSIGN(SpdyUtils);
};
} // namespace net
#endif // NET_QUIC_CORE_SPDY_UTILS_H_