HttpMachine.PCL 5.0.0

dotnet add package HttpMachine.PCL --version 5.0.0
                    
NuGet\Install-Package HttpMachine.PCL -Version 5.0.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="HttpMachine.PCL" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HttpMachine.PCL" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="HttpMachine.PCL" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HttpMachine.PCL --version 5.0.0
                    
#r "nuget: HttpMachine.PCL, 5.0.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.
#addin nuget:?package=HttpMachine.PCL&version=5.0.0
                    
Install HttpMachine.PCL as a Cake Addin
#tool nuget:?package=HttpMachine.PCL&version=5.0.0
                    
Install HttpMachine.PCL as a Cake Tool

HttpMachine for .NET Standard 2.0

NuGet Badge

.NET Standard

Please star this project if you find it useful. Thank you.

Background

This is a fork of the great work done by Benjamin van der Veen. The Original HttpMachine

HttpMachine.PCL is a combined C# HTTP request/reponse parser. It implements a state machine with Adrian Thurston's excellent state machine compiler, Ragel. Because Ragel supports C#, Java, Ruby, C++ and more.

HttpMachine is Copyright (c) 2011 Benjamin van der Veen. HttpMachine is licensed under the MIT License. See LICENSE.txt.

I've forked this project as Benjamin is no longer maintaining the work.

Breaking changes for version 4.0+

.NET Standard 2.0+ is now required minimun version.

Refactoring and simplification of use, have caused some namespaces to change. See example below for guidance for usage.

For instance, while still possible, it's no longer necessary to implement the interface IHttpCombinedParser, instead simply new up the HttpParserDelegate. Methods can be overrided if needed.

Breaking changes from version 3.0.1 to 3.1.0

From version 3.1.0 and forward the ParserHandler must implement IHttpCombinedParser instead of using HttpCombinedParser (see example code below).

Original features

  • HTTP/1.1 and 1.0
  • Supports pipelined requests
  • Tells your server if it should keep-alive
  • Extracts the length of the entity body
  • Support for parsing responses and request in one combined parser.

Additional features

Additions to this version compared with the original HttpMachine by Benjamin van der Veen

  • .NET Standard 1.0 support (after version 4.0 only .NET Standard 2.0 is supported).
  • Support for Chunked Transfer-Encoding
  • Can be used on Windows 8+, .NET 4.5+, Xamarin.Android, Xamarin.iOS and ASP.NET Core 1.0+
  • The Http Method now accepts these additional four characters: $ - , .
  • From library ver 1.1.1 the parser has been combined into one Request/Reponse parser. Filter on MessageType to see what type was passed.
  • Can now manage Zero Lenght Headers - for example EXT: as used in UPnP.
  • From version 4.0 and onwards header values are collected in an IEnumerable<string>;

Use like this:

class Program
    {
        static void Main(string[] args)
        {
            byte[] bArray;

            using (var handler = new HttpParserDelegate())
            using (var parser = new HttpCombinedParser(handler))
            {
                bArray = TestReponse();
                Console.WriteLine(parser.Execute(bArray) == bArray.Length
                    ? $"Reponse test succeed. Type identified is; {handler.HttpRequestResponse.MessageType} \r\n" +
                        $"Headers: \r\n" +
                        $"{string.Join("\r\n", handler.HttpRequestResponse.Headers.Select(h => $"{h.Key}: {string.Join(", ", h.Value)} "))}"
                    : $"Response test failed");

                handler.HttpRequestResponse.Body.Position = 0;
                var reader = new StreamReader(handler.HttpRequestResponse.Body);
                var body = reader.ReadToEnd();
            }

            Console.WriteLine("\r\n\r\n");

            using (var handler = new HttpParserDelegate())
            using (var parser = new HttpCombinedParser(handler))
            {
                bArray = TestChunkedResponse();
                Console.WriteLine(parser.Execute(bArray) == bArray.Length
                    ? $"Chunked Response test succeed. Type identified is; {handler.HttpRequestResponse.MessageType}." +
                    $"Headers: \r\n" +
                    $"{string.Join("\r\n", handler.HttpRequestResponse.Headers.Select(h => $"{h.Key}: {string.Join(",", h.Value)} "))}"
                    : $"Chunked Response test failed");

                handler.HttpRequestResponse.Body.Position = 0;
                var reader = new StreamReader(handler.HttpRequestResponse.Body);
                var body = reader.ReadToEnd();
            }
        }
        
        // Test Response
        private static string TestReponse()
        {
            var stringBuilder = new StringBuilder();
            stringBuilder.Append("HTTP/1.1 200 OK\r\n");
            stringBuilder.Append("CACHE-CONTROL: max-age = 10\r\n");
            stringBuilder.Append("ST: upnp:rootdevice\r\n");
            stringBuilder.Append("ST: upnp:rootdevice\r\n");
            stringBuilder.Append("USN: uuid:73796E6F-6473-6D00-0000-0011322fe5f0::upnp:rootdevice\r\n");
            stringBuilder.Append("EXT:\r\n");
            stringBuilder.Append("SERVER: Synology/DSM/200.200.200.200\r\n");
            stringBuilder.Append("LOCATION: http://200.200.200.101:5000/ssdp/desc-DSM-eth1.xml\r\n");
            stringBuilder.Append("OPT: \"http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n");
            stringBuilder.Append("01-NLS: 1\r\n");
            stringBuilder.Append("BOOTID.UPNP.ORG: 1\r\n");
            stringBuilder.Append("CONFIGID.UPNP.ORG: 1337\r\n");
            stringBuilder.Append("\r\n");
            return stringBuilder.ToString();
        }
        
        // Test request
        private static string TestRequest()
        {
            var stringBuilder = new StringBuilder();
            stringBuilder.Append("NOTIFY * HTTP/1.1\r\n");
            stringBuilder.Append("HOST: 239.255.255.250:1900\r\n");
            stringBuilder.Append("CACHE-CONTROL: max-age = 10\r\n");
            stringBuilder.Append("LOCATION: http://www.bing.com\r\n");
            stringBuilder.Append("NT: \"upnp:rootdevice\"\r\n");
            stringBuilder.Append("NTS: ssdp:alive\r\n");
            stringBuilder.Append("EXT:\r\n");
            stringBuilder.Append("SERVER: Synology/DSM/200.200.200.100 UPnP/2.0 Test/1.0\r\n");
            stringBuilder.Append("BOOTID.UPNP.ORG: 1\r\n");
            stringBuilder.Append("CONFIGID.UPNP.ORG: 121212\r\n");
            stringBuilder.Append("\r\n");
            return stringBuilder.ToString();
        }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.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 is compatible. 
.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.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on HttpMachine.PCL:

Package Downloads
WebsocketClientLite.PCL

A simple and light WebSocket client. Can be set to ignore SSL/TLS server certificate issues (use with care!). Easily and effectively observe incoming message using Reactive Extensions (Rx)

SimpleHttpListener

Simple Http Listener This is the legacy version of Simple HTTP Listener. Please see project web site for a new version.

SimpleHttpListener.Rx

The newer and greatly improved replacement of Simple HTTP Listener PCL.

WebsocketClientLite.Rx2

Uses Rx v2.5.5

SwebSocket

An easy to use WebSocket library.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.0 177 3/27/2025
4.0.3 38,920 4/20/2022
4.0.2 5,275 3/31/2022
3.1.0 299,248 2/11/2018

Updated to .NET Standard v2.0, 2.1,.Net 6,.Net 8,.Net 9