public void FilterRequest(RequestContext request, ResponseContext response) { if (request.Uri.LocalPath == "\\DontLetMeIn") { response.HttpStatusCode = new Forbidden(); response.Data = "Forbidden - 403"; } }
internal void BuildResponseContextBase(ResponseContext responseContext, RequestContext requestContext) { responseContext.Headers.AddValue("ContentType", ""); // Content-Type: text/html; charset=utf-8 responseContext.Headers.AddValue("Content-Length", "0"); responseContext.Headers.AddValue("Accept-Ranges", "bytes"); responseContext.Headers.AddValue("Connection", "close"); responseContext.Headers.AddValue("Server", "Fredde Web Server 1.0"); responseContext.HttpVersion = "HTTP/1.1"; return; }
private void GetHeaderPartsFromSocket(Socket socket, RequestContext requestContext) { var headerSize = 0; byte[] buffer = new byte[_serverContext.BufferSize]; var requestLineSet = false; var RequestLineHeader = string.Empty; while (socket.Available > 0) { socket.ReceiveUntil(buffer, "\r\n"); var headerString = new String(Encoding.UTF8.GetChars(buffer)); // End if no more headers is discovered if (headerString == null) { break; } headerSize += headerString.Length; // Check on sum of header size to try to avoid out of memory exceptions and other nasty things if (headerSize > _serverContext.MaxClientHeaderSize) { throw new EntityToLargeException("Header entity is to large (HTTP413)"); } if (!requestLineSet) { if (headerString == null || headerString == string.Empty) { throw new ArgumentNullException("Request does not contain any data"); } requestLineSet = true; RequestLineHeader = headerString; } else { requestContext.SetHeader(headerString); } } requestContext.SetRequestLineAndUri(RequestLineHeader); }
public HttpContext(RequestContext requestContext, ResponseContext responseContext, Socket socket) { Request = requestContext; Response = responseContext; Socket = socket; }
internal void ProcessRequest(Socket socket, RequestContext requestContext) { requestContext.IpEndPoint = socket.RemoteEndPoint as IPEndPoint; GetHeaderPartsFromSocket(socket, requestContext); }