Class ServletUtils
- java.lang.Object
-
- org.eclipse.jgit.http.server.ServletUtils
-
public final class ServletUtils extends java.lang.ObjectCommon utility functions for servlets.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTRIBUTE_HANDLERRequest attribute storing either UploadPack or ReceivePack.static java.lang.StringATTRIBUTE_REPOSITORYRequest attribute which stores theRepositoryinstance.
-
Constructor Summary
Constructors Modifier Constructor Description privateServletUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static booleanacceptsGzipEncoding(java.lang.String accepts)(package private) static booleanacceptsGzipEncoding(javax.servlet.http.HttpServletRequest req)private static byte[]compress(byte[] raw)static voidconsumeRequestBody(java.io.InputStream in)Consume the rest of the input stream and discard it.static voidconsumeRequestBody(javax.servlet.http.HttpServletRequest req)Consume the entire request body, if one was supplied.private static java.lang.Stringetag(byte[] content)static java.io.InputStreamgetInputStream(javax.servlet.http.HttpServletRequest req)Open the request input stream, automatically inflating if necessary.static RepositorygetRepository(javax.servlet.ServletRequest req)Get the selected repository from the request.(package private) static java.lang.Stringidentify(Repository git)(package private) static booleanisChunked(javax.servlet.http.HttpServletRequest req)static voidsend(byte[] content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)Send a response to aGETorHEADHTTP request.private static byte[]sendInit(byte[] content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)static voidsendPlainText(java.lang.String content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)Send a plain text response to aGETorHEADHTTP request.
-
-
-
Field Detail
-
ATTRIBUTE_REPOSITORY
public static final java.lang.String ATTRIBUTE_REPOSITORY
Request attribute which stores theRepositoryinstance.- See Also:
- Constant Field Values
-
ATTRIBUTE_HANDLER
public static final java.lang.String ATTRIBUTE_HANDLER
Request attribute storing either UploadPack or ReceivePack.- See Also:
- Constant Field Values
-
-
Method Detail
-
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:
java.lang.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:
ATTRIBUTE_REPOSITORY
-
getInputStream
public static java.io.InputStream getInputStream(javax.servlet.http.HttpServletRequest req) throws java.io.IOExceptionOpen the request input stream, automatically inflating if necessary.This method automatically inflates the input stream if the request
Content-Encodingheader was set togzipor the legacyx-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:
java.io.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(java.io.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(java.lang.String content, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) throws java.io.IOExceptionSend a plain text response to aGETorHEADHTTP 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
ETagandContent-Lengthheaders are automatically set by this method.Content-Encodingis 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:
java.io.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 java.io.IOExceptionSend a response to aGETorHEADHTTP request.If the user agent supports a compressed transfer encoding and the content is large enough, the content may be compressed before sending.
The
ETagandContent-Lengthheaders are automatically set by this method.Content-Encodingis conditionally set if the user agent supports a compressed transfer. Callers are responsible for settingContent-Typeand 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:
java.io.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 java.io.IOException- Throws:
java.io.IOException
-
acceptsGzipEncoding
static boolean acceptsGzipEncoding(javax.servlet.http.HttpServletRequest req)
-
acceptsGzipEncoding
static boolean acceptsGzipEncoding(java.lang.String accepts)
-
compress
private static byte[] compress(byte[] raw) throws java.io.IOException- Throws:
java.io.IOException
-
etag
private static java.lang.String etag(byte[] content)
-
identify
static java.lang.String identify(Repository git)
-
-