Package org.omegazero.http.h1
Class HTTP1MessageTransmitter
java.lang.Object
org.omegazero.http.h1.HTTP1MessageTransmitter
This class is used for transmitting HTTP headers.
HTTPRequests and HTTPResponses are supported by this class.
- Since:
- 1.2.1
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newHTTP1MessageTransmitter.Creates a newHTTP1MessageTransmitter. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddHeaders(HTTPMessage msg, StringBuilder sb) Adds any headers that are not part of the defaultHTTPMessageheader map.static voidappendHeader(StringBuilder sb, String name, String value) Appends a HTTP/1-style header to the givenStringBuilder.byte[]generate(HTTPMessage msg) Encodes the givenHTTPMessageinto a byte array.Returns theWritableSocketpassed in the constructor.protected StringgetStartLine(HTTPMessage msg) Returns the HTTP/1 start line of the givenHTTPMessage.voidsend(HTTPMessage msg) Encodes the givenHTTPMessageusinggenerate(HTTPMessage)and writes it to theWritableSocketpassed in the constructor.
-
Field Details
-
socket
-
-
Constructor Details
-
HTTP1MessageTransmitter
public HTTP1MessageTransmitter()Creates a newHTTP1MessageTransmitter. -
HTTP1MessageTransmitter
Creates a newHTTP1MessageTransmitter.- Parameters:
socket- The socket to write encodedHTTPMessages to. This is only required issend(HTTPMessage)is used
-
-
Method Details
-
send
Encodes the givenHTTPMessageusinggenerate(HTTPMessage)and writes it to theWritableSocketpassed in the constructor.- Parameters:
msg- TheHTTPMessage- See Also:
-
generate
Encodes the givenHTTPMessageinto a byte array. This includes the request or response line (depending on the type ofHTTPMessage), the HTTP headers and the terminatingCR LF.- Parameters:
msg- TheHTTPMessage- Returns:
- The encoded data
-
getStartLine
Returns the HTTP/1 start line of the givenHTTPMessage.- Parameters:
msg- TheHTTPMessage- Returns:
- The start line
-
addHeaders
Adds any headers that are not part of the defaultHTTPMessageheader map. For example,HTTPRequests have an additional Host header with the value ofHTTPRequest.getAuthority().Headers are added to the given
StringBuilderusingappendHeader(StringBuilder, String, String).- Parameters:
msg- TheHTTPMessagesb- The string builder
-
getSocket
Returns theWritableSocketpassed in the constructor.- Returns:
- The
WritableSocket
-
appendHeader
Appends a HTTP/1-style header to the givenStringBuilder.- Parameters:
sb- The string buildername- The header namevalue- The header value
-