Class ServletUtils

java.lang.Object
org.eclipse.jgit.http.server.ServletUtils

public final class ServletUtils extends Object
Common utility functions for servlets.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Request attribute storing either UploadPack or ReceivePack.
    static final String
    Request attribute which stores the Repository instance.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static boolean
     
    (package private) static boolean
    acceptsGzipEncoding(javax.servlet.http.HttpServletRequest req)
     
    private static byte[]
    compress(byte[] raw)
     
    static void
    Consume the rest of the input stream and discard it.
    static void
    consumeRequestBody(javax.servlet.http.HttpServletRequest req)
    Consume the entire request body, if one was supplied.
    private static String
    etag(byte[] content)
     
    getInputStream(javax.servlet.http.HttpServletRequest req)
    Open the request input stream, automatically inflating if necessary.
    static Repository
    getRepository(javax.servlet.ServletRequest req)
    Get the selected repository from the request.
    (package private) static String
     
    (package private) static boolean
    isChunked(javax.servlet.http.HttpServletRequest req)
     
    static void
    send(byte[] content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)
    Send a response to a GET or HEAD HTTP request.
    private static byte[]
    sendInit(byte[] content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)
     
    static void
    sendPlainText(String content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)
    Send a plain text response to a GET or HEAD HTTP request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ServletUtils

      private ServletUtils()
  • Method Details

    • getRepository

      public static Repository getRepository(javax.servlet.ServletRequest req)
      Get the selected repository from the request.
      Parameters:
      req - the current request.
      Returns:
      the repository; never null.
      Throws:
      IllegalStateException - the repository was not set by the filter, the servlet is being invoked incorrectly and the programmer should ensure the filter runs before the servlet.
      See Also:
    • getInputStream

      public static InputStream getInputStream(javax.servlet.http.HttpServletRequest req) throws IOException
      Open the request input stream, automatically inflating if necessary.

      This method automatically inflates the input stream if the request Content-Encoding header was set to gzip or the legacy x-gzip.

      Parameters:
      req - the incoming request whose input stream needs to be opened.
      Returns:
      an input stream to read the raw, uncompressed request body.
      Throws:
      IOException - if an input or output exception occurred.
    • consumeRequestBody

      public static void consumeRequestBody(javax.servlet.http.HttpServletRequest req)
      Consume the entire request body, if one was supplied.
      Parameters:
      req - the request whose body must be consumed.
    • isChunked

      static boolean isChunked(javax.servlet.http.HttpServletRequest req)
    • consumeRequestBody

      public static void consumeRequestBody(InputStream in)
      Consume the rest of the input stream and discard it.
      Parameters:
      in - the stream to discard, closed if not null.
    • sendPlainText

      public static void sendPlainText(String content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) throws IOException
      Send a plain text response to a GET or HEAD HTTP request.

      The text response is encoded in the Git character encoding, UTF-8.

      If the user agent supports a compressed transfer encoding and the content is large enough, the content may be compressed before sending.

      The ETag and Content-Length headers are automatically set by this method. Content-Encoding is conditionally set if the user agent supports a compressed transfer. Callers are responsible for setting any cache control headers.

      Parameters:
      content - to return to the user agent as this entity's body.
      req - the incoming request.
      rsp - the outgoing response.
      Throws:
      IOException - the servlet API rejected sending the body.
    • send

      public static void send(byte[] content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) throws IOException
      Send a response to a GET or HEAD HTTP request.

      If the user agent supports a compressed transfer encoding and the content is large enough, the content may be compressed before sending.

      The ETag and Content-Length headers are automatically set by this method. Content-Encoding is conditionally set if the user agent supports a compressed transfer. Callers are responsible for setting Content-Type and any cache control headers.

      Parameters:
      content - to return to the user agent as this entity's body.
      req - the incoming request.
      rsp - the outgoing response.
      Throws:
      IOException - the servlet API rejected sending the body.
    • sendInit

      private static byte[] sendInit(byte[] content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) throws IOException
      Throws:
      IOException
    • acceptsGzipEncoding

      static boolean acceptsGzipEncoding(javax.servlet.http.HttpServletRequest req)
    • acceptsGzipEncoding

      static boolean acceptsGzipEncoding(String accepts)
    • compress

      private static byte[] compress(byte[] raw) throws IOException
      Throws:
      IOException
    • etag

      private static String etag(byte[] content)
    • identify

      static String identify(Repository git)