use of org.eclipse.jetty.http.HttpVersion in project jetty.project by eclipse.
the class HttpConnection method normalizeRequest.
protected void normalizeRequest(Request request) {
HttpVersion version = request.getVersion();
HttpFields headers = request.getHeaders();
ContentProvider content = request.getContent();
ProxyConfiguration.Proxy proxy = destination.getProxy();
// Make sure the path is there
String path = request.getPath();
if (path.trim().length() == 0) {
path = "/";
request.path(path);
}
URI uri = request.getURI();
if (proxy instanceof HttpProxy && !HttpClient.isSchemeSecure(request.getScheme()) && uri != null) {
path = uri.toString();
request.path(path);
}
// If we are HTTP 1.1, add the Host header
if (version.getVersion() <= 11) {
if (!headers.containsKey(HttpHeader.HOST.asString()))
headers.put(getHttpDestination().getHostField());
}
// Add content headers
if (content != null) {
if (!headers.containsKey(HttpHeader.CONTENT_TYPE.asString())) {
String contentType = null;
if (content instanceof ContentProvider.Typed)
contentType = ((ContentProvider.Typed) content).getContentType();
if (contentType != null)
headers.put(HttpHeader.CONTENT_TYPE, contentType);
else
headers.put(HttpHeader.CONTENT_TYPE, "application/octet-stream");
}
long contentLength = content.getLength();
if (contentLength >= 0) {
if (!headers.containsKey(HttpHeader.CONTENT_LENGTH.asString()))
headers.put(HttpHeader.CONTENT_LENGTH, String.valueOf(contentLength));
}
}
// Cookies
CookieStore cookieStore = getHttpClient().getCookieStore();
if (cookieStore != null) {
StringBuilder cookies = null;
if (uri != null)
cookies = convertCookies(cookieStore.get(uri), null);
cookies = convertCookies(request.getCookies(), cookies);
if (cookies != null)
request.header(HttpHeader.COOKIE.asString(), cookies.toString());
}
// Authentication
applyAuthentication(request, proxy != null ? proxy.getURI() : null);
applyAuthentication(request, uri);
}
use of org.eclipse.jetty.http.HttpVersion in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testRequestHasHTTP2Version.
@Test
public void testRequestHasHTTP2Version() throws Exception {
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
HttpVersion version = HttpVersion.fromString(request.getProtocol());
response.setStatus(version == HttpVersion.HTTP_2 ? HttpStatus.OK_200 : HttpStatus.INTERNAL_SERVER_ERROR_500);
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).onRequestBegin(request -> {
if (request.getVersion() != HttpVersion.HTTP_2)
request.abort(new Exception("Not a HTTP/2 request"));
}).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
use of org.eclipse.jetty.http.HttpVersion in project jetty.project by eclipse.
the class Request method getProtocol.
/* ------------------------------------------------------------ */
/*
* @see javax.servlet.ServletRequest#getProtocol()
*/
@Override
public String getProtocol() {
MetaData.Request metadata = _metaData;
if (metadata == null)
return null;
HttpVersion version = metadata.getHttpVersion();
if (version == null)
return null;
return version.toString();
}
Aggregations