Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5958847
Issue #3806 async sendError
gregw Jul 3, 2019
6c49a5d
Issue #3806 async sendError
gregw Jul 3, 2019
f3a18bc
Issue #3806 async sendError
gregw Jul 3, 2019
9d3ae2d
Merge branch 'jetty-9.4.x' into jetty-9.4.x-3806-async-sendError
gregw Jul 5, 2019
c6b2919
updates from review
gregw Jul 5, 2019
f8c87ff
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-38…
gregw Jul 7, 2019
fe6eb47
better tests
gregw Jul 7, 2019
cdad73d
revert ignore complete
gregw Jul 9, 2019
267d2a4
added some TODOs
gregw Jul 10, 2019
1e53ef0
more TODOs
gregw Jul 11, 2019
6008878
fixed rename
gregw Jul 11, 2019
c77f0cb
cleanup ISE and more TODOs
gregw Jul 11, 2019
d6cfc3a
refactored to call sendError for uncaught exceptions rather than onError
gregw Jul 11, 2019
1f1e684
more of the refactor
gregw Jul 11, 2019
53aa9fe
extra tests for sendError from completing state
gregw Jul 12, 2019
d03496c
Issue #3806 async sendError
gregw Jul 17, 2019
ae71b99
Issue #3806 async sendError
gregw Jul 17, 2019
72ffe69
Issue #3806 async sendError
gregw Jul 17, 2019
0b0f19a
Issue #3806 async sendError
gregw Jul 18, 2019
72474d8
Issue #3806 async sendError
gregw Jul 18, 2019
ab7f8e7
Issue #3806 async sendError
gregw Jul 18, 2019
904a20a
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-38…
gregw Jul 18, 2019
8f1ec06
Issue #3806 async sendError
gregw Jul 19, 2019
fb6680f
Issue #3806 async sendError
gregw Jul 19, 2019
f02ce73
Issue #3806 async sendError
gregw Jul 19, 2019
3d3a4ab
Issue #3806 async sendError
gregw Jul 20, 2019
61856eb
Fixed javadoc
gregw Jul 22, 2019
702967d
Fixed Javadoc
gregw Jul 22, 2019
802b692
Issue #3806 async sendError
gregw Jul 25, 2019
f1080a3
Issue #3806 async sendError
gregw Jul 25, 2019
5a21a9d
fixed gzipHandlerTest
gregw Jul 25, 2019
6d9202f
Issue #3806 async sendError
gregw Jul 26, 2019
e448047
Issue #3806 async sendError
gregw Jul 27, 2019
4367f7e
Issue #3806 async sendError
gregw Jul 27, 2019
3c6cf8c
more test fixes
gregw Jul 27, 2019
455eabf
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-38…
gregw Jul 27, 2019
2558aac
Issue #3806 async sendError
gregw Jul 27, 2019
890f59c
Issue #3804 CDI integration
gregw Jul 27, 2019
ca5a07a
Issue #3804 CDI integration
gregw Jul 27, 2019
001e219
Issue #3806 async sendError
gregw Jul 27, 2019
f6ef8ac
Issue #3806 async sendError
gregw Jul 29, 2019
ed3ba54
Issue #3806 async sendError
gregw Jul 29, 2019
b715f2d
Issue #3806 async sendError
gregw Jul 30, 2019
1630ef2
Simplified name of states
gregw Jul 31, 2019
4297934
Cleanups and javadoc
gregw Aug 1, 2019
07203c3
Cleanups and javadoc
gregw Aug 1, 2019
c94e8b6
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-38…
gregw Aug 1, 2019
03698dc
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-38…
gregw Aug 2, 2019
d17b975
remove snake case
gregw Aug 2, 2019
525e294
feedback from review
gregw Aug 2, 2019
d70098e
Write error page into fixed pooled buffer
gregw Aug 3, 2019
48e6289
More test fixes for different error page format
gregw Aug 3, 2019
3a9ce47
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-38…
gregw Aug 3, 2019
64e7276
minor cleanups
gregw Aug 4, 2019
56e19ba
Cleanup from Review
gregw Aug 5, 2019
cbce985
cleanups and simplifications
gregw Aug 5, 2019
e735222
Cleanup from Review
gregw Aug 5, 2019
73ca477
Cleanup from Review
gregw Aug 5, 2019
3873cd2
Cleanup from Review
gregw Aug 6, 2019
0d7cd74
fixed debug
gregw Aug 7, 2019
aaaa71e
Cleanup from Review
gregw Aug 7, 2019
dec09a4
Merge branch 'jetty-9.4.x' into jetty-9.4.x-3806-async-sendError-full…
gregw Aug 13, 2019
da5eb1e
removed unnecessary optimisation
gregw Aug 13, 2019
3ad170e
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-38…
gregw Aug 21, 2019
98f6296
fixed duplicate from merge
gregw Aug 21, 2019
c62add8
Updates from review
gregw Aug 22, 2019
88d0e00
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-38…
gregw Aug 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions jetty-http/src/main/java/org/eclipse/jetty/http/HttpStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,20 @@ public static String getMessage(int code)
}
}

