Give info/refs services more control over response
Currently, SmartServiceInfoRefs always prints "# service=serviceName" followed by a flush packet in response to an info/refs request, and then hands it off to the specific service class. Printing of "# service=serviceName" is mandated for protocol v0, but not v2. Therefore, the existing code works for protocol v0, but whenever a service that supports protocol v2 receives an info/refs request, it must first determine which protocol version is to be used (depending on, for example, the request and any relevant configuration variables), and then decide if "# service=serviceName" needs to be printed. Create a new method that v2-supporting service classes can override, covering the printing of both "# service=serviceName" and everything that the #advertise method prints. This will be used in a subsequent commit in which UploadPackServlet (and the other classes it uses) is updated to support protocol v2. Change-Id: Ia026b06e96a6b15937514096babd024ef77df1ea Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com>
This commit is contained in:
parent
36a8c21069
commit
c32a62cd4a
|
@ -133,9 +133,7 @@ private void service(ServletRequest request, ServletResponse response)
|
|||
res.setContentType(infoRefsResultType(svc));
|
||||
|
||||
final PacketLineOut out = new PacketLineOut(buf);
|
||||
out.writeString("# service=" + svc + "\n");
|
||||
out.end();
|
||||
advertise(req, new PacketLineOutRefAdvertiser(out));
|
||||
respond(req, out, svc);
|
||||
buf.close();
|
||||
} catch (ServiceNotAuthorizedException e) {
|
||||
res.sendError(SC_UNAUTHORIZED, e.getMessage());
|
||||
|
@ -178,6 +176,37 @@ protected abstract void advertise(HttpServletRequest req,
|
|||
PacketLineOutRefAdvertiser pck) throws IOException,
|
||||
ServiceNotEnabledException, ServiceNotAuthorizedException;
|
||||
|
||||
/**
|
||||
* Writes the appropriate response to an info/refs request received by
|
||||
* a smart service. In protocol v0, this starts with "#
|
||||
* service=serviceName" followed by a flush packet, but this is not
|
||||
* necessarily the case in other protocol versions.
|
||||
* <p>
|
||||
* The default implementation writes "# service=serviceName" and a
|
||||
* flush packet, then calls {@link #advertise}. Subclasses should
|
||||
* override this method if they support protocol versions other than
|
||||
* protocol v0.
|
||||
*
|
||||
* @param req
|
||||
* request
|
||||
* @param pckOut
|
||||
* destination of response
|
||||
* @param serviceName
|
||||
* service name to be written out in protocol v0; may or may
|
||||
* not be used in other versions
|
||||
* @throws IOException
|
||||
* @throws ServiceNotEnabledException
|
||||
* @throws ServiceNotAuthorizedException
|
||||
*/
|
||||
protected void respond(HttpServletRequest req,
|
||||
PacketLineOut pckOut, String serviceName)
|
||||
throws IOException, ServiceNotEnabledException,
|
||||
ServiceNotAuthorizedException {
|
||||
pckOut.writeString("# service=" + svc + '\n'); //$NON-NLS-1$
|
||||
pckOut.end();
|
||||
advertise(req, new PacketLineOutRefAdvertiser(pckOut));
|
||||
}
|
||||
|
||||
private class Chain implements FilterChain {
|
||||
private int filterIdx;
|
||||
|
||||
|
|
Loading…
Reference in New Issue