Package org.eclipse.jetty.http
Class HttpTester
java.lang.Object
org.eclipse.jetty.http.HttpTester
A HTTP Testing helper class.
Example usage:
try(Socket socket = new Socket("www.google.com",80)) { HttpTester.Request request = HttpTester.newRequest(); request.setMethod("POST"); request.setURI("/search"); request.setVersion(HttpVersion.HTTP_1_0); request.put(HttpHeader.HOST,"www.google.com"); request.put("Content-Type","application/x-www-form-urlencoded"); request.setContent("q=jetty%20server"); ByteBuffer output = request.generate(); socket.getOutputStream().write(output.array(),output.arrayOffset()+output.position(),output.remaining()); HttpTester.Input input = HttpTester.from(socket.getInputStream()); HttpTester.Response response = HttpTester.parseResponse(input); System.err.printf("%s %s %s%n",response.getVersion(),response.getStatus(),response.getReason()); for (HttpField field:response) System.err.printf("%s: %s%n",field.getName(),field.getValue()); System.err.printf("%n%s%n",response.getContent()); }
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
-
Method Summary
Modifier and TypeMethodDescriptionstatic HttpTester.Input
from
(InputStream in) static HttpTester.Input
from
(ByteBuffer data) static HttpTester.Input
static HttpTester.Request
static HttpTester.Request
parseRequest
(InputStream inputStream) static HttpTester.Request
parseRequest
(String request) static HttpTester.Request
parseRequest
(ByteBuffer request) static HttpTester.Request
parseRequest
(ReadableByteChannel channel) static HttpTester.Request
parseRequest
(HttpTester.Input input) static HttpTester.Response
parseResponse
(InputStream responseStream) static HttpTester.Response
parseResponse
(String response) static HttpTester.Response
parseResponse
(ByteBuffer response) static HttpTester.Response
static void
parseResponse
(HttpTester.Input in, HttpTester.Response response)
-
Method Details
-
from
-
from
-
from
-
newRequest
-
parseRequest
-
parseRequest
-
parseRequest
- Throws:
IOException
-
parseRequest
- Throws:
IOException
-
parseRequest
- Throws:
IOException
-
parseResponse
-
parseResponse
-
parseResponse
- Throws:
IOException
-
parseResponse
- Throws:
IOException
-
parseResponse
public static void parseResponse(HttpTester.Input in, HttpTester.Response response) throws IOException - Throws:
IOException
-