aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.server/src
Commit message (Collapse)AuthorAgeFilesLines
* Add protocol v2 support in httpJonathan Tan2018-06-042-3/+32
| | | | | | | | | | | Teach UploadPack to support protocol v2 with non-bidirectional pipes, and add support to the HTTP protocol for v2. This is only activated if the repository's config has "protocol.version" equal to 2. Change-Id: I093a14acd2c3850b8b98e14936a716958f35a848 Helped-by: Matthias Sohn <matthias.sohn@sap.com> Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com>
* Give info/refs services more control over responseJonathan Tan2018-06-041-3/+32
| | | | | | | | | | | | | | | | | | | | | | | 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>
* InfoRefsServlet: Refactor to not use deprecated methodsDavid Pursehouse2018-05-211-7/+1
| | | | | | | | | - Replace RefDatabase#getRefs(String) with #getRefsByPrefix(String) - Replace RefAdvertiser#send(Map<String, Ref>) with #send(Collection<Ref>) Bug: 534731 Change-Id: I25b617c3b0c54793cf4ab5b62f002e17745a5377 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* Remove further unnecessary 'final' keywordsHan-Wen Nienhuys2018-05-1812-20/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove it from * package private functions. * try blocks * for loops this was done with the following python script: $ cat f.py import sys import re import os def replaceFinal(m): return m.group(1) + "(" + m.group(2).replace('final ', '') + ")" methodDecl = re.compile(r"^([\t ]*[a-zA-Z_ ]+)\(([^)]*)\)") def subst(fn): input = open(fn) os.rename(fn, fn + "~") dest = open(fn, 'w') for l in input: l = methodDecl.sub(replaceFinal, l) dest.write(l) dest.close() for root, dirs, files in os.walk(".", topdown=False): for f in files: if not f.endswith('.java'): continue full = os.path.join(root, f) print full subst(full) Change-Id: If533a75a417594fc893e7c669d2c1f0f6caeb7ca Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
* Remove 'final' in parameter listsHan-Wen Nienhuys2018-05-1513-18/+18
| | | | | Change-Id: Id924f79c8b2c720297ebc49bf9c5d4ddd6d52547 Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
* RepositoryFilter: Refactor doFilter to open Repository in try-with-resourceDavid Pursehouse2018-03-141-8/+3
| | | | | Change-Id: Ic4a056eebe567ff933519d6a805edb7e97c71b22 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* Open auto-closeable resources in try-with-resourceDavid Pursehouse2018-03-132-12/+3
| | | | | | | | | | | | | | | | | | | | When an auto-closeable resources is not opened in try-with-resource, the warning "should be managed by try-with-resource" is emitted by Eclipse. Fix the ones that can be silenced simply by moving the declaration of the variable into a try-with-resource. In cases where we explicitly call the close() method, for example in tests where we are testing specific behavior caused by the close(), suppress the warning. Leave the ones that will require more significant refcactoring to fix. They can be done in separate commits that can be reviewed and tested in isolation. Change-Id: I9682cd20fb15167d3c7f9027cecdc82bc50b83c4 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* InfoRefsServlet: Open OutputStreamWriter in try-with-resourceDavid Pursehouse2018-03-071-21/+22
| | | | | Change-Id: Iaf93d5c020ee67e9effbe93334f1ad419ffaee1f Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* GitSmartHttpTools: Open OutputStream in try-with-resourceDavid Pursehouse2018-03-061-4/+1
| | | | | Change-Id: Ifb50b923f58f73d323cc1492950e58b6dc39f376 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* FileSender: Open OutputStream in try-with-resourceDavid Pursehouse2018-03-061-4/+1
| | | | | Change-Id: I2278950998dffc2b5730a91a5bb3bcc38f4d446b Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* Fix javadoc in org.eclipse.jgit.http.serverMatthias Sohn2017-12-1731-64/+204
| | | | | Change-Id: I732d773b21bbf64285493070964dd9e442eab5d8 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Cleanup: Remove unnecessary $NON-NLS$ tagsMatthias Sohn2017-08-301-1/+1
| | | | Change-Id: I143c9d62b89322509123d4e06a221dd4dc158c55 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Show error message for non-git clientsMasaya Suzuki2017-08-251-1/+1
| | | | | Change-Id: I56435d955348eb9acef6603d868f9add1c8781c9 Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
* Eliminate SectionParser construction boilerplateDave Borowitz2017-08-023-27/+3
| | | | | | | | | Happily, most anonymous SectionParser implementations can be replaced with FooConfig::new, as long as the constructor takes a single Config arg. Many of these, the non-public ones, can in turn be inlined. A few remaining SectionParsers can be lambdas. Change-Id: I3f563e752dfd2007dd3a48d6d313d20e2685943a
* Add missing newlines at ends of Java filesDavid Pursehouse2017-07-251-1/+1
| | | | | Change-Id: Iead36f53d57ead0eb3edd3f9efb63b6630c9c20c Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* Enable and fix warnings about redundant specification of type argumentsDavid Pursehouse2017-02-203-5/+5
| | | | | | | | | | Since the introduction of generic type parameter inference in Java 7, it's not necessary to explicitly specify the type of generic parameters. Enable the warning in Eclipse, and fix all occurrences. Change-Id: I9158caf1beca5e4980b6240ac401f3868520aad0 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* Enable and fix 'Should be tagged with @Override' warningDavid Pursehouse2017-02-1923-0/+62
| | | | | | | | | | | | | | | | | | | | | | | Set missingOverrideAnnotation=warning in Eclipse compiler preferences which enables the warning: The method <method> of type <type> should be tagged with @Override since it actually overrides a superclass method Justification for this warning is described in: http://stackoverflow.com/a/94411/381622 Enabling this causes in excess of 1000 warnings across the entire code-base. They are very easy to fix automatically with Eclipse's "Quick Fix" tool. Fix all of them except 2 which cause compilation failure when the project is built with mvn; add TODO comments on those for further investigation. Change-Id: I5772061041fd361fe93137fd8b0ad356e748a29c Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* dump HTTP: Avoid being confused by Content-Length of a gzipped streamZhen Chen2016-11-221-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | TransportHttp sets 'Accept-Encoding: gzip' to allow the server to compress HTTP responses. When fetching a loose object over HTTP, it uses the following code to read the response: InputStream in = openInputStream(c); int len = c.getContentLength(); return new FileStream(in, len); If the content is gzipped, openInputStream decompresses it and produces the correct content for the object. Unfortunately the Content-Length header contains the length of the compressed stream instead of the actual content length. Use a length of -1 instead since we don't know the actual length. Loose objects are already compressed, so the gzip encoding typically produces a longer compressed payload. The value from the Content-Length is too high, producing EOFException: Short read of block. Change-Id: I8d5284dad608e3abd8217823da2b365e8cd998b0 Signed-off-by: Zhen Chen <czhen@google.com> Helped-by: Jonathan Nieder <jrn@google.com>
* Organize importsDavid Pursehouse2016-11-145-9/+9
| | | | | Change-Id: I7c545d06b1bced678c020fab9af1382bc4416b6e Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* WrappedRequest: Don't use deprecated ServletRequestWrapper#realPathDavid Pursehouse2016-09-221-1/+1
| | | | | Change-Id: I268e66d2299a1a12f7ae44b67a6b947339038245 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* Add HTTP status code to ServiceMayNotContinueExceptionMasaya Suzuki2016-08-233-3/+3
| | | | | | | | The exception can be thrown in a various reason, and sometimes 403 Forbidden is not appropriate. Make the HTTP status code customizable. Change-Id: If2ef6f454f7479158a4e28a12909837db483521c Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
* Report PackProtocolExceptions to client during receive-packDave Borowitz2015-07-091-1/+2
| | | | | | | We have done this since forever with the "wanted old new ref" error, so let's do it for other such errors thrown in the same block as well. Change-Id: Ib3b1c7f05e31a5b3e40e85eb07b16736920a033b
* Use message from ServiceNotAuthorizedException, ServiceNotEnabledExceptionJonathan Nieder2015-06-025-15/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When sending an error response due to ServiceNotAuthorizedException or ServiceNotEnabledException, usually we send a default message. In the ServiceNotEnabledException case, we use 403 Git access forbidden except in a dumb-HTTP-specific filter where we use the servlet container's default 403 response: 403 Forbidden In the ServiceNotAuthorizedException case, we use the servlet container's default 401 response: 401 Unauthorized There is one exception: a ServiceNotEnabledException when handling a smart HTTP /info/refs request uses the message from the exception: 403 Service not enabled Be more consistent by always using the message from the exception. This way, authors of a RepositoryResolver, UploadPackFactory, or ReceivePackFactory can provide a more detailed message when appropriate. The defaults are 401 Unauthorized 403 Service not enabled Change-Id: Id1fe1c2042fb96487c3671c1965c8a65c4b8e1b8 Signed-off-by: Jonathan Nieder <jrn@google.com>
* dumb HTTP: Clarify AsIsFilter by introducing req and res localsJonathan Nieder2015-06-021-3/+5
| | | | | | | No functional change. Change-Id: I945ba18879c360f433e026aa125ef3f9f6a75793 Signed-off-by: Jonathan Nieder <jrn@google.com>
* Replace deprecated release() methods by close()Matthias Sohn2015-05-212-2/+2
| | | | | | | | See the discussion [1] in the Gerrit mailing list. [1] https://groups.google.com/forum/#!topic/repo-discuss/RRQT_xCqz4o Change-Id: I2c67384309c5c2e8511a7d0d4e088b4e95f819ff Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Skip logging stack trace on corrupt objectsShawn Pearce2015-05-062-0/+11
| | | | | | | | | | | | | Instead of dumping a full stack trace when a client sends an invalid commit, record only a short line explaining the attempt: Cannot receive Invalid commit c0ff33...: invalid author into /tmp/jgit.git The text alone is sufficient to explain the problem and the stack trace does not lend any additional useful information. ObjectChecker is quite clear about its rejection cases. Change-Id: Ifc8cf06032489dc6431be1ba66101cf3d4299218
* Add repository name to failures in HTTP server logShawn Pearce2015-05-063-9/+29
| | | | | | | | | If UploadPack or ReceivePack has an exception record an identifier associated with the repository as part of the log message. This can help the HTTP admin track down the offending repository and take action to repair the root cause. Change-Id: I58f22b33cdb40994f044a26fba9fe965b45be51d
* Support agent= capability in wire protocolShawn Pearce2015-04-302-0/+8
| | | | | | | | | | | | | | | | | | Since git-core ff5effd (v1.7.12.1) the native wire protocol transmits the server and client implementation and version strings using capability "agent=git/1.7.12.1" or similar. Support this in JGit and hang the implementation data off UploadPack and ReceivePack. On HTTP transports default to the User-Agent HTTP header until the client overrides this with the optional capability string in the first line. Extract the user agent string into a UserAgent class under transport where it can be specified to a different value if the application's build process has broken the Implementation-Version header in the JGit package. Change-Id: Icfc6524d84a787386d1786310b421b2f92ae9e65
* Clearer error message when service is not enabledHector Oswaldo Caballero2015-04-031-1/+1
| | | | | | | | | | | | | | | | When a user tried to use a service not enabled in the remote server a misleading error message was given: fatal: remote error: Git access forbidden This patch modifies the error message to make the cause clearer to the user. Now, when the user tries to use a not enabled service, the message error clearly states it: fatal: remote error: Service not enabled Change-Id: If096c4ddd17c5aae0e99e3ea6eea4b69bd3c5466 Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
* Revert "Extract path info from requests without decoding"Shawn Pearce2014-12-123-50/+4
| | | | | | | | This reverts commit 19f869996f27adf59ec507e5f565d8b5619576f3. Leaving path info encoded confuses applications like Gitiles. Trying to fix this inside of JGit was maybe the wrong solution. Change-Id: I8df9ab6233ff513e427701c8a1a66022c19784eb
* Extract path info from requests without decodingDavid Pletcher2014-12-093-4/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | Gitiles malfunctions in conjunction with jgit and guice because of a recent Guice bug fix. Work around the problem by parsing the URI directly, bypassing the unescaping performed by the getPathInfo method. This rest of this message is copied from https://gerrit-review.googlesource.com/#/c/60820/ : The fix for Guice issue #745[1] causes getPathInfo() within the GuiceFilter to return decoded values, eliminating the difference between "foo/bar" and "foo%2Fbar". This is in spec with the servlet standard, whose javadoc for getPathInfo[2] states that the return value be "decoded by the web container". Work around this by extracting the path part directly from the request URI, which is unmodified by the container. This is copying the Guice behavior prior to the bugfix. [1] https://github.com/google/guice/issues/745 [2] http://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletRequest.html#getPathInfo() Change-Id: I7fdb291bda377dab6160599ee537962d5f60f1e8 Signed-off-by: David Pletcher <dpletcher@google.com>
* Cleanup javadocs so they pass the java8 doclint checksRobin Rosenberg2014-03-291-1/+1
| | | | | | Bug: 431552 Change-Id: I469316f5645205016e1fa6b0fbd2ff3b509b14bc Signed-off-by: Robin Stocker <robin@nibor.org>
* Extract protocol constants to a common classShawn Pearce2013-11-011-3/+3
| | | | | | This avoids the server from referencing the client code directly. Change-Id: Ie6ade781b5a689646ad8b0b2988ef2b544412195
* Propagate IOException where possible when getting refs.Colby Ranger2013-10-071-1/+2
| | | | | | | | | | Currently, Repository.getAllRefs() and Repository.getTags() silently ignores an IOException and instead returns an empty map. Repository is a public API and as such cannot be changed until the next major revision change. Where possible, update the internal jgit APIs to use the RefDatabase directly, since it propagates the error. Change-Id: I4e4537d8bd0fa772f388262684c5c4ca1929dc4c
* JGit 3.0: move internal classes into an internal subpackageShawn Pearce2013-03-183-4/+4
| | | | | | | | This breaks all existing callers once. Applications are not supposed to build against the internal storage API unless they can accept API churn and make necessary updates as versions change. Change-Id: I2ab1327c202ef2003565e1b0770a583970e432e9
* Declare essentially static methods as staticRobin Rosenberg2012-12-271-1/+1
| | | | Change-Id: I83ca25fb569c0dbc36eb374d5437fcf2b65a6f68
* Add type argumente to some raw reclarationRobin Rosenberg2012-12-273-3/+3
| | | | Change-Id: Ief195fb5c55f75172f0428fdac8c8874292ae566
* Disable response compression on /git-receive-pack URLsShawn Pearce2012-12-071-1/+1
| | | | | | | | | | | | Compressing the response with gzip causes the stream to delay flushing until gzip has seen the entire response message, or buffers fill up and the compressed data has to be sent. This hides the resolving progress monitor from the client, as well as any other progress messages the server might be trying to send. Disable compression in receive, matching what /git-upload-pack has. Change-Id: Ic8d8abe1f43c3f540d1ee7c43a8947a555307d94
* Make an exception for the formatting rules (turn off) for some filesRobin Rosenberg2012-11-161-0/+1
| | | | | | | | | | Our rule to enforce javodocs for public members gives us a problem because there are some patterns where javadoc make little sense so we make the comments as small as possible, which our formatting rules do not like, so disable it for those source files. Change-Id: I6e3edb1e650ed45428b89cf41e6151b6536bca8a Signed-off-by: Chris Aniszczyk <zx@twitter.com>
* Suppress resource warnings with Java 7Robin Rosenberg2012-10-251-0/+1
| | | | | | | | | | | For streams that should not be closed, i.e. don't own an underlying stream, and in-memory streams that do not need to be closed we just suppress the warning. This mostly apply to test cases. GC is enough. For streams with external resources (i.e. files) we add the necessary call to close(). Change-Id: I4d883ba2e7d07f199fe57ccb3459ece00441a570
* Remove unnecessary @SuppressWarningsRobin Rosenberg2012-09-231-1/+0
| | | | Change-Id: Ic7b8494713d59574ee8f064a5c1042b48aedf012
* Merge changes Ic2b78ba9,Ia13e63edShawn O. Pearce2012-09-226-9/+17
|\ | | | | | | | | | | * changes: Use '406 Not Acceptable' when info/refs is disabled Compress large /info/refs responses on HTTP
| * Use '406 Not Acceptable' when info/refs is disabledShawn O. Pearce2012-09-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of a confusing 403 Forbidden error indicating the dumb file service is disabled on this server, use 406 Not Acceptable to mean the client sent a request for content (the plain info/refs file) that this server does not want to provide. The stock C Git client will report HTTP 406 error if it predates 1.6.6 or something goes wrong with the smart request and it tried falling back to the dumb request. This may help to debug cases where a broken proxy server exists between the client and the server and has mangled a prior smart info/refs response. Change-Id: Ic2b78ba9502e4bbdff7cc3ba1fd284cf7616412b
| * Compress large /info/refs responses on HTTPShawn O. Pearce2012-09-195-8/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Enable streaming compression for any response that is bigger than the 32 KiB buffer used by SmartOutputStream. This is useful on the info/refs file which can have many branches and tags listed, and is often bigger than 32 KiB, but also compresses by at least 50%. Disable streaming compression on large git-upload-pack responses, as these are usually highly compressed Git pack data. Trying to compress these with gzip will only waste CPU time and additional transfer space with the gzip wrapper. Small git-upload-pack data is usually text based negotiation responses and can be squeezed smaller with a little bit of CPU usage. Change-Id: Ia13e63ed334f594d5e1ab53a97240eb2e8f550e2
* | Suppress boxing warnings where we know they are okRobin Rosenberg2012-09-221-2/+7
|/ | | | | | | | | Invoke the wrapper types' valueOf via static imports. For booleans used in asserts, add a new assert in the JUnit utility package since out current version of JUnit does not have the assert(boolean, boolean) method. Change-Id: I9099bd8efbc8c133479344d51ce7dabed8958a2b
* Work around smart HTTP bugs in C GitShawn O. Pearce2012-06-275-1/+229
| | | | | | | | | | | | | | | I have unfortunately introduced a few bugs in the native Git client over the years. 1.7.5 is unable to send chunked requests correctly, resulting in corrupt data at the server. Ban this client whenever it uses chunked encoding with an error message. Prior to some more recent versions, git push over HTTP failed to report status information and error messages due to a race within the client and its helper process. Check for these bad versions and send errors as messages before the status report, enabling users to see the failures on their terminal. Change-Id: Ic62d6591cbd851d21dbb3e9b023d655eaecb0624
* Serve 403 from RepositoryFilter on ServiceMayNotContinueExceptionDave Borowitz2012-06-201-1/+1
| | | | | | | | | | This has no effect on Git clients, but for browsers, 403 Forbidden may be more appropriate. 500 Internal Server Error implies that there is a problem with the server, whereas ServiceMayNotContinueException is specifically intended to cover cases where the server is functioning correctly but has determined that the request may not proceed. Change-Id: I825abd2a029d372060103655eabf488a0547c1e8
* Add MetaFilter.serveRegex(Pattern)Dave Borowitz2012-06-082-0/+16
| | | | | | | This allows the use of precompiled patterns, such as those compiled with flags. Change-Id: I1c87fea98e246004aecbae3aabaf1d21fbf3176e
* Expand RegexPipeline documentationDave Borowitz2012-06-081-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | Include some behaviors that were not clear to me until I had used it a few times. Warn about broken behavior for capture groups that do not match. It would be nice to support these, but even for the cases where it's clear what the behavior should be, it would be infeasible to implement. For example, consider the second group of the regex "(/a)/b(/c)?" matched against the path "/a/b". We might want getServletPath() to return "/a/b" and getPathInfo() to return null, but this is hard to implement: there's no easy way to say "the substring up to the point where (/c) would have matched if it were in the string even though it's not." And even if we could, it's not clear there is even a right answer in the general case. Moreover, ideally we could warn about such broken patterns at servlet initialization time, rather than at runtime, but even answering the question of whether there are capture groups that might not match requires more customized regular expression parsing than we want to embark on. Hence, the best we can do is document how it fails. Change-Id: I7bd5011f5bd387f9345a0e79b22a4d7ed918a190
* Allow RepositoryResolver to throw ServiceMayNotContinueExceptionDave Borowitz2012-03-261-0/+4
| | | | | | | | | | | | Implementations may want to send an error message to the user, which doesn't really fit with any of the existing exception types. ServiceMayNotContinueException, on the other hand, is documented as always containing a user-visible error string, so use that. Modify the git and HTTP transport mechanisms to properly relay this message to the end user. Change-Id: I362e67ea46102a145bf2c6284d38788537c9735f