Skip to content

Commit

Permalink
Fixed tests after merge.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed May 4, 2023
1 parent 3463e42 commit baf7224
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ public boolean isEOF()
public abstract int fillBuffer() throws IOException;
}

public static Input from(String string)
{
return from(BufferUtil.toBuffer(string));
}

public static Input from(ByteBuffer data)
{
return new Input(data.slice())
return new Input(data)
{
@Override
public int fillBuffer()
Expand Down Expand Up @@ -201,16 +206,36 @@ public static Request parseRequest(Input input) throws IOException
return null;
}

public static Response parseHeadResponse(String response)
{
return parseResponse(response, true);
}

public static Response parseResponse(String response)
{
return parseResponse(BufferUtil.toBuffer(response));
return parseResponse(response, false);
}

private static Response parseResponse(String response, boolean head)
{
return parseResponse(BufferUtil.toBuffer(response), head);
}

public static Response parseHeadResponse(ByteBuffer response)
{
return parseResponse(response, true);
}

public static Response parseResponse(ByteBuffer response)
{
return parseResponse(response, false);
}

private static Response parseResponse(ByteBuffer response, boolean head)
{
try
{
return parseResponse(from(response));
return parseResponse(from(response), head);
}
catch (IOException x)
{
Expand All @@ -229,6 +254,11 @@ public static Response parseResponse(ReadableByteChannel channel) throws IOExcep
}

public static Response parseResponse(Input input) throws IOException
{
return parseResponse(input, false);
}

public static Response parseResponse(Input input, boolean head) throws IOException
{
Response response;
HttpParser parser = input.takeHttpParser();
Expand All @@ -241,6 +271,7 @@ public static Response parseResponse(Input input) throws IOException
response = new Response();
parser = new HttpParser(response);
}
parser.setHeadResponse(head);
parse(input, parser);
if (response.isComplete())
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ private void sendData(Request request, Response response, Callback callback, Htt
// If there are no satisfiable ranges, send a 416 response.
if (ranges.isEmpty())
{
putHeaders(response, content, NO_CONTENT_LENGTH);
response.getHeaders().putLongField(HttpHeader.CONTENT_LENGTH, 0);
response.getHeaders().put(HttpHeader.CONTENT_RANGE, ByteRange.toNonSatisfiableHeaderValue(contentLength));
Response.writeError(request, response, callback, HttpStatus.RANGE_NOT_SATISFIABLE_416);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,8 @@ public boolean handle(org.eclipse.jetty.server.Request request, Response respons
""";

LocalConnector.LocalEndPoint localEndPoint = connector.executeRequest(rawRequest);

ByteBuffer rawResponse = localEndPoint.waitForResponse(true, 2, TimeUnit.SECONDS);
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
HttpTester.Response response = HttpTester.parseHeadResponse(rawResponse);
assertNotNull(response);
assertThat(response.getStatus(), is(HttpStatus.OK_200));
}
Expand Down Expand Up @@ -370,7 +369,7 @@ public boolean handle(org.eclipse.jetty.server.Request request, Response respons
""";

HttpTester.Response response = HttpTester.parseResponse(connector.getResponse(rawRequest));
HttpTester.Response response = HttpTester.parseHeadResponse(connector.getResponse(rawRequest));
assertNotNull(response);
assertThat(response.getStatus(), is(HttpStatus.OK_200));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ public void testConditionalHeadResponseCommitted() throws Exception
getLocalConnectorConfig().setOutputBufferSize(8);
_rootResourceHandler.setEtags(true);

HttpTester.Response response = HttpTester.parseResponse(
HttpTester.Response response = HttpTester.parseHeadResponse(
_local.getResponse("""
HEAD /context/big.txt HTTP/1.1\r
Host: local\r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void testHEADThenGETPersistent() throws Exception
""";
localEndPoint.addInput(BufferUtil.toBuffer(rawHeadRequest, UTF_8));
HttpTester.Response response = HttpTester.parseResponse(localEndPoint.getResponse(true, 2, TimeUnit.SECONDS));
HttpTester.Response response = HttpTester.parseHeadResponse(localEndPoint.getResponse(true, 2, TimeUnit.SECONDS));

assertThat(response.getStatus(), is(200));
assertNull(response.getField("Vary")); // HEAD should not have a Vary header
Expand Down Expand Up @@ -371,7 +371,7 @@ public void testHead() throws Exception
""";

// Parse HEAD response
response = HttpTester.parseResponse(_connector.getResponse(rawRequest));
response = HttpTester.parseHeadResponse(_connector.getResponse(rawRequest));

assertThat(response.getStatus(), is(200));
assertNull(response.getField("Vary")); // HEAD should not have a Vary header
Expand Down Expand Up @@ -946,6 +946,8 @@ public void testIncludeExcludeInflationPaths() throws Exception
@ValueSource(strings = {"POST", "WIBBLE", "GET", "HEAD"})
public void testIncludeMethods(String method) throws Exception
{
boolean head = HttpMethod.HEAD.is(method);

_gzipHandler.setIncludedMethods("POST", "WIBBLE", "GET", "HEAD");

int fileSize = DEFAULT_OUTPUT_BUFFER_SIZE * 8;
Expand All @@ -969,7 +971,7 @@ public void testIncludeMethods(String method) throws Exception
ByteBuffer rawResponse = _connector.getResponse(request.generate(), 5, TimeUnit.SECONDS);

// Parse response
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
HttpTester.Response response = HttpTester.parseResponse(HttpTester.from(rawResponse), head);

assertThat("Response status", response.getStatus(), is(HttpStatus.OK_200));

Expand All @@ -980,7 +982,7 @@ public void testIncludeMethods(String method) throws Exception
assertThat("Response[Content-Length]", response.getLongField("Content-Length"),
is(both(greaterThan(0L)).and(lessThan((long)fileSize))));

if (method.equals("HEAD"))
if (head)
{
// Don't assert Response body content on HEAD requests.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ public void testBasic(Scenario scenario) throws Exception
{
_server.start();
String rawResponse = _connector.getResponse(scenario.rawRequest);
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
HttpTester.Response response = HttpTester.parseResponse(HttpTester.from(rawResponse), scenario.rawRequest.startsWith("HEAD "));
assertThat(response.toString(), response.getStatus(), is(scenario.expectedStatus));
if (scenario.extraAsserts != null)
scenario.extraAsserts.accept(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public String toString()
// if there are no satisfiable ranges, send 416 response
if (ranges == null || ranges.size() == 0)
{
putHeaders(response, content, Response.USE_KNOWN_CONTENT_LENGTH);
response.setContentLength(0);
response.setHeader(HttpHeader.CONTENT_RANGE.asString(),
InclusiveByteRange.to416HeaderRangeString(content_length));
sendStatus(response, HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ public void testBasic(Scenario scenario) throws Exception
{
_server.start();
String rawResponse = _connector.getResponse(scenario.rawRequest);
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
HttpTester.Response response = HttpTester.parseResponse(HttpTester.from(rawResponse), scenario.rawRequest.startsWith("HEAD "));
assertThat(response.toString(), response.getStatus(), is(scenario.expectedStatus));
if (scenario.extraAsserts != null)
scenario.extraAsserts.accept(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

package org.eclipse.jetty.ee9.test.rfcs;

import java.nio.file.Path;

import org.eclipse.jetty.ee9.test.support.XmlBasedJettyServer;
import org.eclipse.jetty.ee9.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.ee9.test.support.rawhttp.HttpsSocketImpl;
Expand All @@ -24,16 +22,13 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;

/**
* Perform the RFC2616 tests against a server running with the Jetty NIO Connector and listening on HTTPS (HTTP over SSL).
*/
@ExtendWith(WorkDirExtension.class)
public class RFC2616NIOHttpsTest extends RFC2616BaseTest
{

private static XmlBasedJettyServer xmlBasedJettyServer;

@BeforeAll
Expand Down

0 comments on commit baf7224

Please sign in to comment.