Top Description Fields Constructors Methods
org.eclipse.jgit.http.server

public final Class ServletUtils

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.eclipse.jgit.util.HttpSupport.ENCODING_GZIP, .HttpSupport.ENCODING_X_GZIP, .HttpSupport.HDR_ACCEPT_ENCODING, .HttpSupport.HDR_CONTENT_ENCODING, .HttpSupport.HDR_ETAG, .HttpSupport.TEXT_PLAIN

Common utility functions for servlets.

Field Summary

Modifier and TypeField and Description
public static final String
ATTRIBUTE_HANDLER

Request attribute storing either UploadPack or ReceivePack.

public static final String
ATTRIBUTE_REPOSITORY

Request attribute which stores the Repository instance.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static boolean
pack-priv static boolean
private static byte[]
compress(byte[] raw)

public static void
consumeRequestBody(HttpServletRequest
the request whose body must be consumed.
req
)

Consume the entire request body, if one was supplied.

public static void
consumeRequestBody(InputStream
the stream to discard, closed if not null.
in
)

Consume the rest of the input stream and discard it.

private static String
etag(byte[] content)

public static InputStream

Returns:

an input stream to read the raw, uncompressed request body.
getInputStream
(HttpServletRequest
the incoming request whose input stream needs to be opened.
req
)

Open the request input stream, automatically inflating if necessary.

public static Repository

Returns:

the repository; never null.
getRepository
(ServletRequest
the current request.
req
)

Get the selected repository from the request.

pack-priv static String
pack-priv static boolean
public static void
send(byte[]
to return to the user agent as this entity's body.
content
,
final HttpServletRequest
the incoming request.
req
,
final HttpServletResponse
the outgoing response.
rsp
)

Send a response to a GET or HEAD HTTP request.

private static byte[]
sendInit(byte[] content, final HttpServletRequest req, final HttpServletResponse rsp)

public static void
sendPlainText(final String
to return to the user agent as this entity's body.
content
,
final HttpServletRequest
the incoming request.
req
,
final HttpServletResponse
the outgoing response.
rsp
)

Send a plain text response to a GET or HEAD HTTP request.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ATTRIBUTE_HANDLERback to summary
public static final String ATTRIBUTE_HANDLER

Request attribute storing either UploadPack or ReceivePack.

ATTRIBUTE_REPOSITORYback to summary
public static final String ATTRIBUTE_REPOSITORY

Request attribute which stores the Repository instance.

Constructor Detail

ServletUtilsback to summary
private ServletUtils()

Method Detail

acceptsGzipEncodingback to summary
pack-priv static boolean acceptsGzipEncoding(HttpServletRequest req)
acceptsGzipEncodingback to summary
pack-priv static boolean acceptsGzipEncoding(String accepts)
compressback to summary
private static byte[] compress(byte[] raw) throws IOException
consumeRequestBodyback to summary
public static void consumeRequestBody(HttpServletRequest req)

Consume the entire request body, if one was supplied.

Parameters
req:HttpServletRequest

the request whose body must be consumed.

Since
7.0
consumeRequestBodyback to summary
public static void consumeRequestBody(InputStream in)

Consume the rest of the input stream and discard it.

Parameters
in:InputStream

the stream to discard, closed if not null.

etagback to summary
private static String etag(byte[] content)
getInputStreamback to summary
public static InputStream getInputStream(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:HttpServletRequest

the incoming request whose input stream needs to be opened.

Returns:InputStream

an input stream to read the raw, uncompressed request body.

Exceptions
IOException:
if an input or output exception occurred.
Since
7.0
getRepositoryback to summary
public static Repository getRepository(ServletRequest req)

Get the selected repository from the request.

Parameters
req:ServletRequest

the current request.

Returns:Repository

the repository; never null.

Exceptions
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.
Since
7.0
See Also
ATTRIBUTE_REPOSITORY
identifyback to summary
pack-priv static String identify(Repository git)
isChunkedback to summary
pack-priv static boolean isChunked(HttpServletRequest req)
sendback to summary
public static void send(byte[] content, final HttpServletRequest req, final 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:byte[]

to return to the user agent as this entity's body.

req:HttpServletRequest

the incoming request.

rsp:HttpServletResponse

the outgoing response.

Exceptions
IOException:
the servlet API rejected sending the body.
Since
7.0
sendInitback to summary
private static byte[] sendInit(byte[] content, final HttpServletRequest req, final HttpServletResponse rsp) throws IOException
sendPlainTextback to summary
public static void sendPlainText(final String content, final HttpServletRequest req, final 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:String

to return to the user agent as this entity's body.

req:HttpServletRequest

the incoming request.

rsp:HttpServletResponse

the outgoing response.

Exceptions
IOException:
the servlet API rejected sending the body.
Since
7.0