Skip to content

Commit

Permalink
Encoder uses the static table.
Browse files Browse the repository at this point in the history
  • Loading branch information
jstordeur committed Aug 8, 2020
1 parent 3b7462f commit 7035845
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 2 deletions.
44 changes: 43 additions & 1 deletion encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,27 @@ func (e *Encoder) WriteField(f HeaderField) error {
e.wrotePrefix = true
}

e.writeLiteralFieldWithoutNameReference(f)
idxAndVals, nameFound := encoderMap[f.Name]
if nameFound {
if idxAndVals.values == nil {
if len(f.Value) == 0 {
e.writeIndexedField(idxAndVals.idx)
} else {
e.writeLiteralFieldWithNameReference(&f, idxAndVals.idx)
}
} else {
val_idx, valueFound := idxAndVals.values[f.Value]
if valueFound {
e.writeIndexedField(val_idx)
} else {
e.writeLiteralFieldWithNameReference(&f, idxAndVals.idx)
}
}

} else {
e.writeLiteralFieldWithoutNameReference(f)
}

e.w.Write(e.buf)
e.buf = e.buf[:0]
return nil
Expand All @@ -50,3 +70,25 @@ func (e *Encoder) writeLiteralFieldWithoutNameReference(f HeaderField) {
e.buf = appendVarInt(e.buf, 7, uint64(len(f.Value)))
e.buf = append(e.buf, []byte(f.Value)...)
}

// Encodes a header field whose name is present in one of the
// tables.
func (e *Encoder) writeLiteralFieldWithNameReference(
f *HeaderField, idx uint8) {
offset := len(e.buf)
e.buf = appendVarInt(e.buf, 4, uint64(idx))
// Set the 01NTxxxx pattern, forcing N to 0 and T to 1
e.buf[offset] ^= 0x50

e.buf = appendVarInt(e.buf, 7, uint64(len(f.Value)))
e.buf = append(e.buf, []byte(f.Value)...)
}

