2 * Copyright (C) 2009-2010, Google Inc. and others
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
8 * SPDX-License-Identifier: BSD-3-Clause
11 package org.eclipse.jgit.http.server.resolver;
13 import java.util.Arrays;
15 import javax.servlet.http.HttpServletRequest;
17 import org.eclipse.jgit.lib.Config;
18 import org.eclipse.jgit.lib.Repository;
19 import org.eclipse.jgit.transport.UploadPack;
20 import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
21 import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
22 import org.eclipse.jgit.transport.resolver.UploadPackFactory;
25 * Create and configure {@link org.eclipse.jgit.transport.UploadPack} service
28 * Reading by upload-pack is permitted unless {@code http.uploadpack} is
29 * explicitly set to false.
31 public class DefaultUploadPackFactory implements
32 UploadPackFactory<HttpServletRequest> {
33 private static class ServiceConfig {
34 final boolean enabled;
36 ServiceConfig(Config cfg) {
37 enabled = cfg.getBoolean("http", "uploadpack", true);
43 public UploadPack create(HttpServletRequest req, Repository db)
44 throws ServiceNotEnabledException, ServiceNotAuthorizedException {
45 if (db.getConfig().get(ServiceConfig::new).enabled) {
46 UploadPack up = new UploadPack(db);
47 String header = req.getHeader("Git-Protocol"); //$NON-NLS-1$
49 String[] params = header.split(":"); //$NON-NLS-1$
50 up.setExtraParameters(Arrays.asList(params));
54 throw new ServiceNotEnabledException();