private void writeAndCloseSocket(ChannelHandlerContext ctx, HttpRequest request, HttpResponse response) { boolean closeChannel; ConnectionOptions connectionOptions = response.getConnectionOptions(); if (connectionOptions != null && connectionOptions.getCloseSocket() != null) { closeChannel = connectionOptions.getCloseSocket(); } else { closeChannel = !(request.isKeepAlive() != null && request.isKeepAlive()); } if (closeChannel) { ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } else { ctx.writeAndFlush(response); } }
jgen.writeObjectField("delay", httpResponse.getDelay()); if (httpResponse.getConnectionOptions() != null) { jgen.writeObjectField("connectionOptions", httpResponse.getConnectionOptions());
public HttpResponseDTO(HttpResponse httpResponse) { if (httpResponse != null) { statusCode = httpResponse.getStatusCode(); reasonPhrase = httpResponse.getReasonPhrase(); body = BodyWithContentTypeDTO.createDTO(httpResponse.getBody()); headers = httpResponse.getHeaders(); cookies = httpResponse.getCookies(); delay = (httpResponse.getDelay() != null ? new DelayDTO(httpResponse.getDelay()) : null); connectionOptions = (httpResponse.getConnectionOptions() != null ? new ConnectionOptionsDTO(httpResponse.getConnectionOptions()) : null); } }
appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withDelay(").append(new DelayToJavaSerializer().serialize(0, httpResponse.getDelay())).append(")"); if (httpResponse.getConnectionOptions() != null) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withConnectionOptions("); output.append(new ConnectionOptionsToJavaSerializer().serialize(numberOfSpacesToIndent + 2, httpResponse.getConnectionOptions())); appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(")");
private boolean validateSupportedFeatures(Expectation expectation, HttpRequest request, ResponseWriter responseWriter) { boolean valid = true; Action action = expectation.getAction(); String NOT_SUPPORTED_MESSAGE = " is not supported by MockServer deployed as a WAR due to limitations in the JEE specification; use mockserver-netty to enable these features"; if (action instanceof HttpResponse && ((HttpResponse) action).getConnectionOptions() != null) { valid = false; responseWriter.writeResponse(request, response("ConnectionOptions" + NOT_SUPPORTED_MESSAGE), true); } else if (action instanceof HttpObjectCallback) { valid = false; responseWriter.writeResponse(request, response("HttpObjectCallback" + NOT_SUPPORTED_MESSAGE), true); } else if (action instanceof HttpError) { valid = false; responseWriter.writeResponse(request, response("HttpError" + NOT_SUPPORTED_MESSAGE), true); } return valid; }
ConnectionOptions connectionOptions = response.getConnectionOptions(); boolean overrideContentLength = connectionOptions != null && connectionOptions.getContentLengthHeaderOverride() != null; boolean addContentLength = connectionOptions == null || isFalseOrNull(connectionOptions.getSuppressContentLengthHeader());
protected void addConnectionHeader(HttpRequest request, HttpResponse response) { ConnectionOptions connectionOptions = response.getConnectionOptions(); if (connectionOptions != null && connectionOptions.getKeepAliveOverride() != null) { if (connectionOptions.getKeepAliveOverride()) { response.replaceHeader(header(CONNECTION.toString(), KEEP_ALIVE.toString())); } else { response.replaceHeader(header(CONNECTION.toString(), CLOSE.toString())); } } else if (connectionOptions == null || isFalseOrNull(connectionOptions.getSuppressConnectionHeader())) { if (request.isKeepAlive() != null && request.isKeepAlive() && (connectionOptions == null || isFalseOrNull(connectionOptions.getCloseSocket()))) { response.replaceHeader(header(CONNECTION.toString(), KEEP_ALIVE.toString())); } else { response.replaceHeader(header(CONNECTION.toString(), CLOSE.toString())); } } } }
private void writeAndCloseSocket(ChannelHandlerContext ctx, HttpRequest request, HttpResponse response) { boolean closeChannel; ConnectionOptions connectionOptions = response.getConnectionOptions(); if (connectionOptions != null && connectionOptions.getCloseSocket() != null) { closeChannel = connectionOptions.getCloseSocket(); } else { closeChannel = !(request.isKeepAlive() != null && request.isKeepAlive()); } if (closeChannel) { ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } else { ctx.writeAndFlush(response); } }
jgen.writeObjectField("delay", httpResponse.getDelay()); if (httpResponse.getConnectionOptions() != null) { jgen.writeObjectField("connectionOptions", httpResponse.getConnectionOptions());
public HttpResponseDTO(HttpResponse httpResponse) { if (httpResponse != null) { statusCode = httpResponse.getStatusCode(); reasonPhrase = httpResponse.getReasonPhrase(); body = BodyWithContentTypeDTO.createDTO(httpResponse.getBody()); headers = httpResponse.getHeaders(); cookies = httpResponse.getCookies(); delay = (httpResponse.getDelay() != null ? new DelayDTO(httpResponse.getDelay()) : null); connectionOptions = (httpResponse.getConnectionOptions() != null ? new ConnectionOptionsDTO(httpResponse.getConnectionOptions()) : null); } }
appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withDelay(").append(new DelayToJavaSerializer().serialize(0, httpResponse.getDelay())).append(")"); if (httpResponse.getConnectionOptions() != null) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withConnectionOptions("); output.append(new ConnectionOptionsToJavaSerializer().serialize(numberOfSpacesToIndent + 2, httpResponse.getConnectionOptions())); appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(")");
private boolean validateSupportedFeatures(Expectation expectation, HttpRequest request, ResponseWriter responseWriter) { boolean valid = true; Action action = expectation.getAction(); String NOT_SUPPORTED_MESSAGE = " is not supported by MockServer deployed as a WAR due to limitations in the JEE specification; use mockserver-netty to enable these features"; if (action instanceof HttpResponse && ((HttpResponse) action).getConnectionOptions() != null) { responseWriter.writeResponse(request, response("ConnectionOptions" + NOT_SUPPORTED_MESSAGE), true); valid = false; } else if (action instanceof HttpObjectCallback) { responseWriter.writeResponse(request, response("HttpObjectCallback" + NOT_SUPPORTED_MESSAGE), true); valid = false; } else if (action instanceof HttpError) { responseWriter.writeResponse(request, response("HttpError" + NOT_SUPPORTED_MESSAGE), true); valid = false; } return valid; }
ConnectionOptions connectionOptions = response.getConnectionOptions(); boolean overrideContentLength = connectionOptions != null && connectionOptions.getContentLengthHeaderOverride() != null; boolean addContentLength = connectionOptions == null || isFalseOrNull(connectionOptions.getSuppressContentLengthHeader());
protected void addConnectionHeader(HttpRequest request, HttpResponse response) { ConnectionOptions connectionOptions = response.getConnectionOptions(); if (connectionOptions != null && connectionOptions.getKeepAliveOverride() != null) { if (connectionOptions.getKeepAliveOverride()) { response.replaceHeader(header(CONNECTION.toString(), KEEP_ALIVE.toString())); } else { response.replaceHeader(header(CONNECTION.toString(), CLOSE.toString())); } } else if (connectionOptions == null || isFalseOrNull(connectionOptions.getSuppressConnectionHeader())) { if (request.isKeepAlive() != null && request.isKeepAlive() && (connectionOptions == null || isFalseOrNull(connectionOptions.getCloseSocket()))) { response.replaceHeader(header(CONNECTION.toString(), KEEP_ALIVE.toString())); } else { response.replaceHeader(header(CONNECTION.toString(), CLOSE.toString())); } } } }