public class GitSmartHttpTools
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
INFO_REFS |
private static java.lang.String |
INFO_REFS_PATH |
static java.lang.String |
RECEIVE_PACK
Name of the git-receive-pack service.
|
private static java.lang.String |
RECEIVE_PACK_PATH |
static java.lang.String |
RECEIVE_PACK_REQUEST_TYPE
Content type supplied by the client to the /git-receive-pack handler.
|
static java.lang.String |
RECEIVE_PACK_RESULT_TYPE
Content type returned from the /git-receive-pack handler.
|
private static java.util.List<java.lang.String> |
SERVICE_SUFFIXES |
static java.lang.String |
UPLOAD_PACK
Name of the git-upload-pack service.
|
private static java.lang.String |
UPLOAD_PACK_PATH |
static java.lang.String |
UPLOAD_PACK_REQUEST_TYPE
Content type supplied by the client to the /git-upload-pack handler.
|
static java.lang.String |
UPLOAD_PACK_RESULT_TYPE
Content type returned from the /git-upload-pack handler.
|
static java.util.List<java.lang.String> |
VALID_SERVICES
Git service names accepted by the /info/refs?service= handler.
|
Modifier | Constructor and Description |
---|---|
private |
GitSmartHttpTools() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getResponseContentType(javax.servlet.http.HttpServletRequest req)
Get the response Content-Type a client expects for the request.
|
(package private) static java.lang.String |
infoRefsResultType(java.lang.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(javax.servlet.http.HttpServletRequest req)
Check if the HTTP request was for the /git-upload-pack Git handler.
|
static boolean |
isUploadPack(java.lang.String pathOrUri)
Check if the HTTP request path ends with the /git-upload-pack handler.
|
private static void |
send(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.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,
java.lang.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,
java.lang.String textForGit) |
private static void |
sendReceivePackError(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String textForGit) |
private static void |
sendUploadPackError(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String textForGit) |
static java.lang.String |
stripServiceSuffix(java.lang.String path)
Strip the Git service suffix from a request path.
|
private static void |
writePacket(PacketLineOut pckOut,
java.lang.String textForGit) |
private static void |
writeSideBand(java.io.OutputStream out,
java.lang.String textForGit) |
private static final java.lang.String INFO_REFS
public static final java.lang.String UPLOAD_PACK
public static final java.lang.String RECEIVE_PACK
public static final java.lang.String UPLOAD_PACK_REQUEST_TYPE
public static final java.lang.String UPLOAD_PACK_RESULT_TYPE
public static final java.lang.String RECEIVE_PACK_REQUEST_TYPE
public static final java.lang.String RECEIVE_PACK_RESULT_TYPE
public static final java.util.List<java.lang.String> VALID_SERVICES
private static final java.lang.String INFO_REFS_PATH
private static final java.lang.String UPLOAD_PACK_PATH
private static final java.lang.String RECEIVE_PACK_PATH
private static final java.util.List<java.lang.String> SERVICE_SUFFIXES
public static boolean isGitClient(javax.servlet.http.HttpServletRequest req)
req
- the current HTTP request that may have been made by Git.public static void sendError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int httpStatus) throws java.io.IOException
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.
req
- current request.res
- current response.httpStatus
- HTTP status code to set if the client is not a Git client.java.io.IOException
- the response cannot be sent.public static void sendError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int httpStatus, java.lang.String textForGit) throws java.io.IOException
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)
or
ReceivePack.receive(java.io.InputStream, OutputStream, OutputStream)
.
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.java.io.IOException
- the response cannot be sent.private static void sendInfoRefsError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String textForGit) throws java.io.IOException
java.io.IOException
private static void sendUploadPackError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String textForGit) throws java.io.IOException
java.io.IOException
private static void sendReceivePackError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String textForGit) throws java.io.IOException
java.io.IOException
private static boolean isReceivePackSideBand(javax.servlet.http.HttpServletRequest req)
private static void writeSideBand(java.io.OutputStream out, java.lang.String textForGit) throws java.io.IOException
java.io.IOException
private static void writePacket(PacketLineOut pckOut, java.lang.String textForGit) throws java.io.IOException
java.io.IOException
private static void send(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String type, byte[] buf) throws java.io.IOException
java.io.IOException
public static java.lang.String getResponseContentType(javax.servlet.http.HttpServletRequest req)
This method should only be invoked if
isGitClient(HttpServletRequest)
is true.
req
- current request.java.lang.IllegalArgumentException
- the request is not a Git client request. See
isGitClient(HttpServletRequest)
.static java.lang.String infoRefsResultType(java.lang.String svc)
public static java.lang.String stripServiceSuffix(java.lang.String path)
SuffixPipeline
handling
the request, so this method is rarely needed.path
- the path of the request.public static boolean isInfoRefs(javax.servlet.http.HttpServletRequest req)
req
- current request.public static boolean isUploadPack(java.lang.String pathOrUri)
pathOrUri
- path or URI of the request.public static boolean isUploadPack(javax.servlet.http.HttpServletRequest req)
req
- current request.public static boolean isReceivePack(javax.servlet.http.HttpServletRequest req)
req
- current request.