Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
Merge branch 'origin/DevBranch'
Browse files Browse the repository at this point in the history
  • Loading branch information
vsemogutor committed Jun 2, 2014
2 parents 83e84e4 + e0be978 commit e1a6ced
Show file tree
Hide file tree
Showing 74 changed files with 2,350 additions and 1,458 deletions.
Binary file modified res/server.pfx
Binary file not shown.
2 changes: 1 addition & 1 deletion samples/Http2.Owin.Service.Sample/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="useSecurePort" value="false" />
<add key="useSecurePort" value="true" />
<add key="secureAddress" value="https://localhost:8443/" />
<add key="unsecureAddress" value="http://localhost:8080/" />
<add key="handshakeOptions" value="handshake" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
<Compile Include="Startup.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
Expand Down
2 changes: 1 addition & 1 deletion samples/Http2.Owin.StaticFiles.Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void Configuration(IAppBuilder builder)
{
builder.UseHttp2();
builder.UsePush();
builder.UseStaticFiles("/root");
builder.UseStaticFiles("/root");
}
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,24 @@ namespace Microsoft.Http2.Protocol.Compression.HeadersDeltaCompression
{
public enum IndexationType : byte
{
Incremental = 0x00, //05: Literal with incremental indexing | 0 | 0 | Index (6+) |
WithoutIndexation = 0x40, //05: Literal without indexation | 0 | 1 | Index (6+) |
Indexed = 0x80 //05: Indexed | 1 | Index (7+) |
// See spec 07 -> 4.3.2. Literal Header Field without Indexing
// The literal header field without indexing representation starts with
// the '0000' 4-bit pattern.
WithoutIndexation = 0x00, //07: Literal without indexation | 0 | 0 | 0 | 0 | Index (4+) |

// See spec 07 -> 4.3.3. Literal Header Field never Indexed
// The literal header field never indexed representation starts with the
// '0001' 4-bit pattern.
NeverIndexed = 0x10, //07: Literal Never Indexed | 0 | 0 | 0 | 1 | Index (4+) |

// See spec 07 -> 4.4. Encoding Context Update
// An encoding context update starts with the '001' 3-bit pattern.
EncodingContextUpdate = 0x20, //07:Encoding Context Update | 0 | 0 | 1 | Index (4+) |

// See spec 07 -> 4.3.1. Literal Header Field with Incremental Indexing
// This representation starts with the '01' 2-bit pattern.
Incremental = 0x40, //07: Literal with incremental indexing | 0 | 1 | Index (6+) |

Indexed = 0x80 //07: Indexed | 1 | Index (7+) |
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright © Microsoft Open Technologies, Inc.
// All Rights Reserved
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.

// See the Apache 2 License for the specific language governing permissions and limitations under the License.
namespace Microsoft.Http2.Protocol.Compression.HeadersDeltaCompression
{
public enum UVarIntPrefix : byte
{
WithoutIndexing = 4,
NeverIndexed = 4,
EncodingContextUpdate = 4,
Incremental = 6,
Indexed = 7
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@
using System.Linq;
using System.Collections.Generic;
using System.IO;
using Microsoft.Http2.Protocol.Exceptions;

namespace Microsoft.Http2.Protocol.Compression.Huffman
{
internal class BitTree
{
private Node _root;
private HuffmanCodesTable _table;
private bool _isRequest;
private readonly bool[] _eos;

public BitTree(HuffmanCodesTable table, bool isRequest)
public BitTree(HuffmanCodesTable table)
{
_table = table;
_isRequest = isRequest;
_eos = _isRequest ? HuffmanCodesTable.ReqEos : HuffmanCodesTable.RespEos;
_eos = HuffmanCodesTable.Eos;
_root = new Node(false, null);
BuildTree(table);
}
Expand All @@ -36,7 +35,7 @@ private void BuildTree(HuffmanCodesTable table)
Add(bits);
}

Add(_isRequest ? HuffmanCodesTable.ReqEos : HuffmanCodesTable.RespEos);
Add(HuffmanCodesTable.Eos);
}

private void Add(bool[] bits)
Expand Down Expand Up @@ -96,18 +95,26 @@ public byte[] GetBytes(bool[] bits)

if (isEos && ++j == _eos.Length)
{
result = new byte[stream.Position];
Buffer.BlockCopy(stream.GetBuffer(), 0, result, 0, result.Length);
return result;
// see spec 07 - > 4.1.2. String Literal Representation
// A Huffman encoded string literal containing the EOS entry
// MUST be treated as a decoding error.
throw new CompressionError("EOS contains");
}

i++;
}

//all bits are ones then eos is reached
if (symbolBits.Count < 8 && symbolBits.All(bit => bit))
if (IsValidPadding(symbolBits))
break;

// See spec 07 -> 4.1.2. String Literal Representation
// A padding strictly longer than 7 bits MUST be treated as a decoding error.
// A padding not corresponding to the most significant bits of the EOS
// entry MUST be treated as a decoding error.

// If padding is not valid or padding is longer than 7 bits
// then decoding error will thrown by GetByte method
// since not turn recognize the symbol.
var symbol = _table.GetByte(symbolBits);
stream.WriteByte(symbol);
}
Expand All @@ -118,6 +125,30 @@ public byte[] GetBytes(bool[] bits)
}
}

// See spec 07 -> 4.1.2. String Literal Representation
// As the Huffman encoded data doesn't always end at an octet boundary,
// some padding is inserted after it up to the next octet boundary. To
// prevent this padding to be misinterpreted as part of the string
// literal, the most significant bits of the EOS (end-of-string) entry
// in the Huffman table are used.
private bool IsValidPadding(List<bool> symbolBits)
{
if (symbolBits.Count >= 8)
{
return false;
}

for (int i = 0; i < symbolBits.Count; i++)
{
if (symbolBits[i] != HuffmanCodesTable.Eos[i])
{
return false;
}
}

return true;
}

private class Node
{
public bool Value { get; private set; }
Expand Down
Loading

0 comments on commit e1a6ced

Please sign in to comment.