Giter Site home page Giter Site logo

jgauffin / griffin.networking Goto Github PK

View Code? Open in Web Editor NEW
108.0 108.0 35.0 19.68 MB

Networking library for .NET

Home Page: http://blog.gauffin.org/2012/05/griffin-networking-a-somewhat-performant-networking-library-for-net/

License: GNU Lesser General Public License v3.0

C# 83.68% ASP 1.68% CSS 5.31% JavaScript 9.33%

griffin.networking's People

Contributors

hultqvist avatar jgauffin avatar revolutionsmythe avatar vktr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

griffin.networking's Issues

Run the Project in Visual Studio 2012

I downloaded the project. Anytime I want to load the project in Visual Studio 2012 all the sub projects in the protocols folder load properly except the FREESWITCH sub project. However the reason I am showing interest to the project is the FREESWITCH sub project. Please I would like someone to assist me fix this. I think I am missing something.

Thank you.

HttpRequest / ProduceGoodUri issue

Though commit b7bbc67 fixes the exception, the problem mentioned in issue #23 remains.

Example:

  1. Request is http://127.0.0.1/a/b/test.html
  2. Now we're in the HttpRequest constructor:
  • Uri = ProduceGoodUri("/a/b/test.html") = ["http://a/b/test.html"]
  • _pathAndQuery = Uri.PathAndQuery = ["/b/test.html"]

So http://127.0.0.1/b/test.html gets served (note the missing "/a" part).

ServerClientContext.Close() needs lock

When I call Close() on clients which is already (or about to be) closed, sometimes, NullPointerException is raised due to race condition. Close() needs to be thread safe.

Feature Request: Support OWIN

Hello!

Do you have any plans to support OWIN? It would be really great to have a self hosted server that runs on Windows XP without needing administrative rights. Currently I only found solutions that require .NET 4.5 (which is not available on XP) or rely on HttpListener.

Markus

Griffin.Networking.Protocol.Http: HttpRequest ProduceGoodUri not working

Using the DemoServer from the Griffin.Webserver project:

Requesting
http://127.0.0.1/ gives an exception
http://127.0.0.1/a/test.html returns http://127.0.0.1/test.html
http://127.0.0.1/a/b/test.html returns http://127.0.0.1/b/test.html

This was introduced in commit 553cc41. Reverting to _pathAndQuery = url; fixes the issue.

IMessageBuilder reused without initialization.

MessageClientContext is preallocated by server and reused when client connects.
IMessageBuilder is reused by MessageClientContext eventually.

If IMessageBuilder has any state machine in it (like in my server...) It fails to work once it is reused.
I can find no easy workaround for this problem.

I would expect IMessageFormatterFactory.CreateBuilder() is called every time client is connected.

DigestAuthenticator should implement IDisposable

The DigestAuthenticator class in the HTTP project should implement IDisposable in order to dispose the NonceService (the inside Timer). As long the Timer is running a strong reference will keep the instance alive. In this way, new DigestAuthenticator instances will leak memory.
I'd also consider to expose the IDisposable interface to the HttpService, for the dispose chain.
Because the not-so-comfortable disposal of instances, another solution might be to have a centralized clock source (i.e. singleton), then turn any NonceService as a weak-observer of this source.

The example as in may lead to memory leaks:
https://github.com/jgauffin/griffin.networking/blob/master/Source/Protocols/Http/Griffin.Networking.Protocol.Http.DemoServer/Basic/MyHttpService.cs

HTTP-Authentication not working

HTTP authentication does not work (neither Basic nor Digest). The reason seems to be that a WWW-Authorize header is sent, but the correct header would be WWW-Authenticate. The status code is also incorrectly not set to 401 Unauthorized when presenting the challenge.

Error in BodyDecoder.cs. POST method not working

In class Griffin.Networking.Protocol.Http.Pipeline.Handlers.BodyDecoder, method private bool ParseBody(IBufferReader reader) (line 133)

remove line:

