@Override public synchronized void close() { flush(); resp.terminatingChunk(); closed = true; }
private Resp respOrNull(MaybeReq maybeReq) { ReqImpl req = (ReqImpl) maybeReq.getReqOrNull(); if (req != null && req.hasResponseAttached()) { return req.response(); } else { return null; } }
private HTTPCacheKey createCacheKey() { return isCacheable() ? new HTTPCacheKey(host(), uri()) : null; }
private void renderResponseOrError() { String err = validateResponse(); if (err != null) { doRendering(500, new RespBodyBytes(err.getBytes())); } else { renderResponse(); } }
private RouteOptions opts(MediaType contentType) { // don't change if already customized if (options.contentType() == null || !options.contentTypeCustomized()) { options.contentType(contentType); } return options; }
void startChunkedOutputStream() { req.doRendering(code(), null); }
@Override public synchronized Resp response() { if (response == null) { response = new RespImpl(this); if (defaultContentType != null) { response.contentType(defaultContentType); } } return response; }
void doRendering(int code, RespBody body) { if (!isRendering()) { synchronized (this) { if (!isRendering()) { respond(code, body); } } } }
@Override public synchronized Resp file(File file) { ensureCanChange(); this.file = file; return this; }
public FastHttp(HttpRoutesImpl routes, @SuppressWarnings("unused") Config serverConfig, Screen gui) { super(null); this.routes = routes; this.gui = gui; routes.setHttp(this); }
@Override public synchronized Req done() { if (!done) { onDone(); done = true; } return this; }
@Override public Resp done() { req.done(); return this; }
@Override public Screen screen() { if (screen == null) { synchronized (this) { if (screen == null) { screen = createScreen(); } } } return screen; }
@Override public Setup deregister(String verb, String path) { routes.remove(verb, path); return this; }
@Override public Map<String, Object> posted() { if (pendingBodyParsing) { synchronized (this) { if (pendingBodyParsing) { pendingBodyParsing = false; parseRequestBody(); } } } return posted; }
@Override public synchronized Resp body(ByteBuffer body) { ensureCanChange(); this.body = body; return this; }
@Override public synchronized Resp raw(byte[] raw) { ensureCanChange(); this.raw = raw; return this; }
@Override public synchronized Resp body(byte[] body) { ensureCanChange(); this.body = body; return this; }
@Override public synchronized Resp filename(String filename) { ensureCanChange(); this.filename = filename; return this; }