PeanutButter
Loading...
Searching...
No Matches
PeanutButter.SimpleHTTPServer.HttpProcessor Class Reference

Processor for HTTP requests on top of the generic TCP processor. More...

Inheritance diagram for PeanutButter.SimpleHTTPServer.HttpProcessor:
PeanutButter.SimpleHTTPServer.TcpServerProcessor PeanutButter.SimpleTcpServer.IProcessor

Public Member Functions

 HttpProcessor (TcpClient tcpClient, HttpServerBase server)
void ProcessRequest ()
 Process the request.
void ParseRequest ()
 Parses the request from the TcpClient.
void ReadHeaders ()
 Reads in the headers from the TcpClient.
void ParseFormElementsIfRequired (MemoryStream ms)
 Parses form data on the request, if available.
void WriteSuccess (string mimeType=HttpConstants.MimeTypes.HTML, byte[] data=null)
 Perform a successful write (ie, HTTP status 200) with the optionally provided mime type and data data.
void WriteMIMETypeHeader (string mimeType)
 Writes the specified MIME header (Content-Type)
void WriteOKStatusHeader ()
 Writes the OK status header.
void WriteContentLengthHeader (int length)
 Writes the Content-Length header with the provided length.
void WriteConnectionClosesAfterCommsHeader ()
 Writes the header informing the client that the connection will not be held open.
void WriteHeader (string header, string value)
 Writes an arbitrary header to the response stream.
void WriteHeader (string header, int value)
 Writes an integer-value header to the response stream.
void WriteStatusHeader (HttpStatusCode code, string message=null)
 Writes the specified status header to the response stream, with the optional message.
void WriteDataToStream (byte[] data)
 Writes arbitrary byte data to the response stream.
void WriteDataToStream (string data)
 Writes an arbitrary string to the response stream.
void WriteFailure (HttpStatusCode code)
 Writes out a simple http failure.
void WriteFailure (HttpStatusCode code, string message)
 Writes a failure code and message to the response stream and closes the response.
void WriteFailure (HttpStatusCode code, string message, string body)
 Writes out an http failure with body text.
void WriteFailure (HttpStatusCode code, string message, string body, string mimeType)
 Write out a failure with a message, body and custom mime-type.
void WriteEmptyLineToStream ()
 Writes an empty line to the stream: HTTP is line-based, so the client will probably interpret this as an end of section / request.
void WriteResponseLine (string response)
 Write an arbitrary string response to the response stream.
void WriteDocument (string document)
 Write a textural document to the response stream with the assumption that the mime type is text/html.
void WriteDocument (string document, string mimeType)
 Write a textural document to the response stream with the optionally-provided mime type.

Protected Member Functions

void HandleRequest (TcpIoWrapper io)
 Handles the request, given an IO wrapper.
Protected Member Functions inherited from PeanutButter.SimpleHTTPServer.TcpServerProcessor
 TcpServerProcessor (TcpClient client)

Properties

Action< string > LogAction [get]
 Action to use when attempting to log arbitrary data.
Action< RequestLogItemRequestLogAction [get]
 Action to use when attempting to log requests.
HttpServerBase Server [get, protected set]
 Provides access to the server associated with this processor.
string Method [get]
 Method of the current request being processed.
string FullUrl [get]
 Full url for the request being processed.
string FullPath [get]
 The full path, including query, for the request being processed.
string Path [get]
 Just the path for the request being processed.
string Protocol [get]
 Protocol for the request being processed.
Dictionary< string, string > UrlParameters [get, set]
 Url parameters for the request being processed.
Dictionary< string, string > HttpHeaders [get]
 Headers on the request being processed.
long MaxPostSize = MAX_POST_SIZE [get, set]
 Maximum size, in bytes, to accept for a POST.
Dictionary< string, string > FormData [get, set]
 Form data associated with the request.
Properties inherited from PeanutButter.SimpleHTTPServer.TcpServerProcessor
TcpClient TcpClient [get, protected set]
 Provides access to the TcpClient.

Detailed Description

Processor for HTTP requests on top of the generic TCP processor.

Member Function Documentation

◆ HandleRequest()

void PeanutButter.SimpleHTTPServer.HttpProcessor.HandleRequest ( TcpIoWrapper io)
protected

Handles the request, given an IO wrapper.

Parameters
io

◆ ParseFormElementsIfRequired()

void PeanutButter.SimpleHTTPServer.HttpProcessor.ParseFormElementsIfRequired ( MemoryStream ms)

Parses form data on the request, if available.

Parameters
ms

◆ ProcessRequest()

void PeanutButter.SimpleHTTPServer.HttpProcessor.ProcessRequest ( )

Process the request.

Implements PeanutButter.SimpleTcpServer.IProcessor.

◆ WriteContentLengthHeader()

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteContentLengthHeader ( int length)

Writes the Content-Length header with the provided length.

Parameters
length

◆ WriteDataToStream() [1/2]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteDataToStream ( byte[] data)

Writes arbitrary byte data to the response stream.

Parameters
data

◆ WriteDataToStream() [2/2]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteDataToStream ( string data)

Writes an arbitrary string to the response stream.

Parameters
data

◆ WriteDocument() [1/2]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteDocument ( string document)

Write a textural document to the response stream with the assumption that the mime type is text/html.

Parameters
document

◆ WriteDocument() [2/2]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteDocument ( string document,
string mimeType )

Write a textural document to the response stream with the optionally-provided mime type.

Parameters
document
mimeType

◆ WriteFailure() [1/4]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteFailure ( HttpStatusCode code)

Writes out a simple http failure.

Parameters
code

◆ WriteFailure() [2/4]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteFailure ( HttpStatusCode code,
string message )

Writes a failure code and message to the response stream and closes the response.

Parameters
code
message

◆ WriteFailure() [3/4]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteFailure ( HttpStatusCode code,
string message,
string body )

Writes out an http failure with body text.

Parameters
codeThe http code to return
messageThe message to add to the status line
bodyThe body to write out

◆ WriteFailure() [4/4]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteFailure ( HttpStatusCode code,
string message,
string body,
string mimeType )

Write out a failure with a message, body and custom mime-type.

Parameters
code
message
body
mimeType

◆ WriteHeader() [1/2]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteHeader ( string header,
int value )

Writes an integer-value header to the response stream.

Parameters
header
value

◆ WriteHeader() [2/2]

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteHeader ( string header,
string value )

Writes an arbitrary header to the response stream.

Parameters
header
value

◆ WriteMIMETypeHeader()

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteMIMETypeHeader ( string mimeType)

Writes the specified MIME header (Content-Type)

Parameters
mimeType

◆ WriteResponseLine()

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteResponseLine ( string response)

Write an arbitrary string response to the response stream.

Parameters
response

◆ WriteStatusHeader()

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteStatusHeader ( HttpStatusCode code,
string message = null )

Writes the specified status header to the response stream, with the optional message.

Parameters
code
message

◆ WriteSuccess()

void PeanutButter.SimpleHTTPServer.HttpProcessor.WriteSuccess ( string mimeType = HttpConstants::MimeTypes::HTML,
byte[] data = null )

Perform a successful write (ie, HTTP status 200) with the optionally provided mime type and data data.

Parameters
mimeType
data

The documentation for this class was generated from the following file:
  • source/SimpleServers/PeanutButter.SimpleHTTPServer/HttpProcessor.cs