@Test public void ifNoneMatchHeader() throws Exception { final SockJsConfig config = config(); final String path = config.prefix() + "/iframe.html"; final HttpRequest httpRequest = createHttpRequest(path); httpRequest.headers().set(HttpHeaders.Names.IF_NONE_MATCH, "*"); final FullHttpResponse response = Iframe.response(config, httpRequest); assertThat(response.headers().get(HttpHeaders.Names.SET_COOKIE), equalTo("JSESSIONID=dummy; path=/")); assertThat(response.getStatus().code(), is(HttpResponseStatus.NOT_MODIFIED.code())); response.release(); }
public static FullHttpResponse response(final SockJsConfig config, final HttpRequest request) throws Exception { final QueryStringDecoder qsd = new QueryStringDecoder(request.getUri()); final String path = qsd.path(); if (!PATH_PATTERN.matcher(path).matches()) { return createResponse(request, NOT_FOUND, copiedBuffer("Not found", UTF_8)); } if (request.headers().contains(HttpHeaders.Names.IF_NONE_MATCH)) { final FullHttpResponse response = createResponse(request, NOT_MODIFIED); response.headers().set(HttpHeaders.Names.SET_COOKIE, "JSESSIONID=dummy; path=/"); return response; } else { final String content = createContent(config.sockJsUrl()); final FullHttpResponse response = createResponse(request, OK, copiedBuffer(content, UTF_8)); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8"); response.headers().set(HttpHeaders.Names.CACHE_CONTROL, "max-age=31536000, public"); response.headers().set(HttpHeaders.Names.EXPIRES, generateExpires()); final String etag = '\"' + generateMd5(content) + '\"'; response.headers().set(HttpHeaders.Names.ETAG, etag); return response; } }
Iframe { public static FullHttpResponse response(final SockJsConfig config, final HttpRequest request) throws Exception { final QueryStringDecoder qsd = new QueryStringDecoder(request.getUri()); final String path = qsd.path(); if (!PATH_PATTERN.matcher(path).matches()) { return createResponse(request, NOT_FOUND, copiedBuffer("Not found", UTF_8)); } if (request.headers().contains(HttpHeaders.Names.IF_NONE_MATCH)) { final FullHttpResponse response = createResponse(request, NOT_MODIFIED); response.headers().set(HttpHeaders.Names.SET_COOKIE, "JSESSIONID=dummy; path=/"); return response; } else { final String content = createContent(config.sockJsUrl()); final FullHttpResponse response = createResponse(request, OK, copiedBuffer(content, UTF_8)); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8"); response.headers().set(HttpHeaders.Names.CACHE_CONTROL, "max-age=31536000, public"); response.headers().set(HttpHeaders.Names.EXPIRES, generateExpires()); final String etag = '\"' + generateMd5(content) + '\"'; response.headers().set(HttpHeaders.Names.ETAG, etag); return response; } } }
Iframe { public static FullHttpResponse response(final SockJsConfig config, final HttpRequest request) throws Exception { final QueryStringDecoder qsd = new QueryStringDecoder(request.getUri()); final String path = qsd.path(); if (!PATH_PATTERN.matcher(path).matches()) { return createResponse(request, NOT_FOUND, copiedBuffer("Not found", UTF_8)); } if (request.headers().contains(HttpHeaders.Names.IF_NONE_MATCH)) { final FullHttpResponse response = createResponse(request, NOT_MODIFIED); response.headers().set(HttpHeaders.Names.SET_COOKIE, "JSESSIONID=dummy; path=/"); return response; } else { final String content = createContent(config.sockJsUrl()); final FullHttpResponse response = createResponse(request, OK, copiedBuffer(content, UTF_8)); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8"); response.headers().set(HttpHeaders.Names.CACHE_CONTROL, "max-age=31536000, public"); response.headers().set(HttpHeaders.Names.EXPIRES, generateExpires()); final String etag = '\"' + generateMd5(content) + '\"'; response.headers().set(HttpHeaders.Names.ETAG, etag); return response; } } private  Iframe(); }
Iframe { public static FullHttpResponse response(final SockJsConfig config, final HttpRequest request) throws Exception { final QueryStringDecoder qsd = new QueryStringDecoder(request.getUri()); final String path = qsd.path(); if (!PATH_PATTERN.matcher(path).matches()) { return createResponse(request, NOT_FOUND, copiedBuffer("Not found", UTF_8)); } if (request.headers().contains(HttpHeaders.Names.IF_NONE_MATCH)) { final FullHttpResponse response = createResponse(request, NOT_MODIFIED); response.headers().set(HttpHeaders.Names.SET_COOKIE, "JSESSIONID=dummy; path=/"); return response; } else { final String content = createContent(config.sockJsUrl()); final FullHttpResponse response = createResponse(request, OK, copiedBuffer(content, UTF_8)); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8"); response.headers().set(HttpHeaders.Names.CACHE_CONTROL, "max-age=31536000, public"); response.headers().set(HttpHeaders.Names.EXPIRES, generateExpires()); final String etag = '\"' + generateMd5(content) + '\"'; response.headers().set(HttpHeaders.Names.ETAG, etag); return response; } } private  Iframe(); static boolean matches(final String path); static FullHttpResponse response(final SockJsConfig config, final HttpRequest request); }
Iframe { public static FullHttpResponse response(final SockJsConfig config, final HttpRequest request) throws Exception { final QueryStringDecoder qsd = new QueryStringDecoder(request.getUri()); final String path = qsd.path(); if (!PATH_PATTERN.matcher(path).matches()) { return createResponse(request, NOT_FOUND, copiedBuffer("Not found", UTF_8)); } if (request.headers().contains(HttpHeaders.Names.IF_NONE_MATCH)) { final FullHttpResponse response = createResponse(request, NOT_MODIFIED); response.headers().set(HttpHeaders.Names.SET_COOKIE, "JSESSIONID=dummy; path=/"); return response; } else { final String content = createContent(config.sockJsUrl()); final FullHttpResponse response = createResponse(request, OK, copiedBuffer(content, UTF_8)); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8"); response.headers().set(HttpHeaders.Names.CACHE_CONTROL, "max-age=31536000, public"); response.headers().set(HttpHeaders.Names.EXPIRES, generateExpires()); final String etag = '\"' + generateMd5(content) + '\"'; response.headers().set(HttpHeaders.Names.ETAG, etag); return response; } } private  Iframe(); static boolean matches(final String path); static FullHttpResponse response(final SockJsConfig config, final HttpRequest request);  }