Class ProtocolClient

java.lang.Object
java.io.OutputStream
septogeddon.pluginquery.http.ProtocolClient
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ProtocolClient extends OutputStream
The client, or the browser who requested the http. This is also an OutputStream.
  • Constructor Details

    • ProtocolClient

      public ProtocolClient(String version, HTTPContext httpContext, io.netty.channel.ChannelHandlerContext context)
  • Method Details

    • getVersion

      public String getVersion()
      Get the protocol version. (i.e. HTTP/1.1)
      Returns:
      the protocol version
    • getResponseCode

      public int getResponseCode()
      Get the response code. (i.e. 200 for OK)
      Returns:
      the code
    • getResponseText

      public String getResponseText()
      Get the response text. (i.e. "OK" for response code 200)
      Returns:
      the text
    • setVersion

      public void setVersion(String version)
      Set specific version for the response
      Parameters:
      version - the protocol version
    • setResponseCode

      public void setResponseCode(int responseCode)
      Set the response code for the response
      Parameters:
      responseCode - the code
    • setResponseText

      public void setResponseText(String responseText)
      Set the response text (description)
      Parameters:
      responseText - the text description
    • getHeaders

      public Map<String,HTTPHeader> getHeaders()
      Map of headers
      Returns:
      headers
    • getHTTPContext

      public HTTPContext getHTTPContext()
      Get the HTTP Context for this client request
      Returns:
      HTTPContext instance
    • setHeader

      public void setHeader(String key, Object value)
      Set header for this response
      Parameters:
      key - the header name
      value - the header value
    • getHeader

      public HTTPHeader getHeader(String name)
      Get header value
      Parameters:
      name - the header name
      Returns:
      the header value
    • write

      public void write(int b)
      Initialize and send HTTP response and write byte to the memory buffer. Once this method called, you cannot modify the response header (e.g. setHeader(String, Object), setResponseCode(int), etc)
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte
    • write

      public void write(byte[] b)
      Initialize and send HTTP response and write the bytes to the memory buffer. Once this method called, you cannot modify the response header (e.g. setHeader(String, Object), setResponseCode(int), etc)
      Overrides:
      write in class OutputStream
      Parameters:
      b - the bytes
    • write

      public void write(byte[] b, int off, int len)
      Initialize and send HTTP response and write the bytes to the memory buffer. Once this method called, you cannot modify the response header (e.g. setHeader(String, Object), setResponseCode(int), etc)
      Overrides:
      write in class OutputStream
      Parameters:
      b - the byte array
      off - the offset
      len - the array length
    • flush

      public void flush()
      Send the buffer to the client and flush it from the memory
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
    • close

      public void close()
      Send HTTP response to the client and flush() the buffer
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream