15e33a1deSShawn O. Pearce /* 2*5c5f7c6bSMatthias Sohn * Copyright (C) 2009-2010, Google Inc. and others 35e33a1deSShawn O. Pearce * 4*5c5f7c6bSMatthias Sohn * This program and the accompanying materials are made available under the 5*5c5f7c6bSMatthias Sohn * terms of the Eclipse Distribution License v. 1.0 which is available at 6*5c5f7c6bSMatthias Sohn * https://www.eclipse.org/org/documents/edl-v10.php. 75e33a1deSShawn O. Pearce * 8*5c5f7c6bSMatthias Sohn * SPDX-License-Identifier: BSD-3-Clause 95e33a1deSShawn O. Pearce */ 105e33a1deSShawn O. Pearce 115e33a1deSShawn O. Pearce package org.eclipse.jgit.http.server; 125e33a1deSShawn O. Pearce 1330c6c754SDavid Pursehouse import static java.nio.charset.StandardCharsets.UTF_8; 145e33a1deSShawn O. Pearce import static org.eclipse.jgit.http.server.ServletUtils.getRepository; 155e33a1deSShawn O. Pearce 165e33a1deSShawn O. Pearce import java.io.IOException; 17c0f09389SShawn O. Pearce import java.io.OutputStreamWriter; 185e33a1deSShawn O. Pearce 195e33a1deSShawn O. Pearce import javax.servlet.http.HttpServlet; 205e33a1deSShawn O. Pearce import javax.servlet.http.HttpServletRequest; 215e33a1deSShawn O. Pearce import javax.servlet.http.HttpServletResponse; 225e33a1deSShawn O. Pearce 235e33a1deSShawn O. Pearce import org.eclipse.jgit.lib.Constants; 245e33a1deSShawn O. Pearce import org.eclipse.jgit.lib.Repository; 255e33a1deSShawn O. Pearce import org.eclipse.jgit.transport.RefAdvertiser; 265e33a1deSShawn O. Pearce import org.eclipse.jgit.util.HttpSupport; 275e33a1deSShawn O. Pearce 285e33a1deSShawn O. Pearce /** Send a complete list of current refs, including peeled values for tags. */ 295e33a1deSShawn O. Pearce class InfoRefsServlet extends HttpServlet { 305e33a1deSShawn O. Pearce private static final long serialVersionUID = 1L; 315e33a1deSShawn O. Pearce 323b00041cSMatthias Sohn /** {@inheritDoc} */ 337ac182f4SDavid Pursehouse @Override doGet(final HttpServletRequest req, final HttpServletResponse rsp)345e33a1deSShawn O. Pearce public void doGet(final HttpServletRequest req, 355e33a1deSShawn O. Pearce final HttpServletResponse rsp) throws IOException { 365e33a1deSShawn O. Pearce // Assume a dumb client and send back the dumb client 375e33a1deSShawn O. Pearce // version of the info/refs file. 385e33a1deSShawn O. Pearce rsp.setContentType(HttpSupport.TEXT_PLAIN); 39fbf6ce65SDavid Pursehouse rsp.setCharacterEncoding(UTF_8.name()); 405e33a1deSShawn O. Pearce 415e33a1deSShawn O. Pearce final Repository db = getRepository(req); 422c5b7211SDavid Pursehouse try (OutputStreamWriter out = new OutputStreamWriter( 43f93a6a72SShawn O. Pearce new SmartOutputStream(req, rsp, true), 4430c6c754SDavid Pursehouse UTF_8)) { 455e33a1deSShawn O. Pearce final RefAdvertiser adv = new RefAdvertiser() { 465e33a1deSShawn O. Pearce @Override 476d370d83SHan-Wen Nienhuys protected void writeOne(CharSequence line) 482c5b7211SDavid Pursehouse throws IOException { 495e33a1deSShawn O. Pearce // Whoever decided that info/refs should use a different 505e33a1deSShawn O. Pearce // delimiter than the native git:// protocol shouldn't 515e33a1deSShawn O. Pearce // be allowed to design this sort of stuff. :-( 525e33a1deSShawn O. Pearce out.append(line.toString().replace(' ', '\t')); 535e33a1deSShawn O. Pearce } 545e33a1deSShawn O. Pearce 555e33a1deSShawn O. Pearce @Override 565e33a1deSShawn O. Pearce protected void end() { 575e33a1deSShawn O. Pearce // No end marker required for info/refs format. 585e33a1deSShawn O. Pearce } 595e33a1deSShawn O. Pearce }; 6004759f32SShawn O. Pearce adv.init(db); 615e33a1deSShawn O. Pearce adv.setDerefTags(true); 62a2b10e56SDavid Pursehouse adv.send(db.getRefDatabase().getRefsByPrefix(Constants.R_REFS)); 632c5b7211SDavid Pursehouse } 645e33a1deSShawn O. Pearce } 655e33a1deSShawn O. Pearce } 66