summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.server
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2012-09-22 19:53:52 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2012-09-22 19:53:52 -0400
commiteb5b506acdd22c3e5d97d9b3efaf978659ef07f4 (patch)
tree1df0f88e8b14a005088a832295e92261a62d37d1 /org.eclipse.jgit.http.server
parentc3f1fac03fdf3ed5165adfd22aa14a21e5876892 (diff)
parentb3e8f29fe9f578e11ad322c94a4bd2dd6cfb6eb0 (diff)
downloadjgit-eb5b506acdd22c3e5d97d9b3efaf978659ef07f4.tar.gz
jgit-eb5b506acdd22c3e5d97d9b3efaf978659ef07f4.zip
Merge changes Ic2b78ba9,Ia13e63ed
* changes: Use '406 Not Acceptable' when info/refs is disabled Compress large /info/refs responses on HTTP
Diffstat (limited to 'org.eclipse.jgit.http.server')
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java3
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java15
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java2
6 files changed, 17 insertions, 9 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java
index 980d246d2d..529b8391fa 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java
@@ -225,7 +225,7 @@ public class GitFilter extends MetaFilter {
refs = refs.through(new AsIsFileFilter(asIs));
refs.with(new InfoRefsServlet());
} else
- refs.with(new ErrorServlet(HttpServletResponse.SC_FORBIDDEN));
+ refs.with(new ErrorServlet(HttpServletResponse.SC_NOT_ACCEPTABLE));
if (asIs != AsIsFileService.DISABLED) {
final IsLocalFilter mustBeLocal = new IsLocalFilter();
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java
index ffaa13153c..52f928548b 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java
@@ -72,7 +72,8 @@ class InfoRefsServlet extends HttpServlet {
final Repository db = getRepository(req);
final OutputStreamWriter out = new OutputStreamWriter(
- new SmartOutputStream(req, rsp), Constants.CHARSET);
+ new SmartOutputStream(req, rsp, true),
+ Constants.CHARSET);
final RefAdvertiser adv = new RefAdvertiser() {
@Override
protected void writeOne(final CharSequence line) throws IOException {
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
index 10cadd7bb0..3d6c35b0b6 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
@@ -171,7 +171,7 @@ class ReceivePackServlet extends HttpServlet {
return;
}
- SmartOutputStream out = new SmartOutputStream(req, rsp) {
+ SmartOutputStream out = new SmartOutputStream(req, rsp, true) {
@Override
public void flush() throws IOException {
doFlush();
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
index c39b78900d..145c63bcaf 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
@@ -70,22 +70,29 @@ class SmartOutputStream extends TemporaryBuffer {
private static final int LIMIT = 32 * 1024;
private final HttpServletRequest req;
-
private final HttpServletResponse rsp;
-
+ private boolean compressStream;
private boolean startedOutput;
SmartOutputStream(final HttpServletRequest req,
- final HttpServletResponse rsp) {
+ final HttpServletResponse rsp,
+ boolean compressStream) {
super(LIMIT);
this.req = req;
this.rsp = rsp;
+ this.compressStream = compressStream;
}
@Override
protected OutputStream overflow() throws IOException {
startedOutput = true;
- return rsp.getOutputStream();
+
+ OutputStream out = rsp.getOutputStream();
+ if (compressStream && acceptsGzipEncoding(req)) {
+ rsp.setHeader(HDR_CONTENT_ENCODING, ENCODING_GZIP);
+ out = new GZIPOutputStream(out);
+ }
+ return out;
}
public void close() throws IOException {
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java
index 907b328db9..4810753779 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java
@@ -122,7 +122,7 @@ abstract class SmartServiceInfoRefs implements Filter {
throws IOException {
final HttpServletRequest req = (HttpServletRequest) request;
final HttpServletResponse res = (HttpServletResponse) response;
- final SmartOutputStream buf = new SmartOutputStream(req, res);
+ final SmartOutputStream buf = new SmartOutputStream(req, res, true);
try {
res.setContentType(infoRefsResultType(svc));
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
index 046db45766..c5272b55eb 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
@@ -172,7 +172,7 @@ class UploadPackServlet extends HttpServlet {
return;
}
- SmartOutputStream out = new SmartOutputStream(req, rsp) {
+ SmartOutputStream out = new SmartOutputStream(req, rsp, false) {
@Override
public void flush() throws IOException {
doFlush();
an>slackHook, SlackMeta{ Channel: "foo", Username: "username", Color: "blue", }) } func TestWebhook_History(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) webhook := AssertExistsAndLoadBean(t, &Webhook{ID: 1}).(*Webhook) tasks, err := webhook.History(0) assert.NoError(t, err) if assert.Len(t, tasks, 1) { assert.Equal(t, int64(1), tasks[0].ID) } webhook = AssertExistsAndLoadBean(t, &Webhook{ID: 2}).(*Webhook) tasks, err = webhook.History(0) assert.NoError(t, err) assert.Len(t, tasks, 0) } func TestWebhook_UpdateEvent(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) webhook := AssertExistsAndLoadBean(t, &Webhook{ID: 1}).(*Webhook) hookEvent := &HookEvent{ PushOnly: true, SendEverything: false, ChooseEvents: false, HookEvents: HookEvents{ Create: false, Push: true, PullRequest: false, }, } webhook.HookEvent = hookEvent assert.NoError(t, webhook.UpdateEvent()) assert.NotEmpty(t, webhook.Events) actualHookEvent := &HookEvent{} assert.NoError(t, json.Unmarshal([]byte(webhook.Events), actualHookEvent)) assert.Equal(t, *hookEvent, *actualHookEvent) } func TestWebhook_EventsArray(t *testing.T) { assert.Equal(t, []string{"create", "push", "pull_request"}, (&Webhook{ HookEvent: &HookEvent{SendEverything: true}, }).EventsArray(), ) assert.Equal(t, []string{"push"}, (&Webhook{ HookEvent: &HookEvent{PushOnly: true}, }).EventsArray(), ) } func TestCreateWebhook(t *testing.T) { hook := &Webhook{ RepoID: 3, URL: "www.example.com/unit_test", ContentType: ContentTypeJSON, Events: `{"push_only":false,"send_everything":false,"choose_events":false,"events":{"create":false,"push":true,"pull_request":true}}`, } AssertNotExistsBean(t, hook) assert.NoError(t, CreateWebhook(hook)) AssertExistsAndLoadBean(t, hook) } func TestGetWebhookByRepoID(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hook, err := GetWebhookByRepoID(1, 1) assert.NoError(t, err) assert.Equal(t, int64(1), hook.ID) _, err = GetWebhookByRepoID(NonexistentID, NonexistentID) assert.Error(t, err) assert.True(t, IsErrWebhookNotExist(err)) } func TestGetWebhookByOrgID(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hook, err := GetWebhookByOrgID(3, 3) assert.NoError(t, err) assert.Equal(t, int64(3), hook.ID) _, err = GetWebhookByOrgID(NonexistentID, NonexistentID) assert.Error(t, err) assert.True(t, IsErrWebhookNotExist(err)) } func TestGetActiveWebhooksByRepoID(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hooks, err := GetActiveWebhooksByRepoID(1) assert.NoError(t, err) if assert.Len(t, hooks, 1) { assert.Equal(t, int64(1), hooks[0].ID) assert.True(t, hooks[0].IsActive) } } func TestGetWebhooksByRepoID(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hooks, err := GetWebhooksByRepoID(1) assert.NoError(t, err) if assert.Len(t, hooks, 2) { assert.Equal(t, int64(1), hooks[0].ID) assert.Equal(t, int64(2), hooks[1].ID) } } func TestGetActiveWebhooksByOrgID(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hooks, err := GetActiveWebhooksByOrgID(3) assert.NoError(t, err) if assert.Len(t, hooks, 1) { assert.Equal(t, int64(3), hooks[0].ID) assert.True(t, hooks[0].IsActive) } } func TestGetWebhooksByOrgID(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hooks, err := GetWebhooksByOrgID(3) assert.NoError(t, err) if assert.Len(t, hooks, 1) { assert.Equal(t, int64(3), hooks[0].ID) assert.True(t, hooks[0].IsActive) } } func TestUpdateWebhook(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hook := AssertExistsAndLoadBean(t, &Webhook{ID: 2}).(*Webhook) hook.IsActive = true hook.ContentType = ContentTypeForm AssertNotExistsBean(t, hook) assert.NoError(t, UpdateWebhook(hook)) AssertExistsAndLoadBean(t, hook) } func TestDeleteWebhookByRepoID(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) AssertExistsAndLoadBean(t, &Webhook{ID: 2, RepoID: 1}) assert.NoError(t, DeleteWebhookByRepoID(1, 2)) AssertNotExistsBean(t, &Webhook{ID: 2, RepoID: 1}) err := DeleteWebhookByRepoID(NonexistentID, NonexistentID) assert.Error(t, err) assert.True(t, IsErrWebhookNotExist(err)) } func TestDeleteWebhookByOrgID(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) AssertExistsAndLoadBean(t, &Webhook{ID: 3, OrgID: 3}) assert.NoError(t, DeleteWebhookByOrgID(3, 3)) AssertNotExistsBean(t, &Webhook{ID: 3, OrgID: 3}) err := DeleteWebhookByOrgID(NonexistentID, NonexistentID) assert.Error(t, err) assert.True(t, IsErrWebhookNotExist(err)) } func TestToHookTaskType(t *testing.T) { assert.Equal(t, GOGS, ToHookTaskType("gogs")) assert.Equal(t, SLACK, ToHookTaskType("slack")) assert.Equal(t, GITEA, ToHookTaskType("gitea")) } func TestHookTaskType_Name(t *testing.T) { assert.Equal(t, "gogs", GOGS.Name()) assert.Equal(t, "slack", SLACK.Name()) assert.Equal(t, "gitea", GITEA.Name()) } func TestIsValidHookTaskType(t *testing.T) { assert.True(t, IsValidHookTaskType("gogs")) assert.True(t, IsValidHookTaskType("slack")) assert.True(t, IsValidHookTaskType("gitea")) assert.False(t, IsValidHookTaskType("invalid")) } func TestHookTasks(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hookTasks, err := HookTasks(1, 1) assert.NoError(t, err) if assert.Len(t, hookTasks, 1) { assert.Equal(t, int64(1), hookTasks[0].ID) } hookTasks, err = HookTasks(NonexistentID, 1) assert.NoError(t, err) assert.Len(t, hookTasks, 0) } func TestCreateHookTask(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hookTask := &HookTask{ RepoID: 3, HookID: 3, Type: GITEA, URL: "http://www.example.com/unit_test", Payloader: &api.PushPayload{}, } AssertNotExistsBean(t, hookTask) assert.NoError(t, CreateHookTask(hookTask)) AssertExistsAndLoadBean(t, hookTask) } func TestUpdateHookTask(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) hook := AssertExistsAndLoadBean(t, &HookTask{ID: 1}).(*HookTask) hook.PayloadContent = "new payload content" hook.DeliveredString = "new delivered string" hook.IsDelivered = true AssertNotExistsBean(t, hook) assert.NoError(t, UpdateHookTask(hook)) AssertExistsAndLoadBean(t, hook) } func TestPrepareWebhooks(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) hookTasks := []*HookTask{ {RepoID: repo.ID, HookID: 1, EventType: HookEventPush}, } for _, hookTask := range hookTasks { AssertNotExistsBean(t, hookTask) } assert.NoError(t, PrepareWebhooks(repo, HookEventPush, &api.PushPayload{})) for _, hookTask := range hookTasks { AssertExistsAndLoadBean(t, hookTask) } } // TODO TestHookTask_deliver // TODO TestDeliverHooks