Top Description Fields Constructors Methods
org.eclipse.jgit.http.server

public Class GitSmartHttpTools

extends Object
Class Inheritance
Static Imports
jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN, .HttpServletResponse.SC_INTERNAL_SERVER_ERROR, .HttpServletResponse.SC_NOT_FOUND, org.eclipse.jgit.http.server.ServletUtils.ATTRIBUTE_HANDLER, org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_SIDE_BAND_64K, .SideBandOutputStream.CH_ERROR, .SideBandOutputStream.SMALL_BUF

Utility functions for handling the Git-over-HTTP protocol.

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
public static final String
RECEIVE_PACK

Name of the git-receive-pack service.

private static final String
public static final String
RECEIVE_PACK_REQUEST_TYPE

Content type supplied by the client to the /git-receive-pack handler.

public static final String
RECEIVE_PACK_RESULT_TYPE

Content type returned from the /git-receive-pack handler.

private static final List<String>
public static final String
UPLOAD_PACK

Name of the git-upload-pack service.

private static final String
public static final String
UPLOAD_PACK_REQUEST_TYPE

Content type supplied by the client to the /git-upload-pack handler.

public static final String
UPLOAD_PACK_RESULT_TYPE

Content type returned from the /git-upload-pack handler.

public static final List<String>
VALID_SERVICES

Git service names accepted by the /info/refs?service= handler.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the Content-Type the client expects.
getResponseContentType
(HttpServletRequest
current request.
req
)

Get the response Content-Type a client expects for the request.

pack-priv static String
public static boolean

Returns:

true if the request is likely made by a Git client program.
isGitClient
(HttpServletRequest
the current HTTP request that may have been made by Git.
req
)

Check a request for Git-over-HTTP indicators.

public static boolean

Returns:

true if the request is for the /info/refs service.
isInfoRefs
(HttpServletRequest
current request.
req
)

Check if the HTTP request was for the /info/refs?service= Git handler.

public static boolean

Returns:

true if the request is for the /git-receive-pack handler.
isReceivePack
(HttpServletRequest
current request.
req
)

Check if the HTTP request was for the /git-receive-pack Git handler.

private static boolean
public static boolean

Returns:

true if the request is for the /git-upload-pack handler.
isUploadPack
(String
path or URI of the request.
pathOrUri
)

Check if the HTTP request path ends with the /git-upload-pack handler.

public static boolean

Returns:

true if the request is for the /git-upload-pack handler.
isUploadPack
(HttpServletRequest
current request.
req
)

Check if the HTTP request was for the /git-upload-pack Git handler.

private static void
send(HttpServletRequest req, HttpServletResponse res, String type, byte[] buf, int httpStatus)

public static void
sendError(HttpServletRequest
current request.
req
,
HttpServletResponse
current response.
res
,
int
HTTP status code to set if the client is not a Git client.
httpStatus
)

Send an error to the Git client or browser.

public static void
sendError(HttpServletRequest
current request.
req
,
HttpServletResponse
current response.
res
,
int
HTTP status code to set if the client is not a Git client.
httpStatus
,
String
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.
textForGit
)

Send an error to the Git client or browser.

private static void
sendInfoRefsError(HttpServletRequest req, HttpServletResponse res, String textForGit, int httpStatus)

private static void
sendReceivePackError(HttpServletRequest req, HttpServletResponse res, String textForGit, int httpStatus)

private static void
sendUploadPackError(HttpServletRequest req, HttpServletResponse res, String textForGit, int httpStatus)

public static String

Returns:

the path up to the last path component before the service suffix; the path as-is if it contains no service suffix.
stripServiceSuffix
(String
the path of the request.
path
)

Strip the Git service suffix from a request path.

private static void
writePacket(PacketLineOut pckOut, String textForGit)

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INFO_REFSback to summary
private static final String INFO_REFS
INFO_REFS_PATHback to summary
private static final String INFO_REFS_PATH
RECEIVE_PACKback to summary
public static final String RECEIVE_PACK

Name of the git-receive-pack service.

RECEIVE_PACK_PATHback to summary
private static final String RECEIVE_PACK_PATH
RECEIVE_PACK_REQUEST_TYPEback to summary
public static final String RECEIVE_PACK_REQUEST_TYPE

Content type supplied by the client to the /git-receive-pack handler.

RECEIVE_PACK_RESULT_TYPEback to summary
public static final String RECEIVE_PACK_RESULT_TYPE

Content type returned from the /git-receive-pack handler.

SERVICE_SUFFIXESback to summary
private static final List<String> SERVICE_SUFFIXES
UPLOAD_PACKback to summary
public static final String UPLOAD_PACK

