Class GitSmartHttpTools
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static final String
static final String
Name of the git-receive-pack service.private static final String
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.private static final String
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. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getResponseContentType
(javax.servlet.http.HttpServletRequest req) Get the response Content-Type a client expects for the request.(package private) static String
infoRefsResultType
(String svc) static boolean
isGitClient
(javax.servlet.http.HttpServletRequest req) Check a request for Git-over-HTTP indicators.static boolean
isInfoRefs
(javax.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /info/refs?service= Git handler.static boolean
isReceivePack
(javax.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /git-receive-pack Git handler.private static boolean
isReceivePackSideBand
(javax.servlet.http.HttpServletRequest req) static boolean
isUploadPack
(String pathOrUri) Check if the HTTP request path ends with the /git-upload-pack handler.static boolean
isUploadPack
(javax.servlet.http.HttpServletRequest req) Check if the HTTP request was for the /git-upload-pack Git handler.private static void
send
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String type, byte[] buf) static void
sendError
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int httpStatus) Send an error to the Git client or browser.static void
sendError
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int httpStatus, String textForGit) Send an error to the Git client or browser.private static void
sendInfoRefsError
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String textForGit) private static void
sendReceivePackError
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String textForGit) private static void
sendUploadPackError
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String textForGit) static String
stripServiceSuffix
(String path) Strip the Git service suffix from a request path.private static void
writePacket
(PacketLineOut pckOut, String textForGit) private static void
writeSideBand
(OutputStream out, String textForGit)
-
Field Details
-
INFO_REFS
- See Also:
-
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. -
INFO_REFS_PATH
- See Also:
-
UPLOAD_PACK_PATH
- See Also:
-
RECEIVE_PACK_PATH
- See Also:
-
SERVICE_SUFFIXES
-
-
Constructor Details
-
GitSmartHttpTools
private GitSmartHttpTools()
-
-
Method Details
-
isGitClient
public static boolean isGitClient(javax.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(javax.servlet.http.HttpServletRequest req, javax.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(javax.servlet.http.HttpServletRequest req, javax.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.
-
sendInfoRefsError
private static void sendInfoRefsError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String textForGit) throws IOException - Throws:
IOException
-
sendUploadPackError
private static void sendUploadPackError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String textForGit) throws IOException - Throws:
IOException
-
sendReceivePackError
private static void sendReceivePackError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String textForGit) throws IOException - Throws:
IOException
-
isReceivePackSideBand
private static boolean isReceivePackSideBand(javax.servlet.http.HttpServletRequest req) -
writeSideBand
- Throws:
IOException
-
writePacket
- Throws:
IOException
-
send
private static void send(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, String type, byte[] buf) throws IOException - Throws:
IOException
-
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)
.
-
infoRefsResultType
-
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(javax.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(javax.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(javax.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.
-