use of org.apache.hc.core5.http.io.HttpFilterChain in project httpcomponents-core by apache.
the class TerminalServerFilter method handle.
@Override
public void handle(final ClassicHttpRequest request, final HttpFilterChain.ResponseTrigger responseTrigger, final HttpContext context, final HttpFilterChain chain) throws HttpException, IOException {
final ClassicHttpResponse response = responseFactory.newHttpResponse(HttpStatus.SC_OK);
final HttpRequestHandler handler = handlerMapper.resolve(request, context);
if (handler != null) {
handler.handle(request, response, context);
} else {
response.setCode(HttpStatus.SC_NOT_IMPLEMENTED);
}
responseTrigger.submitResponse(response);
}
use of org.apache.hc.core5.http.io.HttpFilterChain in project httpcomponents-core by apache.
the class HttpServerExpectationFilter method handle.
@Override
public final void handle(final ClassicHttpRequest request, final HttpFilterChain.ResponseTrigger responseTrigger, final HttpContext context, final HttpFilterChain chain) throws HttpException, IOException {
final Header expect = request.getFirstHeader(HttpHeaders.EXPECT);
final boolean expectContinue = expect != null && HeaderElements.CONTINUE.equalsIgnoreCase(expect.getValue());
if (expectContinue) {
final boolean verified = verify(request, context);
if (verified) {
responseTrigger.sendInformation(new BasicClassicHttpResponse(HttpStatus.SC_CONTINUE));
} else {
final ClassicHttpResponse expectationFailed = new BasicClassicHttpResponse(HttpStatus.SC_EXPECTATION_FAILED);
final HttpEntity responseContent = generateResponseContent(expectationFailed);
expectationFailed.setEntity(responseContent);
responseTrigger.submitResponse(expectationFailed);
return;
}
}
chain.proceed(request, responseTrigger, context);
}
use of org.apache.hc.core5.http.io.HttpFilterChain in project httpcomponents-core by apache.
the class AbstractHttpServerAuthFilter method handle.
@Override
public final void handle(final ClassicHttpRequest request, final HttpFilterChain.ResponseTrigger responseTrigger, final HttpContext context, final HttpFilterChain chain) throws HttpException, IOException {
final Header h = request.getFirstHeader(HttpHeaders.AUTHORIZATION);
final T challengeResponse = h != null ? parseChallengeResponse(h.getValue(), context) : null;
final URIAuthority authority = request.getAuthority();
final String requestUri = request.getRequestUri();
final boolean authenticated = authenticate(challengeResponse, authority, requestUri, context);
final Header expect = request.getFirstHeader(HttpHeaders.EXPECT);
final boolean expectContinue = expect != null && HeaderElements.CONTINUE.equalsIgnoreCase(expect.getValue());
if (authenticated) {
if (expectContinue) {
responseTrigger.sendInformation(new BasicClassicHttpResponse(HttpStatus.SC_CONTINUE));
}
chain.proceed(request, responseTrigger, context);
} else {
final ClassicHttpResponse unauthorized = new BasicClassicHttpResponse(HttpStatus.SC_UNAUTHORIZED);
unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, generateChallenge(challengeResponse, authority, requestUri, context));
final HttpEntity responseContent = generateResponseContent(unauthorized);
unauthorized.setEntity(responseContent);
if (respondImmediately || expectContinue || request.getEntity() == null) {
// Respond immediately
responseTrigger.submitResponse(unauthorized);
// Consume request body later
EntityUtils.consume(request.getEntity());
} else {
// Consume request body first
EntityUtils.consume(request.getEntity());
// Respond later
responseTrigger.submitResponse(unauthorized);
}
}
}
Aggregations