All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webbitserver.HttpResponse Maven / Gradle / Ivy

There is a newer version: 0.4.15
Show newest version
package org.webbitserver;

import java.net.HttpCookie;
import java.nio.charset.Charset;

/**
 * Writes a response back to the client.
 * 

* IMPORTANT: The connection will remain open until {@link #end()} or {@link #error(Throwable)} is called. Don't * forget these! * * @author Joe Walnes */ public interface HttpResponse { String SET_COOKIE_HEADER = "Set-Cookie"; /** * For text based responses, sets the Charset to encode the response as. *

* If not set, defaults to UTF8. */ HttpResponse charset(Charset charset); /** * Current Charset used to encode to response as. * * @see #charset(Charset) */ Charset charset(); /** * Sets the HTTP status code. *

* Defaults to 200 (OK). */ HttpResponse status(int status); /** * Retrieve HTTP status code that this response is going to return. * * @see #status(int) */ int status(); /** * Adds an HTTP header. Multiple HTTP headers can be added with the same name. */ HttpResponse header(String name, String value); /** * Adds a numeric HTTP header. Multiple HTTP headers can be added with the same name. */ HttpResponse header(String name, long value); /** * Adds a cookie * * @param httpCookie the cookie */ HttpResponse cookie(HttpCookie httpCookie); /** * Write text based content back to the client. * * @see #charset(Charset) * @see #content(byte[]) */ HttpResponse content(String content); /** * Writes immediately to the client without closing the connection. * (The {@link #content(String)} method caches content until {@link #end()} is called() *

* TODO: Make content write immediately instead and remove this method? * * @param content what to write */ HttpResponse write(String content); /** * Write binary based content back to the client. * * @see #content(String) */ HttpResponse content(byte[] content); /** * Marks the response as erroneous. The error shall be displayed to the user (500 SERVER ERROR) * and the connection closed. *

* Every response should have either {@link #end()} or {@link #error(Throwable)} called. No more * operations should be performed on a response after these. */ HttpResponse error(Throwable error); /** * Marks the response as ended. At this point any remaining data shall be flushed and * the connection closed. *

* Every response should have either {@link #end()} or {@link #error(Throwable)} called. No more * operations should be performed on a response after these. */ HttpResponse end(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy