本文整理匯總了Java中org.eclipse.jetty.http.HttpHeader類的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeader類的具體用法?Java HttpHeader怎麽用?Java HttpHeader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpHeader類屬於org.eclipse.jetty.http包,在下文中一共展示了HttpHeader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: putHeaders
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
@Override
protected void putHeaders(HttpServletResponse response, HttpContent content, long contentLength) {
super.putHeaders(response, content, contentLength);
HttpFields fields = ((Response) response).getHttpFields();
if (requestHolder.get().getDispatcherType() == DispatcherType.ERROR) {
/*
* Do not cache error page and also makes sure that error page is not eligible for
* modification check. That is, error page will be always retrieved.
*/
fields.put(HttpHeader.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
} else if (requestHolder.get().getRequestURI().equals("/favicon.ico")) {
/*
* Make sure favicon request is cached. Otherwise, it will be requested for every
* page request.
*/
fields.put(HttpHeader.CACHE_CONTROL, "max-age=86400,public");
}
}
示例2: postRequest
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
private Request postRequest(ApiURL url, JsonObject r, Timeout timeout) {
Fields fields = new Fields();
fields.add("r", GsonUtil.gson.toJson(r));
Request request = httpClient.newRequest(url.getUrl()).method(HttpMethod.POST).agent(ApiURL.USER_AGENT)
.header("Origin", url.getOrigin()).content(new FormContentProvider(fields));
if (url.getReferer() != null) {
request.header(HttpHeader.REFERER, url.getReferer());
}
if (timeout != null) {
request.timeout(timeout.getTime(), timeout.getUnit());
}
return request;
}
示例3: setHeader
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
public void setHeader(HttpHeader name, String value)
{
if (HttpHeader.CONTENT_TYPE == name)
setContentType(value);
else
{
if (isIncluding())
return;
_fields.put(name, value);
if (HttpHeader.CONTENT_LENGTH == name)
{
if (value == null)
_contentLength = -1l;
else
_contentLength = Long.parseLong(value);
}
}
}
示例4: addHeader
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
@Override
public void addHeader(String name, String value)
{
if (isIncluding())
{
if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
name = name.substring(SET_INCLUDE_HEADER_PREFIX.length());
else
return;
}
if (HttpHeader.CONTENT_TYPE.is(name))
{
setContentType(value);
return;
}
if (HttpHeader.CONTENT_LENGTH.is(name))
{
setHeader(name,value);
return;
}
_fields.add(name, value);
}
示例5: setLocale
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
@Override
public void setLocale(Locale locale)
{
if (locale == null || isCommitted() || isIncluding())
return;
_locale = locale;
_fields.put(HttpHeader.CONTENT_LANGUAGE, locale.toString().replace('_', '-'));
if (_outputType != OutputType.NONE)
return;
if (_channel.getRequest().getContext() == null)
return;
String charset = _channel.getRequest().getContext().getContextHandler().getLocaleEncoding(locale);
if (charset != null && charset.length() > 0 && !_explicitEncoding)
setCharacterEncoding(charset,false);
}
示例6: putHeaders
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
public static void putHeaders(HttpServletResponse response, HttpContent content, long contentLength, boolean etag)
{
long lml=content.getResource().lastModified();
if (lml>=0)
response.setDateHeader(HttpHeader.LAST_MODIFIED.asString(),lml);
if (contentLength==0)
contentLength=content.getContentLengthValue();
if (contentLength >=0)
{
if (contentLength<Integer.MAX_VALUE)
response.setContentLength((int)contentLength);
else
response.setHeader(HttpHeader.CONTENT_LENGTH.asString(),Long.toString(contentLength));
}
String ct=content.getContentTypeValue();
if (ct!=null && response.getContentType()==null)
response.setContentType(ct);
String ce=content.getContentEncodingValue();
if (ce!=null)
response.setHeader(HttpHeader.CONTENT_ENCODING.asString(),ce);
if (etag)
{
String et=content.getETagValue();
if (et!=null)
response.setHeader(HttpHeader.ETAG.asString(),et);
}
}
示例7: onProxyResponseFailure
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
@Override
protected void onProxyResponseFailure(final HttpServletRequest clientRequest, final HttpServletResponse proxyResponse,
final Response serverResponse, final Throwable failure) {
_log.warn(failure.toString());
if (proxyResponse.isCommitted()) {
// Parent behavior
super.onProxyResponseFailure(clientRequest, proxyResponse, serverResponse, failure);
} else {
proxyResponse.resetBuffer();
if (failure instanceof TimeoutException) {
proxyResponse.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
} else {
// Unavailable business server as JSON response
proxyResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
proxyResponse.setContentType("application/json");
try {
proxyResponse.getOutputStream().write("{\"code\":\"business-down\"}".getBytes(StandardCharsets.UTF_8));
} catch (final IOException ioe) {
_log.warn("Broken proxy stream", ioe);
}
}
proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
final AsyncContext asyncContext = clientRequest.getAsyncContext();
asyncContext.complete();
}
}
示例8: sendChallengeIfNecessary
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
/**
* Jetty has a bug in which if there is an Authorization header sent by a client which is
* not of the Negotiate type, Jetty does not send the challenge to negotiate. This works
* around that issue, forcing the challenge to be sent. Will require investigation on
* upgrade to a newer version of Jetty.
*/
Authentication sendChallengeIfNecessary(Authentication computedAuth, ServletRequest request,
ServletResponse response) throws IOException {
if (computedAuth == Authentication.UNAUTHENTICATED) {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
String header = req.getHeader(HttpHeader.AUTHORIZATION.asString());
// We have an authorization header, but it's not Negotiate
if (header != null && !header.startsWith(HttpHeader.NEGOTIATE.asString())) {
LOG.debug("Client sent Authorization header that was not for Negotiate,"
+ " sending challenge anyways.");
if (DeferredAuthentication.isDeferred(res)) {
return Authentication.UNAUTHENTICATED;
}
res.setHeader(HttpHeader.WWW_AUTHENTICATE.asString(), HttpHeader.NEGOTIATE.asString());
res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return Authentication.SEND_CONTINUE;
}
}
return computedAuth;
}
示例9: sanityCheck
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
private void sanityCheck() throws Exception {
UserLoginSession ul = login();
String authHeader = HttpHeader.AUTHORIZATION.toString();
String authToken = "_dremio" + ul.getToken();
Space dg = expectSuccess(currentApiV2.path("space/DG").request(JSON).header(authHeader, authToken).buildGet(), Space.class);
assertEquals(10, dg.getContents().getDatasets().size());
expectSuccess(currentApiV2.path("/jobs").request(JSON).header(authHeader, authToken).buildGet(), JobsUI.class);
SourceUI source = expectSuccess(currentApiV2.path("source/LocalFS1").request(JSON).header(authHeader, authToken).buildGet(), SourceUI.class);
NamespaceTree ns = source.getContents();
assertEquals("/source/LocalFS1", source.getResourcePath().toString());
assertTrue(ns.getDatasets().size() + ns.getFolders().size() + ns.getFiles().size() > 0);
String folderName = "folder_" + System.currentTimeMillis();
expectSuccess((currentApiV2.path("space/DG/folder/").request(JSON).header(authHeader, authToken)).buildPost(Entity.json("{\"name\": \""+folderName+"\"}")), Folder.class);
}
示例10: rawRequest
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
protected String rawRequest(String url, Map<String, String> params) throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
Request req = httpClient.newRequest(new String(url.getBytes("UTF-8"), "UTF-8"))
.header(HttpHeader.CONTENT_ENCODING, "UTF-8")
.method(HttpMethod.GET)
.header(HttpHeader.ACCEPT_ENCODING, "UTF-8");
req = req.param("app_token", APIKeys.getAPPKey());
if (params != null) {
for (String key : params.keySet()) {
req = req.param(key, params.get(key));
}
}
Main.log.info("GET {}, {}, {}", req, req.getQuery(), req.getParams());
ContentResponse resp = req.send();
if (resp.getStatus() != HttpStatus.OK_200) {
throw new HttpRequestException(
"Request ended with non-OK status: "
+ HttpStatus.getMessage(resp.getStatus()),
resp.getRequest()
);
}
return resp.getContentAsString();
}
示例11: sendMessageToHyVarRec
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
protected String sendMessageToHyVarRec(String message, URI uri) throws UnresolvedAddressException, ExecutionException, InterruptedException, TimeoutException {
HttpClient hyvarrecClient = new HttpClient();
try {
hyvarrecClient.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
URI hyvarrecUri = uri;
Request hyvarrecRequest = hyvarrecClient.POST(hyvarrecUri);
hyvarrecRequest.header(HttpHeader.CONTENT_TYPE, "application/json");
hyvarrecRequest.content(new StringContentProvider(message), "application/json");
ContentResponse hyvarrecResponse;
String hyvarrecAnswerString = "";
hyvarrecResponse = hyvarrecRequest.send();
hyvarrecAnswerString = hyvarrecResponse.getContentAsString();
// Only for Debug
System.err.println("HyVarRec Answer: "+hyvarrecAnswerString);
return hyvarrecAnswerString;
}
示例12: testNewSessionReqForSpnegoLogin
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
/**
* Test to verify response when request is sent for {@link WebServerConstants#SPENGO_LOGIN_RESOURCE_PATH} from
* unauthenticated session. Expectation is client will receive response with Negotiate header.
* @throws Exception
*/
@Test
public void testNewSessionReqForSpnegoLogin() throws Exception {
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
final HttpSession session = Mockito.mock(HttpSession.class);
Mockito.when(request.getSession(true)).thenReturn(session);
Mockito.when(request.getRequestURI()).thenReturn(WebServerConstants.SPENGO_LOGIN_RESOURCE_PATH);
final Authentication authentication = spnegoAuthenticator.validateRequest(request, response, false);
assertEquals(authentication, Authentication.SEND_CONTINUE);
verify(response).sendError(401);
verify(response).setHeader(HttpHeader.WWW_AUTHENTICATE.asString(), HttpHeader.NEGOTIATE.asString());
}
示例13: testAuthClientRequestForSpnegoLoginResource
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
/**
* Test to verify response when request is sent for {@link WebServerConstants#SPENGO_LOGIN_RESOURCE_PATH} from
* authenticated session. Expectation is server will find the authenticated UserIdentity.
* @throws Exception
*/
@Test
public void testAuthClientRequestForSpnegoLoginResource() throws Exception {
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
final HttpSession session = Mockito.mock(HttpSession.class);
final Authentication authentication = Mockito.mock(UserAuthentication.class);
Mockito.when(request.getSession(true)).thenReturn(session);
Mockito.when(request.getRequestURI()).thenReturn(WebServerConstants.SPENGO_LOGIN_RESOURCE_PATH);
Mockito.when(session.getAttribute(SessionAuthentication.__J_AUTHENTICATED)).thenReturn(authentication);
final UserAuthentication returnedAuthentication = (UserAuthentication) spnegoAuthenticator.validateRequest
(request, response, false);
assertEquals(authentication, returnedAuthentication);
verify(response, never()).sendError(401);
verify(response, never()).setHeader(HttpHeader.WWW_AUTHENTICATE.asString(), HttpHeader.NEGOTIATE.asString());
}
示例14: testAuthClientRequestForOtherPage
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
/**
* Test to verify response when request is sent for any other resource other than
* {@link WebServerConstants#SPENGO_LOGIN_RESOURCE_PATH} from authenticated session. Expectation is server will
* find the authenticated UserIdentity and will not perform the authentication again for new resource.
* @throws Exception
*/
@Test
public void testAuthClientRequestForOtherPage() throws Exception {
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
final HttpSession session = Mockito.mock(HttpSession.class);
final Authentication authentication = Mockito.mock(UserAuthentication.class);
Mockito.when(request.getSession(true)).thenReturn(session);
Mockito.when(request.getRequestURI()).thenReturn(WebServerConstants.WEBSERVER_ROOT_PATH);
Mockito.when(session.getAttribute(SessionAuthentication.__J_AUTHENTICATED)).thenReturn(authentication);
final UserAuthentication returnedAuthentication = (UserAuthentication) spnegoAuthenticator.validateRequest
(request, response, false);
assertEquals(authentication, returnedAuthentication);
verify(response, never()).sendError(401);
verify(response, never()).setHeader(HttpHeader.WWW_AUTHENTICATE.asString(), HttpHeader.NEGOTIATE.asString());
}
示例15: testAuthClientRequestForLogOut
import org.eclipse.jetty.http.HttpHeader; //導入依賴的package包/類
/**
* Test to verify that when request is sent for {@link WebServerConstants#LOGOUT_RESOURCE_PATH} then the UserIdentity
* will be removed from the session and returned authentication will be null from
* {@link DrillSpnegoAuthenticator#validateRequest(ServletRequest, ServletResponse, boolean)}
* @throws Exception
*/
@Test
public void testAuthClientRequestForLogOut() throws Exception {
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
final HttpSession session = Mockito.mock(HttpSession.class);
final Authentication authentication = Mockito.mock(UserAuthentication.class);
Mockito.when(request.getSession(true)).thenReturn(session);
Mockito.when(request.getRequestURI()).thenReturn(WebServerConstants.LOGOUT_RESOURCE_PATH);
Mockito.when(session.getAttribute(SessionAuthentication.__J_AUTHENTICATED)).thenReturn(authentication);
final UserAuthentication returnedAuthentication = (UserAuthentication) spnegoAuthenticator.validateRequest
(request, response, false);
assertNull(returnedAuthentication);
verify(session).removeAttribute(SessionAuthentication.__J_AUTHENTICATED);
verify(response, never()).sendError(401);
verify(response, never()).setHeader(HttpHeader.WWW_AUTHENTICATE.asString(), HttpHeader.NEGOTIATE.asString());
}