Class ServletUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic void
consumeRequestBody
(jakarta.servlet.http.HttpServletRequest req) Consume the entire request body, if one was supplied.static void
Consume the rest of the input stream and discard it.static InputStream
getInputStream
(jakarta.servlet.http.HttpServletRequest req) Open the request input stream, automatically inflating if necessary.static org.eclipse.jgit.lib.Repository
getRepository
(jakarta.servlet.ServletRequest req) Get the selected repository from the request.static void
send
(byte[] content, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse rsp) Send a response to aGET
orHEAD
HTTP request.static void
sendPlainText
(String content, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse rsp) Send a plain text response to aGET
orHEAD
HTTP request.
-
Field Details
-
ATTRIBUTE_REPOSITORY
Request attribute which stores theRepository
instance.- See Also:
-
ATTRIBUTE_HANDLER
Request attribute storing either UploadPack or ReceivePack.- See Also:
-
-
Method Details
-
getRepository
public static org.eclipse.jgit.lib.Repository getRepository(jakarta.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(jakarta.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 togzip
or 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:
IOException
- if an input or output exception occurred.
-
consumeRequestBody
public static void consumeRequestBody(jakarta.servlet.http.HttpServletRequest req) Consume the entire request body, if one was supplied.- Parameters:
req
- the request whose body must be consumed.
-
consumeRequestBody
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, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse rsp) throws IOException Send a plain text response to aGET
orHEAD
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
andContent-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, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse rsp) throws IOException Send a response to aGET
orHEAD
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
andContent-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 settingContent-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.
-