use of org.apache.hc.core5.http.HttpVersion in project httpcomponents-core by apache.
the class HttpProtocolNegotiator method connected.
@Override
public void connected(final IOSession session) throws IOException {
final HttpVersion httpVersion;
final TlsDetails tlsDetails = ioSession.getTlsDetails();
if (tlsDetails != null) {
final String appProtocol = tlsDetails.getApplicationProtocol();
if (TextUtils.isEmpty(appProtocol)) {
httpVersion = HttpVersion.HTTP_1_1;
} else if (appProtocol.equals(ApplicationProtocol.HTTP_1_1.id)) {
httpVersion = HttpVersion.HTTP_1_1;
} else if (appProtocol.equals(ApplicationProtocol.HTTP_2.id)) {
httpVersion = HttpVersion.HTTP_2;
} else {
throw new ProtocolNegotiationException("Unsupported application protocol: " + appProtocol);
}
} else {
httpVersion = HttpVersion.HTTP_1_1;
}
startProtocol(httpVersion);
}
use of org.apache.hc.core5.http.HttpVersion in project ecf by eclipse.
the class HttpClientRetrieveFileTransfer method getResponseCode.
public int getResponseCode() {
if (responseCode != -1)
return responseCode;
ProtocolVersion version = getMethod.getVersion();
if (version == null) {
responseCode = -1;
httpVersion = 1;
return responseCode;
}
httpVersion = version.getMinor();
if (httpResponse != null) {
responseCode = httpResponse.getCode();
}
return responseCode;
}
use of org.apache.hc.core5.http.HttpVersion in project httpcomponents-core by apache.
the class TestBasicLineParser method testHttpVersionParsing.
@Test
public void testHttpVersionParsing() throws Exception {
final CharArrayBuffer buffer = new CharArrayBuffer(16);
buffer.append("HTTP/1.1");
ParserCursor cursor = new ParserCursor(0, buffer.length());
HttpVersion version = (HttpVersion) parser.parseProtocolVersion(buffer, cursor);
Assertions.assertEquals("HTTP", version.getProtocol(), "HTTP protocol name");
Assertions.assertEquals(1, version.getMajor(), "HTTP major version number");
Assertions.assertEquals(1, version.getMinor(), "HTTP minor version number");
Assertions.assertEquals("HTTP/1.1", version.toString(), "HTTP version number");
Assertions.assertEquals(buffer.length(), cursor.getPos());
Assertions.assertTrue(cursor.atEnd());
buffer.clear();
buffer.append("HTTP/1.123 123");
cursor = new ParserCursor(0, buffer.length());
version = (HttpVersion) parser.parseProtocolVersion(buffer, cursor);
Assertions.assertEquals("HTTP", version.getProtocol(), "HTTP protocol name");
Assertions.assertEquals(1, version.getMajor(), "HTTP major version number");
Assertions.assertEquals(123, version.getMinor(), "HTTP minor version number");
Assertions.assertEquals("HTTP/1.123", version.toString(), "HTTP version number");
Assertions.assertEquals(' ', buffer.charAt(cursor.getPos()));
Assertions.assertEquals(buffer.length() - 4, cursor.getPos());
Assertions.assertFalse(cursor.atEnd());
}
use of org.apache.hc.core5.http.HttpVersion in project httpcomponents-core by apache.
the class HttpBenchmark method doExecute.
private Results doExecute(final HttpAsyncRequester requester, final Stats stats) throws Exception {
final URI requestUri = config.getUri();
final HttpHost host = new HttpHost(requestUri.getScheme(), requestUri.getHost(), requestUri.getPort());
final AtomicLong requestCount = new AtomicLong(config.getRequests());
final HttpVersion version = HttpVersion.HTTP_1_1;
final CountDownLatch completionLatch = new CountDownLatch(config.getConcurrencyLevel());
final BenchmarkWorker[] workers = new BenchmarkWorker[config.getConcurrencyLevel()];
for (int i = 0; i < workers.length; i++) {
final HttpCoreContext context = HttpCoreContext.create();
context.setProtocolVersion(version);
final BenchmarkWorker worker = new BenchmarkWorker(requester, host, context, requestCount, completionLatch, stats, config);
workers[i] = worker;
}
final long deadline = config.getTimeLimit() != null ? config.getTimeLimit().toMilliseconds() : Long.MAX_VALUE;
final long startTime = System.currentTimeMillis();
for (int i = 0; i < workers.length; i++) {
workers[i].execute();
}
completionLatch.await(deadline, TimeUnit.MILLISECONDS);
if (config.getVerbosity() >= 3) {
System.out.println("...done");
}
final long endTime = System.currentTimeMillis();
for (int i = 0; i < workers.length; i++) {
workers[i].releaseResources();
}
return new Results(stats.getServerName(), stats.getVersion(), host.getHostName(), host.getPort() > 0 ? host.getPort() : host.getSchemeName().equalsIgnoreCase("https") ? 443 : 80, requestUri.toASCIIString(), stats.getContentLength(), config.getConcurrencyLevel(), endTime - startTime, stats.getSuccessCount(), stats.getFailureCount(), stats.getKeepAliveCount(), stats.getTotalBytesRecv(), stats.getTotalBytesSent(), stats.getTotalContentLength());
}
Aggregations