hpack 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package hpack --version 1.1.0                
NuGet\Install-Package hpack -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="hpack" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add hpack --version 1.1.0                
#r "nuget: hpack, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install hpack as a Cake Addin
#addin nuget:?package=hpack&version=1.1.0

// Install hpack as a Cake Tool
#tool nuget:?package=hpack&version=1.1.0                

hpack

Header Compression for HTTP/2 written in C#

An Example on how to use the hpack.Encoder and hpack.Decoder

First, you have to create a HeaderListener that implements IHeaderListener

using System;
using System.Text;

namespace HTTP2
{
  public class EmitHeaderEventArgs : EventArgs
  {
    private string _name;
    private string _value;
    
    public string Name { get { return this._name; } }
    
    public string Value { get { return this._value; } }
    
    public EmitHeaderEventArgs(byte[] name, byte[] value)
    {
      this._name = Encoding.UTF8.GetString(name);
      this._value = Encoding.UTF8.GetString(value);
    }
    
    public EmitHeaderEventArgs(string name, string value)
    {
      this._name = name;
      this._value = value;
    }
  }
  
  public class HeaderListener : hpack.IHeaderListener
  {
    public delegate void EmitHeaderEventHandler(object sender, EmitHeaderEventArgs e);
    
    public event EmitHeaderEventHandler HeaderEmitted;
    
    public HeaderListener()
    {
      
    }
    
    protected virtual void OnHeaderEmitted(EmitHeaderEventArgs e)
    {
      if (this.HeaderEmitted != null) {
        this.HeaderEmitted(this, e);
      }
    }
    
    public void AddHeader(byte[] name, byte[] value, bool sensitive)
    {
      this.OnHeaderEmitted(new EmitHeaderEventArgs(name, value));
    }
  }
}

Then you can instantiate this HeaderListener and add an EventListener

using System;

namespace HTTP2
{
  class MainClass
  {
    public static void Main(string[] args)
    {
      var headerListener = new HeaderListener();
      headerListener.HeaderEmitted += (object sender, EmitHeaderEventArgs e) {
        Console.WriteLine("header emitted => name: " + e.Name + "; value: " + e.Value);
      };
    }
  }
}

Now you can encode and decode headers

...
hpack.Encoder hpackEncoder = new hpack.Encoder(4096);
hpack.Decoder hpackDecoder = new hpack.Decoder(8192, 4096);

using(var binWriter = new BinaryWriter(new MemoryStream())) {
  hpackEncoder.EncodeHeader(binWriter, ":authority", "localhost:8080");
  hpackEncoder.EncodeHeader(binWriter, ":method", "GET");
  hpackEncoder.EncodeHeader(binWriter, ":path", "/");
  hpackEncoder.EncodeHeader(binWriter, ":scheme", "http");
  
  // send the data (binWriter) to the server!
  
  // wait for receiving headers...
  // for this example the encoded data in binWriter.
  var headerBlockFragment = new byte[binWriter.BaseStream.Length];
  binWriter.BaseStream.Position = 0;
  binWriter.BaseStream.Read(headerBlockFragment, 0, binWriter.BaseStream.Length);
  using(var binReader = new BinaryReader(new MemoryStream(headerBlockFragment))) {
    hpackDecoder.Decode(binReader, headerListener);
    hpackDecoder.EndHeaderBlock(); // this must be called to finalize the decoding process.
    
    // now the decoded headers should be printed from the defined "headerListener.HeaderEmitted" above.
  }
}
...
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on hpack:

Package Downloads
HttpTwo.Net

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0 315 11/28/2023
1.3.0 231 8/14/2023
1.2.0 660 6/3/2022
1.1.0 3,240 10/12/2018
1.0.2.29220 43,323 4/24/2016
0.2.5701.39423 1,983 8/11/2015
0.1.5701.14029 1,533 8/11/2015

changed architecture target to .NETStandard 2.0