public class UploadPack extends Object
Modifier and Type | Class and Description |
---|---|
static class |
UploadPack.AdvertisedRequestValidator
Validator corresponding to
UploadPack.RequestPolicy.ADVERTISED . |
static class |
UploadPack.AnyRequestValidator
Validator corresponding to
UploadPack.RequestPolicy.ANY . |
static class |
UploadPack.FirstLine
Data in the first line of a request, the line itself plus options.
|
static class |
UploadPack.ReachableCommitRequestValidator
Validator corresponding to
UploadPack.RequestPolicy.REACHABLE_COMMIT . |
static class |
UploadPack.ReachableCommitTipRequestValidator
Validator corresponding to
UploadPack.RequestPolicy.REACHABLE_COMMIT_TIP . |
static class |
UploadPack.RequestPolicy
Policy the server uses to validate client requests
|
static interface |
UploadPack.RequestValidator
Validator for client requests.
|
static class |
UploadPack.TipRequestValidator
Validator corresponding to
UploadPack.RequestPolicy.TIP . |
Constructor and Description |
---|
UploadPack(Repository copyFrom)
Create a new pack upload for an open repository.
|
Modifier and Type | Method and Description |
---|---|
Map<String,Ref> |
getAdvertisedRefs()
Get refs which were advertised to the client.
|
AdvertiseRefsHook |
getAdvertiseRefsHook()
Get the hook used while advertising the refs to the client.
|
int |
getDepth()
Returns the clone/fetch depth.
|
OutputStream |
getMessageOutputStream()
Get an underlying stream for sending messages to the client
|
String |
getPeerUserAgent()
Get the user agent of the client.
|
PostUploadHook |
getPostUploadHook()
Get the configured post upload hook.
|
PreUploadHook |
getPreUploadHook()
Get the configured pre upload hook.
|
RefFilter |
getRefFilter()
Get the filter used while advertising the refs to the client.
|
Repository |
getRepository()
Get the repository this upload is reading from.
|
UploadPack.RequestPolicy |
getRequestPolicy()
Get policy used by the service to validate client requests
|
RevWalk |
getRevWalk()
Get the RevWalk instance used by this connection.
|
PackStatistics |
getStatistics()
Get the PackWriter's statistics if a pack was sent to the client.
|
int |
getTimeout()
Get timeout (in seconds) before aborting an IO operation.
|
boolean |
isBiDirectionalPipe()
Whether this class expects a bi-directional pipe opened between the
client and itself.
|
boolean |
isSideBand()
Check whether the client expects a side-band stream.
|
void |
sendAdvertisedRefs(RefAdvertiser adv)
Generate an advertisement of available refs and capabilities.
|
void |
sendAdvertisedRefs(RefAdvertiser adv,
String serviceName)
Generate an advertisement of available refs and capabilities.
|
void |
sendMessage(String what)
Send a message to the client, if it supports receiving them.
|
void |
setAdvertisedRefs(Map<String,Ref> allRefs)
Set the refs advertised by this UploadPack.
|
void |
setAdvertiseRefsHook(AdvertiseRefsHook advertiseRefsHook)
Set the hook used while advertising the refs to the client.
|
void |
setBiDirectionalPipe(boolean twoWay)
Set whether this class will assume the socket is a fully bidirectional
pipe between the two peers
|
void |
setExtraParameters(Collection<String> params)
Set the Extra Parameters provided by the client.
|
void |
setPackConfig(PackConfig pc)
Set the configuration used by the pack generator.
|
void |
setPostUploadHook(PostUploadHook hook)
Set the hook for post upload actions (logging, repacking).
|
void |
setPreUploadHook(PreUploadHook hook)
Set the hook that controls how this instance will behave.
|
void |
setRefFilter(RefFilter refFilter)
Set the filter used while advertising the refs to the client.
|
void |
setRequestPolicy(UploadPack.RequestPolicy policy)
Set the policy used to enforce validation of a client's want list.
|
void |
setRequestValidator(UploadPack.RequestValidator validator)
Set custom validator for client want list.
|
void |
setTimeout(int seconds)
Set the timeout before willing to abort an IO call.
|
void |
setTransferConfig(TransferConfig tc)
Set configuration controlling transfer options.
|
void |
upload(InputStream input,
OutputStream output,
OutputStream messages)
Execute the upload task on the socket.
|
public UploadPack(Repository copyFrom)
copyFrom
- the source repository.public final Repository getRepository()
public final RevWalk getRevWalk()
public final Map<String,Ref> getAdvertisedRefs()
setAdvertisedRefs(Map)
has not been called yet.public void setAdvertisedRefs(Map<String,Ref> allRefs)
Intended to be called from a
PreUploadHook
.
allRefs
- explicit set of references to claim as advertised by this
UploadPack instance. This overrides any references that may
exist in the source repository. The map is passed to the
configured getRefFilter()
. If null, assumes all refs
were advertised.public int getTimeout()
public void setTimeout(int seconds)
seconds
- number of seconds to wait (with no data transfer occurring)
before aborting an IO read or write operation with the
connected client.public boolean isBiDirectionalPipe()
public void setBiDirectionalPipe(boolean twoWay)
twoWay
- if true, this class will assume the socket is a fully
bidirectional pipe between the two peers and takes advantage
of that by first transmitting the known refs, then waiting to
read commands. If false, this class assumes it must read the
commands before writing output and does not perform the
initial advertising.public UploadPack.RequestPolicy getRequestPolicy()
public void setRequestPolicy(UploadPack.RequestPolicy policy)
policy
- the policy used to enforce validation of a client's want list.
By default the policy is
UploadPack.RequestPolicy.ADVERTISED
,
which is the Git default requiring clients to only ask for an
object that a reference directly points to. This may be
relaxed to
UploadPack.RequestPolicy.REACHABLE_COMMIT
or
UploadPack.RequestPolicy.REACHABLE_COMMIT_TIP
when callers have setBiDirectionalPipe(boolean)
set
to false. Overrides any policy specified in a
TransferConfig
.public void setRequestValidator(UploadPack.RequestValidator validator)
validator
- custom validator for client want list.public AdvertiseRefsHook getAdvertiseRefsHook()
public RefFilter getRefFilter()
public void setAdvertiseRefsHook(AdvertiseRefsHook advertiseRefsHook)
If the AdvertiseRefsHook
chooses to
call setAdvertisedRefs(Map)
, only refs set by this hook
and selected by the RefFilter
will be shown to the client.
advertiseRefsHook
- the hook; may be null to show all refs.public void setRefFilter(RefFilter refFilter)
Only refs allowed by this filter will be sent to the client. The filter
is run against the refs specified by the
AdvertiseRefsHook
(if applicable). If
null or not set, uses the filter implied by the
TransferConfig
.
refFilter
- the filter; may be null to show all refs.public PreUploadHook getPreUploadHook()
public void setPreUploadHook(PreUploadHook hook)
hook
- the hook; if null no special actions are taken.public PostUploadHook getPostUploadHook()
public void setPostUploadHook(PostUploadHook hook)
hook
- the hook; if null no special actions are taken.public void setPackConfig(PackConfig pc)
pc
- configuration controlling packing parameters. If null the
source repository's settings will be used.public void setTransferConfig(TransferConfig tc)
tc
- configuration controlling transfer options. If null the source
repository's settings will be used.public boolean isSideBand() throws RequestNotYetReadException
RequestNotYetReadException
- if the client's request has not yet been read from the wire, so
we do not know if they expect side-band. Note that the client
may have already written the request, it just has not been
read.public void setExtraParameters(Collection<String> params)
These are parameters passed by the client through a side channel such as the Git-Protocol HTTP header, to allow a client to request a newer response format while remaining compatible with older servers that do not understand different request formats.
params
- parameters supplied by the client, split at colons or NUL
bytes.public void upload(InputStream input, OutputStream output, OutputStream messages) throws IOException
If the client passed extra parameters (e.g., "version=2") through a side channel, the caller must call setExtraParameters first to supply them.
input
- raw input to read client commands from. Caller must ensure the
input is buffered, otherwise read performance may suffer.output
- response back to the Git network client, to write the pack
data onto. Caller must ensure the output is buffered,
otherwise write performance may suffer.messages
- secondary "notice" channel to send additional messages out
through. When run over SSH this should be tied back to the
standard error channel of the command execution. For most
other network connections this should be null.IOException
public PackStatistics getStatistics()
public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException
adv
- the advertisement formatter.IOException
- the formatter failed to write an advertisement.ServiceMayNotContinueException
- the hook denied advertisement.public void sendAdvertisedRefs(RefAdvertiser adv, @Nullable String serviceName) throws IOException, ServiceMayNotContinueException
adv
- the advertisement formatter.serviceName
- if not null, also output "# service=serviceName" followed by a
flush packet before the advertisement. This is required
in v0 of the HTTP protocol, described in Git's
Documentation/technical/http-protocol.txt.IOException
- the formatter failed to write an advertisement.ServiceMayNotContinueException
- the hook denied advertisement.public void sendMessage(String what)
If the client doesn't support receiving messages, the message will be discarded, with no other indication to the caller or to the client.
what
- string describing the problem identified by the hook. The
string must not end with an LF, and must not contain an LF.public OutputStream getMessageOutputStream()
public int getDepth()
public String getPeerUserAgent()
If the client is new enough to use agent=
capability that value
will be returned. Older HTTP clients may also supply their version using
the HTTP User-Agent
header. The capability overrides the HTTP
header if both are available.
When an HTTP request has been received this method returns the HTTP
User-Agent
header value until capabilities have been parsed.
Copyright © 2018 Eclipse JGit Project. All rights reserved.