Name of the git-upload-pack service.

UPLOAD_PACK_PATHback to summary
private static final String UPLOAD_PACK_PATH
UPLOAD_PACK_REQUEST_TYPEback to summary
public static final String UPLOAD_PACK_REQUEST_TYPE

Content type supplied by the client to the /git-upload-pack handler.

UPLOAD_PACK_RESULT_TYPEback to summary
public static final String UPLOAD_PACK_RESULT_TYPE

Content type returned from the /git-upload-pack handler.

VALID_SERVICESback to summary
public static final List<String> VALID_SERVICES

Git service names accepted by the /info/refs?service= handler.

Constructor Detail

GitSmartHttpToolsback to summary
private GitSmartHttpTools()

Method Detail

getResponseContentTypeback to summary
public static String getResponseContentType(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:HttpServletRequest

current request.

Returns:String

the Content-Type the client expects.

Exceptions
IllegalArgumentException:
the request is not a Git client request. See isGitClient(HttpServletRequest).
Since
7.0
infoRefsResultTypeback to summary
pack-priv static String infoRefsResultType(String svc)
isGitClientback to summary
public static boolean isGitClient(HttpServletRequest req)

Check a request for Git-over-HTTP indicators.

Parameters
req:HttpServletRequest

the current HTTP request that may have been made by Git.

Returns:boolean

true if the request is likely made by a Git client program.

Since
7.0
isInfoRefsback to summary
public static boolean isInfoRefs(HttpServletRequest req)

Check if the HTTP request was for the /info/refs?service= Git handler.

Parameters
req:HttpServletRequest

current request.

Returns:boolean

true if the request is for the /info/refs service.

Since
7.0
isReceivePackback to summary
public static boolean isReceivePack(HttpServletRequest req)

Check if the HTTP request was for the /git-receive-pack Git handler.

Parameters
req:HttpServletRequest

current request.

Returns:boolean

true if the request is for the /git-receive-pack handler.

Since
7.0
isReceivePackSideBandback to summary
private static boolean isReceivePackSideBand(HttpServletRequest req)
isUploadPackback to summary
public static boolean isUploadPack(String pathOrUri)

Check if the HTTP request path ends with the /git-upload-pack handler.

Parameters
pathOrUri:String

path or URI of the request.

Returns:boolean

true if the request is for the /git-upload-pack handler.

isUploadPackback to summary
public static boolean isUploadPack(HttpServletRequest req)

Check if the HTTP request was for the /git-upload-pack Git handler.

Parameters
req:HttpServletRequest

current request.

Returns:boolean

true if the request is for the /git-upload-pack handler.

Since
7.0
sendback to summary
private static void send(HttpServletRequest req, HttpServletResponse res, String type, byte[] buf, int httpStatus) throws IOException
sendErrorback to summary
public static void sendError(HttpServletRequest req, 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:HttpServletRequest

current request.

res:HttpServletResponse

current response.

httpStatus:int

HTTP status code to set if the client is not a Git client.

Exceptions
IOException:
the response cannot be sent.
Since
7.0
sendErrorback to summary
public static void sendError(HttpServletRequest req, 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 org.eclipse.jgit.transport.UploadPack#upload(java.io.InputStream, OutputStream, OutputStream) or org.eclipse.jgit.transport.ReceivePack#receive(java.io.InputStream, OutputStream, OutputStream).

Parameters
req:HttpServletRequest

current request.

res:HttpServletResponse

current response.

httpStatus:int

HTTP status code to set if the client is not a Git client.

textForGit:String

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.

Exceptions
IOException:
the response cannot be sent.
Since
7.0
sendInfoRefsErrorback to summary
private static void sendInfoRefsError(HttpServletRequest req, HttpServletResponse res, String textForGit, int httpStatus) throws IOException
sendReceivePackErrorback to summary
private static void sendReceivePackError(HttpServletRequest req, HttpServletResponse res, String textForGit, int httpStatus) throws IOException
sendUploadPackErrorback to summary
private static void sendUploadPackError(HttpServletRequest req, HttpServletResponse res, String textForGit, int httpStatus) throws IOException
stripServiceSuffixback to summary
public static String stripServiceSuffix(String path)

Strip the Git service suffix from a request path. Generally the suffix is stripped by the SuffixPipeline handling the request, so this method is rarely needed.

Parameters
path:String

the path of the request.

Returns:String

the path up to the last path component before the service suffix; the path as-is if it contains no service suffix.

writePacketback to summary
private static void writePacket(PacketLineOut pckOut, String textForGit) throws IOException
writeSideBandback to summary
private static void writeSideBand(OutputStream out, String textForGit) throws IOException