public static boolean hasNoBody(int status)
{
switch (status)
{
case NO_CONTENT_204:
case NOT_MODIFIED_304:
case PARTIAL_CONTENT_206:
return true;

default:
return status < OK_200;
}
}

/**
* Simple test against an code to determine if it falls into the
* <code>Informational</code> message category as defined in the <a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.io;

import java.io.OutputStream;
import java.nio.ByteBuffer;

import org.eclipse.jetty.util.BufferUtil;

/**
* Simple wrapper of a ByteBuffer as an OutputStream.
* The buffer does not grow and this class will throw an
* {@link java.nio.BufferOverflowException} if the buffer capacity is exceeded.
*/
public class ByteBufferOutputStream extends OutputStream
{
final ByteBuffer _buffer;

public ByteBufferOutputStream(ByteBuffer buffer)
{
_buffer = buffer;
}

public void close()
{
}

public void flush()
{
}

public void write(byte[] b)
{
write(b, 0, b.length);
}

public void write(byte[] b, int off, int len)
{
BufferUtil.append(_buffer, b, off, len);
}

public void write(int b)
{
BufferUtil.append(_buffer, (byte)b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,14 @@ protected void sendProxyResponseError(HttpServletRequest clientRequest, HttpServ
catch (Exception e)
{
_log.ignore(e);
try
{
proxyResponse.sendError(-1);
}
catch (Exception e2)
{
_log.ignore(e2);
}
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.annotation.Name;

/**
Expand Down Expand Up @@ -79,11 +81,20 @@ public String apply(String target, HttpServletRequest request, HttpServletRespon
// status code 400 and up are error codes
if (code >= 400)
{
response.sendError(code, _reason);
if (!StringUtil.isBlank(_reason))
{
// use both setStatusWithReason (to set the reason) and sendError to set the message
Request.getBaseRequest(request).getResponse().setStatusWithReason(code, _reason);
response.sendError(code, _reason);
}
else
{
response.sendError(code);
}
}
else
{
response.setStatus(code);
response.setStatus(code, _reason);
}
return target;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
Expand Down Expand Up @@ -88,7 +90,13 @@ public String matchAndApply(String target, HttpServletRequest request, HttpServl
// status code 400 and up are error codes so include a reason
if (code >= 400)
{
response.sendError(code, _reason);
if (StringUtil.isBlank(_reason))
response.sendError(code);
else
{
Request.getBaseRequest(request).getResponse().setStatusWithReason(code, _reason);
response.sendError(code, _reason);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.IOException;

import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Dispatcher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -59,7 +61,7 @@ public void testStatusCodeWithReason() throws IOException
_rule.apply(null, _request, _response);

assertEquals(i, _response.getStatus());
assertEquals(null, _response.getReason());
assertEquals("reason" + i, _response.getReason());
}
}

Expand All @@ -72,7 +74,7 @@ public void testErrorStatusNoReason() throws IOException
_rule.apply(null, _request, _response);

assertEquals(i, _response.getStatus());
assertEquals("", _response.getReason());
assertEquals(HttpStatus.getMessage(i), _request.getAttribute(Dispatcher.ERROR_MESSAGE));
super.reset();
}
}
Expand All @@ -87,7 +89,7 @@ public void testErrorStatusWithReason() throws IOException
_rule.apply(null, _request, _response);

assertEquals(i, _response.getStatus());
assertEquals("reason-" + i, _response.getReason());
assertEquals("reason-" + i, _request.getAttribute(Dispatcher.ERROR_MESSAGE));
super.reset();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -321,7 +322,8 @@ public void testBasic() throws Exception
response = _connector.getResponse("POST /ctx/acme/wholesale/index.html HTTP/1.0\r\n" +
"Authorization: Basic " + encodedChris + "\r\n" +
"\r\n");
assertThat(response, startsWith("HTTP/1.1 403 !"));
assertThat(response, startsWith("HTTP/1.1 403 Forbidden"));
assertThat(response, containsString("!Secure"));

//a user in role HOMEOWNER can do a GET
response = _connector.getResponse("GET /ctx/acme/retail/index.html HTTP/1.0\r\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.eclipse.jetty.security.authentication;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.HttpFields;
Expand All @@ -26,6 +27,7 @@
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.server.Authentication;
import org.eclipse.jetty.server.HttpChannel;
import org.eclipse.jetty.server.HttpChannelState;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpOutput;
import org.eclipse.jetty.server.Request;
Expand All @@ -34,6 +36,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -61,21 +65,27 @@ public Server getServer()
{
return null;
}
};
Request req = new Request(channel, null);
HttpOutput out = new HttpOutput(channel)
{

@Override
public void close()
protected HttpOutput newHttpOutput()
{
return;
return new HttpOutput(this)
{
@Override
public void close() {}

@Override
public void flush() throws IOException {}
};
}
};
Response res = new Response(channel, out);
Request req = channel.getRequest();
Response res = channel.getResponse();
MetaData.Request metadata = new MetaData.Request(new HttpFields());
metadata.setURI(new HttpURI("http://localhost"));
req.setMetaData(metadata);

assertThat(channel.getState().handling(), is(HttpChannelState.Action.DISPATCH));
assertEquals(Authentication.SEND_CONTINUE, _authenticator.validateRequest(req, res, true));
assertEquals(HttpHeader.NEGOTIATE.asString(), res.getHeader(HttpHeader.WWW_AUTHENTICATE.asString()));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, res.getStatus());
Expand All @@ -91,24 +101,30 @@ public Server getServer()
{
return null;
}
};
Request req = new Request(channel, null);
HttpOutput out = new HttpOutput(channel)
{

@Override
public void close()
protected HttpOutput newHttpOutput()
{
return;
return new HttpOutput(this)
{
@Override
public void close() {}

@Override
public void flush() throws IOException {}
};
}
};
Response res = new Response(channel, out);
Request req = channel.getRequest();
Response res = channel.getResponse();
HttpFields http_fields = new HttpFields();
// Create a bogus Authorization header. We don't care about the actual credentials.
http_fields.add(HttpHeader.AUTHORIZATION, "Basic asdf");
MetaData.Request metadata = new MetaData.Request(http_fields);
metadata.setURI(new HttpURI("http://localhost"));
req.setMetaData(metadata);

assertThat(channel.getState().handling(), is(HttpChannelState.Action.DISPATCH));
assertEquals(Authentication.SEND_CONTINUE, _authenticator.validateRequest(req, res, true));
assertEquals(HttpHeader.NEGOTIATE.asString(), res.getHeader(HttpHeader.WWW_AUTHENTICATE.asString()));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, res.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void run()
Scheduler.Task task = _timeoutTask;
_timeoutTask = null;
if (task != null)
_state.getHttpChannel().execute(() -> _state.onTimeout());
_state.timeout();
}

public void addThrowable(Throwable e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class Dispatcher implements RequestDispatcher
{
private static final Logger LOG = Log.getLogger(Dispatcher.class);

public static final String __ERROR_DISPATCH = "org.eclipse.jetty.server.Dispatcher.ERROR";

/**
* Dispatch include attribute names
*/
Expand Down Expand Up @@ -83,15 +81,7 @@ public void forward(ServletRequest request, ServletResponse response) throws Ser

public void error(ServletRequest request, ServletResponse response) throws ServletException, IOException
{
try
{
request.setAttribute(__ERROR_DISPATCH, Boolean.TRUE);
forward(request, response, DispatcherType.ERROR);
}
finally
{
request.setAttribute(__ERROR_DISPATCH, null);
}
forward(request, response, DispatcherType.ERROR);
}

@Override
Expand Down
Loading