@Override public URL resource() { return asset.resource(); }
/** * @return Generate a weak Etag using the {@link #path()}, {@link #lastModified()} and * {@link #length()}. */ @Nonnull default String etag() { try { StringBuilder b = new StringBuilder(32); b.append("W/\""); BaseEncoding b64 = BaseEncoding.base64(); int lhash = resource().toURI().hashCode(); b.append(b64.encode(Longs.toByteArray(lastModified() ^ lhash))); b.append(b64.encode(Longs.toByteArray(length() ^ lhash))); b.append('"'); return b.toString(); } catch (URISyntaxException x) { throw Throwing.sneakyThrow(x); } }
@Override public URL resource() { return asset.resource(); }
/** * @return Generate a weak Etag using the {@link #path()}, {@link #lastModified()} and * {@link #length()}. */ @Nonnull default String etag() { try { StringBuilder b = new StringBuilder(32); b.append("W/\""); BaseEncoding b64 = BaseEncoding.base64(); int lhash = resource().toURI().hashCode(); b.append(b64.encode(Longs.toByteArray(lastModified() ^ lhash))); b.append(b64.encode(Longs.toByteArray(length() ^ lhash))); b.append('"'); return b.toString(); } catch (URISyntaxException x) { throw Throwing.sneakyThrow(x); } }
@Override protected void send(final Request req, final Response rsp, final Asset asset) throws Exception { LessSource.URLSource src = new LessSource.URLSource(asset.resource(), req.charset().name()); CompilationResult result = compiler.compile(src); result.getWarnings().forEach(warning -> log.warn(warning.toString())); if (req.path().endsWith(".map")) { rsp.type(MediaType.json) .send(Results.ok(result.getSourceMap())); } else { rsp.type(MediaType.css) .send(Results.ok(result.getCss())); } } }