// Encodes an indexed field, meaning it's entirely defined in one of the
// tables.
func (e *Encoder) writeIndexedField(idx uint8) {
offset := len(e.buf)
e.buf = appendVarInt(e.buf, 6, uint64(idx))
// Set the 1Txxxxxx pattern, forcing T to 1
e.buf[offset] ^= 0xc0
}
58 changes: 58 additions & 0 deletions encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ var _ = Describe("Encoder", func() {
return data[len(hf.Value):]
}

// Reads one indexed field line representation from data and verifies it
// matches expected_hf.
// Returns the leftover bytes from data.
checkIndexedHeaderField := func(data []byte, expected_hf HeaderField) []byte {
Expect(data[0] >> 7).To(Equal(uint8(1))) // 1Txxxxxx
index, data, err := readVarInt(6, data)
Expect(err).ToNot(HaveOccurred())
Expect(staticTableEntries[index]).To(Equal(expected_hf))
return data
}

checkHeaderFieldWithNameRef := func(data []byte, expected_hf HeaderField) []byte {
// read name reference
Expect(data[0] >> 6).To(Equal(uint8(1))) // 01NTxxxx
index, data, err := readVarInt(4, data)
Expect(err).ToNot(HaveOccurred())
Expect(staticTableEntries[index].Name).To(Equal(expected_hf.Name))
// read literal value
valueLen, data, err := readVarInt(7, data)
Expect(err).ToNot(HaveOccurred())
Expect(valueLen).To(BeEquivalentTo(len(expected_hf.Value)))
Expect(string(data[:len(expected_hf.Value)])).To(Equal(expected_hf.Value))
return data[len(expected_hf.Value):]
}

It("encodes a single field", func() {
hf := HeaderField{Name: "foobar", Value: "lorem ipsum"}
Expect(encoder.WriteField(hf)).To(Succeed())
Expand Down Expand Up @@ -68,6 +93,39 @@ var _ = Describe("Encoder", func() {
Expect(data).To(BeEmpty())
})

It("encodes all the fields of the static table", func() {
for _, hf := range staticTableEntries {
Expect(encoder.WriteField(hf)).To(Succeed())
}

data, requiredInsertCount, deltaBase := readPrefix(output.Bytes())
Expect(requiredInsertCount).To(BeZero())
Expect(deltaBase).To(BeZero())

for _, hf := range staticTableEntries {
data = checkIndexedHeaderField(data, hf)
}
Expect(data).To(BeEmpty())
})

It("encodes fields with name reference in the static table", func() {
hf1 := HeaderField{Name: ":status", Value: "666"}
hf2 := HeaderField{Name: "server", Value: "lorem ipsum"}
hf3 := HeaderField{Name: ":method", Value: ""}
Expect(encoder.WriteField(hf1)).To(Succeed())
Expect(encoder.WriteField(hf2)).To(Succeed())
Expect(encoder.WriteField(hf3)).To(Succeed())

data, requiredInsertCount, deltaBase := readPrefix(output.Bytes())
Expect(requiredInsertCount).To(BeZero())
Expect(deltaBase).To(BeZero())

data = checkHeaderFieldWithNameRef(data, hf1)
data = checkHeaderFieldWithNameRef(data, hf2)
data = checkHeaderFieldWithNameRef(data, hf3)
Expect(data).To(BeEmpty())
})

It("encodes multiple requests", func() {
hf1 := HeaderField{Name: "foobar", Value: "lorem ipsum"}
Expect(encoder.WriteField(hf1)).To(Succeed())
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ module github.com/marten-seemann/qpack
go 1.14

require (
github.com/client9/misspell v0.3.4 // indirect
github.com/kisielk/gotool v1.0.0 // indirect
github.com/mdempsky/maligned v0.0.0-20180708014732-6e39bd26a8c8 // indirect
github.com/mibk/dupl v1.0.0 // indirect
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.1
github.com/securego/gosec v0.0.0-20200401082031-e946c8c39989 // indirect
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381
)
49 changes: 49 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
Expand All @@ -17,24 +23,57 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mdempsky/maligned v0.0.0-20180708014732-6e39bd26a8c8 h1:zvpKif6gkrh82wAd2JIffdLyCL52N8r+ABwHxdIOvWM=
github.com/mdempsky/maligned v0.0.0-20180708014732-6e39bd26a8c8/go.mod h1:oGVD62YTpMEWw0JqJ2Vl48dzHywJBMlapkfsmhtokOU=
github.com/mibk/dupl v1.0.0 h1:aZc3jqrF9n0tUHwHt/+jsRxA8cRgA0Gdl56M7W7PoqE=
github.com/mibk/dupl v1.0.0/go.mod h1:pCr4pNxxIbFGvtyCOi0c7LVjmV6duhKWV+ex5vh38ME=
github.com/mozilla/tls-observatory v0.0.0-20200317151703-4fa42e1c2dee/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d h1:AREM5mwr4u1ORQBMvzfzBgpsctsbQikCVpvC+tX285E=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/securego/gosec v0.0.0-20200401082031-e946c8c39989 h1:rq2/kILQnPtq5oL4+IAjgVOjh5e2yj2aaCYi7squEvI=
github.com/securego/gosec v0.0.0-20200401082031-e946c8c39989/go.mod h1:i9l/TNj+yDFh9SZXUTvspXTjbFXgZGP/UvhU1S65A4A=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 h1:vY5WqiEon0ZSTGM3ayVVi+twaHKHDFUVloaQ/wug9/c=
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYvZ+fpjMXqs+XEriussHjSYqeXVnAdSV1tkMYk=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -49,7 +88,14 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200331202046-9d5940d49312 h1:2PHG+Ia3gK1K2kjxZnSylizb//eyaMG8gDFbOG7wLV8=
golang.org/x/tools v0.0.0-20200331202046-9d5940d49312/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand All @@ -61,10 +107,13 @@ google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyz
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
2 changes: 1 addition & 1 deletion integrationtests/interop/qifs
Submodule qifs updated 136 files
130 changes: 130 additions & 0 deletions static_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,133 @@ var staticTableEntries = [...]HeaderField{
{Name: "x-frame-options", Value: "deny"},
{Name: "x-frame-options", Value: "sameorigin"},
}

type indexAndValues struct {
idx uint8
values map[string]uint8
}

// A map of the header names from the static table to their index in the table.
// This is used by the encoder to quickly find if a header is in the static table
// and what value should be used to encode it.
// There's a second level of mapping for the headers that have some predefined
// values in the static table.
var encoderMap = map[string]indexAndValues{
":authority": indexAndValues{0, nil},
":path": indexAndValues{1, map[string]uint8{"/": 1}},
"age": indexAndValues{2, map[string]uint8{"0": 2}},
"content-disposition": indexAndValues{3, nil},
"content-length": indexAndValues{4, map[string]uint8{"0": 4}},
"cookie": indexAndValues{5, nil},
"date": indexAndValues{6, nil},
"etag": indexAndValues{7, nil},
"if-modified-since": indexAndValues{8, nil},
"if-none-match": indexAndValues{9, nil},
"last-modified": indexAndValues{10, nil},
"link": indexAndValues{11, nil},
"location": indexAndValues{12, nil},
"referer": indexAndValues{13, nil},
"set-cookie": indexAndValues{14, nil},
":method": indexAndValues{15, map[string]uint8{
"CONNECT": 15,
"DELETE": 16,
"GET": 17,
"HEAD": 18,
"OPTIONS": 19,
"POST": 20,
"PUT": 21}},
":scheme": indexAndValues{22, map[string]uint8{
"http": 22,
"https": 23}},
":status": indexAndValues{24, map[string]uint8{
"103": 24,
"200": 25,
"304": 26,
"404": 27,
"503": 28,
"100": 63,
"204": 64,
"206": 65,
"302": 66,
"400": 67,
"403": 68,
"421": 69,
"425": 70,
"500": 71}},
"accept": indexAndValues{29, map[string]uint8{
"*/*": 29,
"application/dns-message": 30}},
"accept-encoding": indexAndValues{31, map[string]uint8{"gzip, deflate, br": 31}},
"accept-ranges": indexAndValues{32, map[string]uint8{"bytes": 32}},
"access-control-allow-headers": indexAndValues{33, map[string]uint8{
"cache-control": 33,
"content-type": 34,
"*": 75}},
"access-control-allow-origin": indexAndValues{35, map[string]uint8{"*": 35}},
"cache-control": indexAndValues{36, map[string]uint8{
"max-age=0": 36,
"max-age=2592000": 37,
"max-age=604800": 38,
"no-cache": 39,
"no-store": 40,
"public, max-age=31536000": 41}},
"content-encoding": indexAndValues{42, map[string]uint8{
"br": 42,
"gzip": 43}},
"content-type": indexAndValues{44, map[string]uint8{
"application/dns-message": 44,
"application/javascript": 45,
"application/json": 46,
"application/x-www-form-urlencoded": 47,
"image/gif": 48,
"image/jpeg": 49,
"image/png": 50,
"text/css": 51,
"text/html; charset=utf-8": 52,
"text/plain": 53,
"text/plain;charset=utf-8": 54}},
"range": indexAndValues{55, map[string]uint8{"bytes=0-": 55}},
"strict-transport-security": indexAndValues{56, map[string]uint8{
"max-age=31536000": 56,
"max-age=31536000; includesubdomains": 57,
"max-age=31536000; includesubdomains; preload": 58}},
"vary": indexAndValues{59, map[string]uint8{
"accept-encoding": 59,
"origin": 60}},
"x-content-type-options": indexAndValues{61, map[string]uint8{"nosniff": 61}},
"x-xss-protection": indexAndValues{62, map[string]uint8{"1; mode=block": 62}},
// ":status" is duplicated and takes index 63 to 71
"accept-language": indexAndValues{72, nil},
"access-control-allow-credentials": indexAndValues{73, map[string]uint8{
"FALSE": 73,
"TRUE": 74}},
// "access-control-allow-headers" is duplicated and takes index 75
"access-control-allow-methods": indexAndValues{76, map[string]uint8{
"get": 76,
"get, post, options": 77,
"options": 78}},
"access-control-expose-headers": indexAndValues{79, map[string]uint8{
"content-length": 79,
"content-type": 80}},
"access-control-request-method": indexAndValues{81, map[string]uint8{
"get": 81,
"post": 82}},
"alt-svc": indexAndValues{83, map[string]uint8{"clear": 83}},
"authorization": indexAndValues{84, nil},
"content-security-policy": indexAndValues{85, map[string]uint8{
"script-src 'none'; object-src 'none'; base-uri 'none'": 85}},
"early-data": indexAndValues{86, map[string]uint8{"1": 86}},
"expect-ct": indexAndValues{87, nil},
"forwarded": indexAndValues{88, nil},
"if-range": indexAndValues{89, nil},
"origin": indexAndValues{90, nil},
"purpose": indexAndValues{91, map[string]uint8{"prefetch": 91}},
"server": indexAndValues{92, nil},
"timing-allow-origin": indexAndValues{93, map[string]uint8{"*": 93}},
"upgrade-insecure-requests": indexAndValues{94, map[string]uint8{"1": 94}},
"user-agent": indexAndValues{95, nil},
"x-forwarded-for": indexAndValues{96, nil},
"x-frame-options": indexAndValues{97, map[string]uint8{
"deny": 97,
"sameorigin": 98}},
}
Loading

0 comments on commit 7035845

Please sign in to comment.