chromium/net/third_party/quiche/src/quiche/http2/http2_constants.h

// Copyright 2016 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 QUICHE_HTTP2_HTTP2_CONSTANTS_H_
#define QUICHE_HTTP2_HTTP2_CONSTANTS_H_

// Constants from the HTTP/2 spec, RFC 7540, and associated helper functions.

#include <cstdint>
#include <iosfwd>
#include <ostream>
#include <string>

#include "absl/container/flat_hash_set.h"
#include "absl/strings/string_view.h"
#include "quiche/common/platform/api/quiche_export.h"
#include "quiche/common/quiche_text_utils.h"

namespace http2 {

// TODO(jamessynge): create http2_simple_types for types similar to
// SpdyStreamId, but not for structures like Http2FrameHeader. Then will be
// able to move these stream id functions there.
constexpr uint32_t UInt31Mask() {}
constexpr uint32_t StreamIdMask() {}

// The value used to identify types of frames. Upper case to match the RFC.
// The comments indicate which flags are valid for that frame type.
enum class Http2FrameType : uint8_t {};

// Is the frame type known/supported?
inline bool IsSupportedHttp2FrameType(uint32_t v) {}
inline bool IsSupportedHttp2FrameType(Http2FrameType v) {}

// The return type is 'std::string' so that they can generate a unique string
// for each unsupported value. Since these are just used for debugging/error
// messages, that isn't a cost to we need to worry about. The same applies to
// the functions later in this file.
QUICHE_EXPORT std::string Http2FrameTypeToString(Http2FrameType v);
QUICHE_EXPORT std::string Http2FrameTypeToString(uint8_t v);
QUICHE_EXPORT inline std::ostream& operator<<(std::ostream& out,
                                              Http2FrameType v) {}

// Flags that appear in supported frame types. These are treated as bit masks.
// The comments indicate for which frame types the flag is valid.
enum Http2FrameFlag : uint8_t {};

// Formats zero or more flags for the specified type of frame. Returns an
// empty string if flags==0.
QUICHE_EXPORT std::string Http2FrameFlagsToString(Http2FrameType type,
                                                  uint8_t flags);
QUICHE_EXPORT std::string Http2FrameFlagsToString(uint8_t type, uint8_t flags);

// Error codes for GOAWAY and RST_STREAM frames.
enum class Http2ErrorCode : uint32_t {};

// Is the error code supported? (So far that means it is in RFC 7540.)
inline bool IsSupportedHttp2ErrorCode(uint32_t v) {}
inline bool IsSupportedHttp2ErrorCode(Http2ErrorCode v) {}

// Format the specified error code.
QUICHE_EXPORT std::string Http2ErrorCodeToString(uint32_t v);
QUICHE_EXPORT std::string Http2ErrorCodeToString(Http2ErrorCode v);
QUICHE_EXPORT inline std::ostream& operator<<(std::ostream& out,
                                              Http2ErrorCode v) {}

// Supported parameters in SETTINGS frames; so far just those in RFC 7540.
enum class Http2SettingsParameter : uint16_t {};

// Is the settings parameter supported (so far that means it is in RFC 7540)?
inline bool IsSupportedHttp2SettingsParameter(uint32_t v) {}
inline bool IsSupportedHttp2SettingsParameter(Http2SettingsParameter v) {}

// Format the specified settings parameter.
QUICHE_EXPORT std::string Http2SettingsParameterToString(uint32_t v);
QUICHE_EXPORT std::string Http2SettingsParameterToString(
    Http2SettingsParameter v);
inline std::ostream& operator<<(std::ostream& out, Http2SettingsParameter v) {}

// Information about the initial, minimum and maximum value of settings (not
// applicable to all settings parameters).
class QUICHE_EXPORT Http2SettingsInfo {};

// Http3 early fails upper case request headers, but Http2 still needs case
// insensitive comparison.
InvalidHeaderSet;

// Returns all disallowed HTTP/2 headers.
QUICHE_EXPORT const InvalidHeaderSet& GetInvalidHttp2HeaderSet();

}  // namespace http2

#endif  // QUICHE_HTTP2_HTTP2_CONSTANTS_H_