Class GitSmartHttpTools
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Name of the git-receive-pack service.static final String
Content type supplied by the client to the /git-receive-pack handler.static final String
Content type returned from the /git-receive-pack handler.static final String
Name of the git-upload-pack service.static final String
Content type supplied by the client to the /git-upload-pack handler.static final String
Content type returned from the /git-upload-pack handler.Git service names accepted by the /info/refs?service= handler. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getResponseContentType
(jakarta.servlet.http.HttpServletRequest req) Get the response Content-Type a client expects for the request.static boolean
isGitClient
(jakarta.servlet.http.HttpServletRequest req) Check a request for Git-over-HTTP indicators.static boolean
isInfoRefs
(jakarta.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /info/refs?service= Git handler.static boolean
isReceivePack
(jakarta.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /git-receive-pack Git handler.static boolean
isUploadPack
(jakarta.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /git-upload-pack Git handler.static boolean
isUploadPack
(String pathOrUri) Check if the HTTP request path ends with the /git-upload-pack handler.static void
sendError
(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, int httpStatus) Send an error to the Git client or browser.static void
sendError
(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, int httpStatus, String textForGit) Send an error to the Git client or browser.static String
stripServiceSuffix
(String path) Strip the Git service suffix from a request path.
-
Field Details
-
UPLOAD_PACK
Name of the git-upload-pack service.- See Also:
-
RECEIVE_PACK
Name of the git-receive-pack service.- See Also:
-
UPLOAD_PACK_REQUEST_TYPE
Content type supplied by the client to the /git-upload-pack handler.- See Also:
-
UPLOAD_PACK_RESULT_TYPE
Content type returned from the /git-upload-pack handler.- See Also:
-
RECEIVE_PACK_REQUEST_TYPE
Content type supplied by the client to the /git-receive-pack handler.- See Also:
-
RECEIVE_PACK_RESULT_TYPE
Content type returned from the /git-receive-pack handler.- See Also:
-
VALID_SERVICES
Git service names accepted by the /info/refs?service= handler.
-
-
Method Details
-
isGitClient
public static boolean isGitClient(jakarta.servlet.http.HttpServletRequest req) Check a request for Git-over-HTTP indicators.- Parameters:
req
- the current HTTP request that may have been made by Git.- Returns:
- true if the request is likely made by a Git client program.
-
sendError
public static void sendError(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, int httpStatus) throws IOException Send an error to the Git client or browser.Server implementors may use this method to send customized error messages to a Git protocol client using an HTTP 200 OK response with the error embedded in the payload. If the request was not issued by a Git client, an HTTP response code is returned instead.
- Parameters:
req
- current request.res
- current response.httpStatus
- HTTP status code to set if the client is not a Git client.- Throws:
IOException
- the response cannot be sent.
-
sendError
public static void sendError(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, int httpStatus, String textForGit) throws IOException Send an error to the Git client or browser.Server implementors may use this method to send customized error messages to a Git protocol client using an HTTP 200 OK response with the error embedded in the payload. If the request was not issued by a Git client, an HTTP response code is returned instead.
This method may only be called before handing off the request to
UploadPack.upload(java.io.InputStream, OutputStream, OutputStream)
orReceivePack.receive(java.io.InputStream, OutputStream, OutputStream)
.- Parameters:
req
- current request.res
- current response.httpStatus
- HTTP status code to set if the client is not a Git client.textForGit
- plain text message to display on the user's console. This is shown only if the client is likely to be a Git client. If null or the empty string a default text is chosen based on the HTTP response code.- Throws:
IOException
- the response cannot be sent.
-
getResponseContentType
Get the response Content-Type a client expects for the request.This method should only be invoked if
isGitClient(HttpServletRequest)
is true.- Parameters:
req
- current request.- Returns:
- the Content-Type the client expects.
- Throws:
IllegalArgumentException
- the request is not a Git client request. SeeisGitClient(HttpServletRequest)
.
-
stripServiceSuffix
Strip the Git service suffix from a request path. Generally the suffix is stripped by theSuffixPipeline
handling the request, so this method is rarely needed.- Parameters:
path
- the path of the request.- Returns:
- the path up to the last path component before the service suffix; the path as-is if it contains no service suffix.
-
isInfoRefs
public static boolean isInfoRefs(jakarta.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /info/refs?service= Git handler.- Parameters:
req
- current request.- Returns:
- true if the request is for the /info/refs service.
-
isUploadPack
Check if the HTTP request path ends with the /git-upload-pack handler.- Parameters:
pathOrUri
- path or URI of the request.- Returns:
- true if the request is for the /git-upload-pack handler.
-
isUploadPack
public static boolean isUploadPack(jakarta.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /git-upload-pack Git handler.- Parameters:
req
- current request.- Returns:
- true if the request is for the /git-upload-pack handler.
-
isReceivePack
public static boolean isReceivePack(jakarta.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /git-receive-pack Git handler.- Parameters:
req
- current request.- Returns:
- true if the request is for the /git-receive-pack handler.
-