A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/kape142/HTTP-2-server/tree/v0.1.0 below:

GitHub - kape142/HTTP-2-server at v0.1.0

An implementation of the HTTP/2 protocol in .NET Core

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See usage for notes on how to use the library in your system.

To run a server based on this library you must have .NET Core Runtime 2.1-Preview2 installed, as this is, per today, the only version of .NET Core supporting SSL connection with ALPN negotiation.

As this library runs on a preview of the latest .NET Core, we do not have any continuous integartion.

Clone solution of of Github.

Name Description Server() Initializes a new instance of the Server class that finds a local IP and sets certificat to default = null. Server(String) Initializes a new instance of the Server class and sets the specific IP. Certificat is set to default = null. Server(X509Certificate2) Initializes a new instance of the Server class, finds a local IP and sets certificat to the specified X509Certificate2. Server(String,X509Certificate2) Initializes a new instance of the Server class, sets specified IP and sets certificat to the specified X509Certificate2. Name Description Port Returns the port the server is listening to. Name Description Listen(int) Starts listening to given port. Get(string, RestURI.HTTPMethod) Returns the data from given url. Post(string, RestURI.HTTPMethod) Posts data to given url.
using System;
using System.Security.Cryptography.X509Certificates;
using lib;

namespace Example
{
    class ExampleServer
    {
        static void Main(string[] args)
        {
            //Creating the certificate
            var serverCertificate = new X509Certificate2("Certificate/TcpTLSServer_TemporaryKey.pfx", "1234");
           
            //Creating the server
            Server server = new Server( serverCertificate); // serverCertificate);
             //test Get method
            server.Get("testurl", (req, res) => {
                res.Send("get from test url");
            });

            //test Post method
            server.Post("testurl", (req, res) => {
                res.Send($"post from test url, {req.BodyAsString()}");
            });

            //test sending JSON object
            server.Get("jsonobject", (req, res) =>
             {
                 res.Send("{ \"name\":\"Jone\", \"age\":39, \"car\":null }");
             });
            
            //Server starts listening to port, and responding to webpage.
            server.Listen(443);
        }
    }
}

Tests for this library are placed in its own project, UnitTesting.csproj. To run our tests you can open the solution in in Visual Studio 2017 and either;

TestHPack(), tests encoding and decoding of headers

Http2.Hpack.Decoder decoder = new Http2.Hpack.Decoder();
Http2.Hpack.Encoder encoder = new Http2.Hpack.Encoder();
...
Http2.Hpack.Encoder.Result encodeResult = encoder.EncodeInto(headerBlockFragment, headers);
Http2.Hpack.DecoderExtensions.DecodeFragmentResult decodeResult = decoder.DecodeHeaderBlockFragment(new ArraySegment<byte>(buffer, 0, buffer.Length), maxHeaderFieldsSize, headers);

TestAddSettingsPayload(), adds settings payload to a frame and then reads it out.

var settings = new(ushort, uint)[] { (SETTINGS_INITIAL_WINDOW_SIZE, 0x1000), (SETTINGS_ENABLE_PUSH, 0x0) };
...
SettingsPayload sp = frame.GetSettingsPayloadDecoded();
Assert.Equal(settings, sp.Settings);

TestAddRSTPayload(), adds reset paylaod to a frame and reads it out.

frame.AddRSTStreamPayload(error);
...
RSTStreamPayload rp = frame.GetRSTStreamPayloadDecoded();
Assert.Equal(error, rp.ErrorCode);

TestAddPushPromisePayload(), adds pushpromise paylaod to a frame and reads it out.

frame.AddPushPromisePayload(psi, hbf, endHeaders: true);
...
PushPromisePayload pp = frame.GetPushPromisePayloadDecoded();
Assert.Equal(psi, pp.PromisedStreamID);
Assert.Equal(hbf, pp.HeaderBlockFragment);
Assert.Equal(0, pp.PadLength);

TestAddDataPayload(), adds pushpromise paylaod to a frame and reads it out.

frame.AddDataPayload(ExtractBytes(data), paddingLength:16);
...
dp = frame.GetDataPayloadDecoded();
Assert.Equal(ExtractBytes(data), dp.Data);
Assert.Equal(0, dp.PadLength);

TestSplit32BitToBoolAnd31bitInt(), seperates the first bit from an integer.

uint _uint = 0b10000000000000000000000000000000;
int test = (int)(_uint | 0b01111000000000000000000000000000); // 1 and 2013265920
..
var t = Split32BitToBoolAnd31bitInt(test);
Assert.True(t.bit32);
Assert.True(2013265920 == t.int31);
...

TestExtractBytes(), converts a long, an int or a short into byte arrays.

...
short s = 12364;
b = ExtractBytes(s);
Array.Reverse(b);
Assert.Equal(BitConverter.ToInt16(b, 0),s);

TestConvertFromIncompleteByteArray(), converts byte array of 1-4 bytes into an int

int i = 1823423647;
var b = BitConverter.GetBytes(i);
Array.Reverse(b);
Assert.Equal(ConvertFromIncompleteByteArray(b), i);

TestConvertToBytes(), Converts integer to bytearray

int i = 19;
var b = BitConverter.GetBytes(i);
Array.Reverse(b);
Assert.Equal(b, ConvertToByteArray(i));

TestCombineHeaderPayloads(), combines the payloads from a header frame and potentally the following continuations frames to get the complete headerlist.

...
var continuation = new HTTP2Frame(28).AddContinuationFrame(continuationData, true);
var total = CombineHeaderPayloads(header, continuation);
...
Assert.Equal(CombineByteArrays(headerData, continuationData),total);

TestPriorityPayload(), adds priotiry payload to frame.

...
PriorityPayload pp = frame.GetPriorityPayloadDecoded();
Assert.Equal(sid, pp.StreamDependency);
Assert.True(pp.StreamDependencyIsExclusive);
Assert.Equal(28, pp.Weight);

TestHeaderPayload(), adds header payload to frame.

 byte[] data = { 1, 2, 3, 4 };
HTTP2Frame frame = new HTTP2Frame(1).AddHeaderPayload(data, 2, true, true);
HeaderPayload hh = frame.GetHeaderPayloadDecoded();

TestRestURI(), adds several HTTP-methods to different URLs and and then checks if they are there.

...
RestLibrary.AddURI("GET", "shoppinglists/", (req, res) => res.Send("List of shoppinglists"));
...
Assert.True(RestLibrary.HasMethod("GET", "shoppinglists"));
...
Establishing a connection over HTTP/2 Limitations and further development

We use SemVer for versioning. For the versions available, see the tags on this repository.

See also the list of contributors who participated in this project.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4