blob: d02e27610b43e625add5741617bfbab933450fd5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright 2014 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.
#include "net/spdy/hpack_encoder.h"
#include <map>
#include <string>
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace {
using std::string;
// Test that EncoderHeaderSet() simply encodes everything as literals
// without indexing.
TEST(HpackEncoderTest, Basic) {
HpackEncoder encoder(kuint32max);
std::map<string, string> header_set1;
header_set1["name1"] = "value1";
header_set1["name2"] = "value2";
string encoded_header_set1;
EXPECT_TRUE(encoder.EncodeHeaderSet(header_set1, &encoded_header_set1));
EXPECT_EQ("\x40\x05name1\x06value1"
"\x40\x05name2\x06value2", encoded_header_set1);
std::map<string, string> header_set2;
header_set2["name2"] = "different-value";
header_set2["name3"] = "value3";
string encoded_header_set2;
EXPECT_TRUE(encoder.EncodeHeaderSet(header_set2, &encoded_header_set2));
EXPECT_EQ("\x40\x05name2\x0f" "different-value"
"\x40\x05name3\x06value3", encoded_header_set2);
}
// Test that trying to encode a header set with a too-long header
// field will fail.
TEST(HpackEncoderTest, HeaderTooLarge) {
HpackEncoder encoder(10);
std::map<string, string> header_set;
header_set["name1"] = "too-long value";
header_set["name2"] = "value2";
// TODO(akalin): Verify that the encoder did not attempt to encode
// the second header field.
string encoded_header_set;
EXPECT_FALSE(encoder.EncodeHeaderSet(header_set, &encoded_header_set));
}
} // namespace
} // namespace net
|