Package org.omegazero.http.h1
Class HTTP1MessageTransmitter
java.lang.Object
org.omegazero.http.h1.HTTP1MessageTransmitter
This class is used for transmitting HTTP headers.
HTTPRequest
s and HTTPResponse
s 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 void
addHeaders
(HTTPMessage msg, StringBuilder sb) Adds any headers that are not part of the defaultHTTPMessage
header map.static void
appendHeader
(StringBuilder sb, String name, String value) Appends a HTTP/1-style header to the givenStringBuilder
.byte[]
generate
(HTTPMessage msg) Encodes the givenHTTPMessage
into a byte array.Returns theWritableSocket
passed in the constructor.protected String
getStartLine
(HTTPMessage msg) Returns the HTTP/1 start line of the givenHTTPMessage
.void
send
(HTTPMessage msg) Encodes the givenHTTPMessage
usinggenerate(HTTPMessage)
and writes it to theWritableSocket
passed in the constructor.
-
Field Details
-
socket
-
-
Constructor Details
-
HTTP1MessageTransmitter
public HTTP1MessageTransmitter()Creates a newHTTP1MessageTransmitter
. -
HTTP1MessageTransmitter
Creates a newHTTP1MessageTransmitter
.- Parameters:
socket
- The socket to write encodedHTTPMessage
s to. This is only required issend(HTTPMessage)
is used
-
-
Method Details
-
send
Encodes the givenHTTPMessage
usinggenerate(HTTPMessage)
and writes it to theWritableSocket
passed in the constructor.- Parameters:
msg
- TheHTTPMessage
- See Also:
-
generate
Encodes the givenHTTPMessage
into 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 defaultHTTPMessage
header map. For example,HTTPRequest
s have an additional Host header with the value ofHTTPRequest.getAuthority()
.Headers are added to the given
StringBuilder
usingappendHeader(StringBuilder, String, String)
.- Parameters:
msg
- TheHTTPMessage
sb
- The string builder
-
getSocket
Returns theWritableSocket
passed 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
-