Class GitSmartHttpTools
- java.lang.Object
-
- org.eclipse.jgit.http.server.GitSmartHttpTools
-
public class GitSmartHttpTools extends Object
Utility functions for handling the Git-over-HTTP protocol.
-
-
Field Summary
Fields Modifier and Type Field Description static String
RECEIVE_PACK
Name of the git-receive-pack service.static String
RECEIVE_PACK_REQUEST_TYPE
Content type supplied by the client to the /git-receive-pack handler.static String
RECEIVE_PACK_RESULT_TYPE
Content type returned from the /git-receive-pack handler.static String
UPLOAD_PACK
Name of the git-upload-pack service.static String
UPLOAD_PACK_REQUEST_TYPE
Content type supplied by the client to the /git-upload-pack handler.static String
UPLOAD_PACK_RESULT_TYPE
Content type returned from the /git-upload-pack handler.static List<String>
VALID_SERVICES
Git service names accepted by the /info/refs?service= handler.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getResponseContentType(javax.servlet.http.HttpServletRequest req)
Get the response Content-Type a client expects for the request.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.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.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.static String
stripServiceSuffix(String path)
Strip the Git service suffix from a request path.
-
-
-
Field Detail
-
UPLOAD_PACK
public static final String UPLOAD_PACK
Name of the git-upload-pack service.- See Also:
- Constant Field Values
-
RECEIVE_PACK
public static final String RECEIVE_PACK
Name of the git-receive-pack service.- See Also:
- Constant Field Values
-
UPLOAD_PACK_REQUEST_TYPE
public static final String UPLOAD_PACK_REQUEST_TYPE
Content type supplied by the client to the /git-upload-pack handler.- See Also:
- Constant Field Values
-
UPLOAD_PACK_RESULT_TYPE
public static final String UPLOAD_PACK_RESULT_TYPE
Content type returned from the /git-upload-pack handler.- See Also:
- Constant Field Values
-
RECEIVE_PACK_REQUEST_TYPE
public static final String RECEIVE_PACK_REQUEST_TYPE
Content type supplied by the client to the /git-receive-pack handler.- See Also:
- Constant Field Values
-
RECEIVE_PACK_RESULT_TYPE
public static final String RECEIVE_PACK_RESULT_TYPE
Content type returned from the /git-receive-pack handler.- See Also:
- Constant Field Values
-
-
Method Detail
-
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.
-
getResponseContentType
public static String getResponseContentType(javax.servlet.http.HttpServletRequest req)
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
public static String stripServiceSuffix(String path)
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
public static boolean isUploadPack(String pathOrUri)
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.
-
-