64 lines
1.5 KiB
C#
64 lines
1.5 KiB
C#
// /**
|
|
// * File: Connection.cs
|
|
// * Author: haraldwolff
|
|
// *
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
// *
|
|
// *
|
|
// **/
|
|
using System;
|
|
using ln.type;
|
|
using System.IO;
|
|
using System.Text;
|
|
using ln.logging;
|
|
using ln.http.listener;
|
|
using ln.http.exceptions;
|
|
using ln.protocols.helper;
|
|
|
|
namespace ln.http.connections
|
|
{
|
|
public abstract class Connection : IDisposable
|
|
{
|
|
public Listener Listener { get; private set; }
|
|
|
|
public abstract IPv6 RemoteHost { get; }
|
|
public abstract int RemotePort { get; }
|
|
|
|
public abstract Stream GetStream();
|
|
|
|
public Connection(Listener listener)
|
|
{
|
|
Listener = listener;
|
|
}
|
|
|
|
public virtual HttpRequest ReadRequest(HTTPServer httpServer)
|
|
{
|
|
try
|
|
{
|
|
if (HttpLikeProtocolReader.ReadRequest(GetStream(), Encoding.UTF8, out Request request))
|
|
return new HttpRequest(httpServer, request);
|
|
return null;
|
|
} catch (IOException)
|
|
{
|
|
return null;
|
|
} catch (ConnectionClosedException)
|
|
{
|
|
return null;
|
|
} catch (Exception e)
|
|
{
|
|
Logging.Log(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public abstract void Close();
|
|
public virtual void Dispose()
|
|
{
|
|
Close();
|
|
Listener = null;
|
|
}
|
|
|
|
}
|
|
}
|