reader.Position += bytesLeft;

reader already moves position on copy (line above mentioned line).

No RemoteEndPoint in HTTP request.

Please fix that.

Class: Griffin.Networking.Protocol.Http.Pipeline.Handlers.HeaderDecoder
Method: void HandleUpstream(IPipelineHandlerContext, IPipelineMessage)

After line:
var recivedHttpMsg = new ReceivedHttpRequest((IRequest)_message);

Add:
((HttpRequest)recivedHttpMsg.HttpRequest).RemoteEndPoint = msg.RemoteEndPoint as System.Net.IPEndPoint;

This solves issue.

WebServer crashed because HTTP 1.0

My code as below

                // Module manager handles all modules in the server
                var moduleManager = new ModuleManager();

                moduleManager.Add(new BodyDecodingModule(new UrlFormattedDecoder()));
                MyModule myM = new MyModule();
                moduleManager.Add(myM);
                // And start the server.
                HttpServer _server = new HttpServer(moduleManager);                    
                _server.Start(IPAddress.Any, 8088);



  public class MyModule : IWorkerModule
 {
    public ModuleResult HandleRequest(IHttpContext context)
    {
        IRequest msg = context.Request;
        if (msg.Method == "GET")
        {
            byte[] byContent = Encoding.UTF8.GetBytes(dictParams["echostr"]);
            context.Response.Body = new MemoryStream();
            context.Response.ContentType = "text/html; charset=UTF-8";
            context.Response.Body.Write(byContent, 0, byContent.Length);
            context.Response.Body.Position = 0;
        }
        else if (msg.Method == "POST")
        {
            if (msg.ContentLength > 0 && msg.Body != null)
            {
                var buff = new byte[msg.ContentLength];
                msg.Body.Read(buff, 0, msg.ContentLength);
                Encoding codeM = Encoding.GetEncoding("utf-8");
                string strContent = codeM.GetString(buff);
                OutputMessage(string.Format("Content:{0}", strContent));
            }
        }           
        return ModuleResult.Continue;
    }

}


My application was crashed after received one http request. Logger as below

Method:GET/ContentEncoding:/ContentLength:0
ProtocolVersion:HTTP/1.0/KeepAlive:True/ContentType:
Uri AbsoluteUri:http://58.215.164.183/?signature=1dfea26808d632903549c69d78558fce1c418405&echostr=5867553698596935317&timestamp=1365661332&nonce=1366146317/AbsolutePath://Host:58.215.164.183/Port:80
QueryString/Name:signature/Value:1dfea26808d632903549c69d78558fce1c418405
QueryString/Name:echostr/Value:5867553698596935317
QueryString/Name:timestamp/Value:1365661332
QueryString/Name:nonce/Value:1366146317
Headers/Name:User-Agent/Value:Mozilla/4.0
Headers/Name:Accept/Value:/
Headers/Name:Host/Value:58.215.164.183
Headers/Name:Pragma/Value:no-cache
Headers/Name:Connection/Value:Keep-Alive

Message Framing Fails When Sending Data Quickly

When receiving a lot of messages from a client application in quick succession: The server will throw one of the following exceptions:

Invalid Data Version (your validation)
Message Length Negative (your validation)
Some Serialization Issue (due to invalid stream of bytes) (BinaryFormatter)

The problem is that when sending a lot of messages very quickly the message framing messes up. The bytes are received in the wrong order.

The exception thrown depends on "luck" really if what the client perceives to be the length prefix is converted to a positive integer, the message length negative exception will not be thrown; else, it is.

How to make a https request with pure griffin networking?

@jgauffin: I noticed that no matter what I do, a .NET webrequest to a Griffin.Webserver HTTPS port will time out. WebClient, HttpWebRequest, etc all behave the same. All the solutions I found out there are not helping here. It is important to mention that Browsers like Firefox are able to connect to the same port normally.

So I'd like to use pure griffin.networking to open an SSL connection to the HTTPS port hoping that this will not time out but I've not been able to figure out how. Can you quickly throw together a code sample?

Thank you very much!

Boundary errors

  • In HttpRequest.ParseContentType you delete boundary and this causes errors durring files upload.
  • Typo in MultipartDecoder.Decode : var boundry = contentType.GetParameter("boundry");

Freeswitch

Hi, I've seen a Freeswitch protocol implementation in your source code. Are you planning to make it available and working ?
Thank you.

HttpService.OnRequest receives an IRequest with a null RemoteEndPoint

For instance, take your example from the README and change it like so:

internal class Program
{
    public static void RunDemo()
    {
        var server = new MessagingServer(new MyHttpServiceFactory(),
                                            new MessagingServerConfiguration(new HttpMessageFactory()));
        server.Start(new IPEndPoint(IPAddress.Loopback, 8888));
    }
}

// factory
public class MyHttpServiceFactory : IServiceFactory
{
    public IServerService CreateClient(EndPoint remoteEndPoint)
    {
        return new MyHttpService();
    }
}

// and the handler
public class MyHttpService : HttpService
{
    private static readonly BufferSliceStack Stack = new BufferSliceStack(50, 32000);

    public MyHttpService()
        : base(Stack)
    {
    }

    public override void Dispose()
    {
    }

    public override void OnRequest(IRequest request)
    {
        var response = request.CreateResponse(HttpStatusCode.OK, "Welcome");

        response.Body = new MemoryStream();
        response.ContentType = "text/plain";
        var buffer = Encoding.UTF8.GetBytes(request.RemoteEndPoint.Address.ToString());
        response.Body.Write(buffer, 0, buffer.Length);
        response.Body.Position = 0;

        Send(response);
    }
}

Pipeline and streams

There is a problem with streams and pipelines.

They seam to work on small amount of data, but when you try to use images or something larger output get's mess up. (html is mixed with images and css/js). As it turns out it's related to using same connection by browsers and reading output at the same time.

Also when you switch to keep alive false in response you get more errors (Close message not supported, easy fix), after that i got null reference (socket was null ServerClientContext.cs:218), those two fixes solves my problem partially... now the response is cutoff and I get half of an image, part of js and css. If I find a fix I will post it here. I will also try to solve connection sharing problem.

Byte ranges not supported

Please add support for byte ranges (see this document), which will provide better support for HTML5 audio/video.

I've tried to do it myself like this:

        var stream = File.OpenRead(Path.Combine(BaseDirectory, path));
        response.AddHeader("Accept-Ranges", "bytes");
        response.ContentType = HttpServer.GetContentTypeForExtension(Path.GetExtension(path).Substring(1));
        // Handle ranges
        if (request.Headers.Any(h => h.Name == "Range"))
        {
            response.StatusCode = 206;
            response.StatusDescription = "Partial Content";
            var range = request.Headers["Range"].Value;
            var type = range.Remove(range.IndexOf("="));
            if (type != "bytes")
            {
                response.StatusCode = 400;
                response.StatusDescription = "Bad Request";
                return;
            }
            range = range.Substring(range.IndexOf("=") + 1);
            var rangeParts = range.Split('-');
            stream.Seek(int.Parse(rangeParts[0]), SeekOrigin.Begin);
        }
        stream.CopyTo(response.Body);

But it doesn't seem to work.

Fails to handle file uploads

I tried uploading a 5 MB file to a griffin HTTP server (through a form in a page), and it throws a BadRequestException ("First line is not a valid REQUEST/RESPONSE line: ------WebKitFormBoundaryu4oi8KgPtBP26v6q") and dies horribly.

Null reference....

I tried out your library to use the http server... and noticed it fails on http 1.0 requests.

System.NullReferenceException in MultiPartParser

In Griffin.Networking.Protocol.Http.DemoServer project, on sending POST request with multipart/form-data in function HttpMultipart(Stream data, string b, Encoding encoding) b and encodeing are null.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.