Skip to content

Commit

Permalink
Better header handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Jul 25, 2018
1 parent 45e1a1c commit 1d4ea6a
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions src/main/java/io/sinistral/proteus/server/ServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Locale;
import java.util.Map;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
Expand Down Expand Up @@ -89,6 +90,42 @@ public HeaderMap getHeaders()
{
return this.headers;
}

public ServerResponse<T> addHeader(HttpString headerName, String headerValue)
{
this.headers.add(headerName, headerValue);
this.hasHeaders = true;

return this;
}

public ServerResponse<T> addHeader(String headerString, String headerValue)
{
HttpString headerName = HttpString.tryFromString(headerString);

this.headers.add(headerName, headerValue);
this.hasHeaders = true;

return this;
}

public ServerResponse<T> setHeader(HttpString headerName, String headerValue)
{
this.headers.put(headerName, headerValue);
this.hasHeaders = true;

return this;
}

public ServerResponse<T> setHeader(String headerString, String headerValue)
{
HttpString headerName = HttpString.tryFromString(headerString);

this.headers.put(headerName, headerValue);
this.hasHeaders = true;

return this;
}

/**
* @return the contentType
Expand Down Expand Up @@ -188,29 +225,31 @@ public ServerResponse<T> entity(T entity)

public ServerResponse<T> lastModified(Date date)
{
this.headers.add(Headers.LAST_MODIFIED, date.getTime());
this.headers.put(Headers.LAST_MODIFIED, date.getTime());
return this;
}

public ServerResponse<T> contentLanguage(Locale locale)
{
this.headers.add(Headers.CONTENT_LANGUAGE, locale.toLanguageTag());
this.headers.put(Headers.CONTENT_LANGUAGE, locale.toLanguageTag());
return this;
}

public ServerResponse<T> contentLanguage(String language)
{
this.headers.add(Headers.CONTENT_LANGUAGE, language);
this.headers.put(Headers.CONTENT_LANGUAGE, language);
return this;
}

public ServerResponse<T> throwable(Throwable throwable)
{
this.throwable = throwable;

if (this.status == StatusCodes.ACCEPTED)
{
badRequest();
return badRequest(throwable);
}

return this;
}

Expand Down

0 comments on commit 1d4ea6a

Please sign in to comment.