org.apache.shindig.gadgets.http
Class HttpRequest

java.lang.Object
  extended by org.apache.shindig.gadgets.http.HttpRequest

public class HttpRequest
extends Object

Creates HttpRequests. A new HttpRequest should be created for every unique HttpRequest being constructed.


Field Summary
static String DOS_PREVENTION_HEADER
          Automatically added to every request so that we know that the request came from our server.
 
Constructor Summary
HttpRequest(HttpRequest request)
          Clone an existing HttpRequest.
HttpRequest(Uri uri)
          Construct a new request for the given uri.
 
Method Summary
 HttpRequest addAllHeaders(Map<String,? extends List<String>> headers)
          Adds all headers in the provided map to the request.
 HttpRequest addHeader(String name, String value)
          Add a single header to the request.
 HttpRequest addHeaders(Map<String,String> headers)
          Adds an entire map of headers to the request.
 boolean equals(Object obj)
           
 AuthType getAuthType()
           
 int getCacheTtl()
           
 String getContainer()
           
 String getContentType()
           
 boolean getFollowRedirects()
           
 Uri getGadget()
           
 String getHeader(String name)
           
 Map<String,List<String>> getHeaders()
           
 List<String> getHeaders(String name)
           
 boolean getIgnoreCache()
           
 String getMethod()
           
 OAuthArguments getOAuthArguments()
           
 String getParam(String paramName)
           
 Integer getParamAsInteger(String paramName)
           
 Map<String,String> getParams()
           
 InputStream getPostBody()
           
 String getPostBodyAsString()
           
 int getPostBodyLength()
          Retrieves the total length of the post body.
 String getRewriteMimeType()
           
 SecurityToken getSecurityToken()
           
 Uri getUri()
           
 int hashCode()
           
 boolean isCajaRequested()
          Should content fetched in response to this request be sanitized based on the specified mime-type
 boolean isSanitizationRequested()
          Should content fetched in response to this request be sanitized based on the specified mime-type
 List<String> removeHeader(String name)
          Remove all headers with the given name from the request.
 HttpRequest setAuthType(AuthType authType)
           
 HttpRequest setCacheTtl(int cacheTtl)
           
 void setCajaRequested(boolean cajaRequested)
           
 HttpRequest setContainer(String container)
           
 HttpRequest setFollowRedirects(boolean followRedirects)
           
 HttpRequest setGadget(Uri gadget)
           
 HttpRequest setHeader(String name, String value)
          Sets a single header value, overwriting any previously set headers with the same name.
 HttpRequest setIgnoreCache(boolean ignoreCache)
           
 HttpRequest setMethod(String method)
           
 HttpRequest setOAuthArguments(OAuthArguments oauthArguments)
           
<T> void
setParam(String paramName, T paramValue)
           
 HttpRequest setPostBody(byte[] postBody)
          Assigns the specified body to the request, copying all input bytes.
 HttpRequest setPostBody(InputStream is)
          Fills in the request body from an InputStream.
 HttpRequest setRewriteMimeType(String rewriteMimeType)
           
 void setSanitizationRequested(boolean sanitizationRequested)
           
 HttpRequest setSecurityToken(SecurityToken securityToken)
          Assign the security token to use for making any form of authenticated request.
 HttpRequest setUri(Uri uri)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DOS_PREVENTION_HEADER

public static final String DOS_PREVENTION_HEADER
Automatically added to every request so that we know that the request came from our server.

See Also:
Constant Field Values
Constructor Detail

HttpRequest

public HttpRequest(Uri uri)
Construct a new request for the given uri.


HttpRequest

public HttpRequest(HttpRequest request)
Clone an existing HttpRequest.

Method Detail

setMethod

public HttpRequest setMethod(String method)

setUri

public HttpRequest setUri(Uri uri)

addHeader

public HttpRequest addHeader(String name,
                             String value)
Add a single header to the request. If a value for the given name is already set, a second value is added. If you wish to overwrite any possible values for a header, use setHeader(String, String).


setHeader

public HttpRequest setHeader(String name,
                             String value)
Sets a single header value, overwriting any previously set headers with the same name.


addHeaders

public HttpRequest addHeaders(Map<String,String> headers)
Adds an entire map of headers to the request.


addAllHeaders

public HttpRequest addAllHeaders(Map<String,? extends List<String>> headers)
Adds all headers in the provided map to the request.


removeHeader

public List<String> removeHeader(String name)
Remove all headers with the given name from the request.

Returns:
Any values that were removed from the request.

setPostBody

public HttpRequest setPostBody(byte[] postBody)
Assigns the specified body to the request, copying all input bytes.


setPostBody

public HttpRequest setPostBody(InputStream is)
                        throws IOException
Fills in the request body from an InputStream.

Throws:
IOException

setIgnoreCache

public HttpRequest setIgnoreCache(boolean ignoreCache)
Parameters:
ignoreCache - Whether to ignore all caching for this request.

isSanitizationRequested

public boolean isSanitizationRequested()
Should content fetched in response to this request be sanitized based on the specified mime-type


setSanitizationRequested

public void setSanitizationRequested(boolean sanitizationRequested)

isCajaRequested

public boolean isCajaRequested()
Should content fetched in response to this request be sanitized based on the specified mime-type


setCajaRequested

public void setCajaRequested(boolean cajaRequested)

setCacheTtl

public HttpRequest setCacheTtl(int cacheTtl)
Parameters:
cacheTtl - The amount of time to cache the result object for, in seconds. If set to -1, HTTP cache control headers will be honored. Otherwise objects will be cached for the time specified.

setGadget

public HttpRequest setGadget(Uri gadget)
Parameters:
gadget - The gadget that caused this HTTP request to be necessary. May be null if the request was not initiated by the actions of a gadget.

setContainer

public HttpRequest setContainer(String container)
Parameters:
container - The container that this request originated from.

setSecurityToken

public HttpRequest setSecurityToken(SecurityToken securityToken)
Assign the security token to use for making any form of authenticated request.


setOAuthArguments

public HttpRequest setOAuthArguments(OAuthArguments oauthArguments)
Parameters:
oauthArguments - arguments for OAuth/signed fetched

setFollowRedirects

public HttpRequest setFollowRedirects(boolean followRedirects)
Parameters:
followRedirects - whether this request should automatically follow redirects.

setAuthType

public HttpRequest setAuthType(AuthType authType)
Parameters:
authType - The type of authentication being used for this request.

setRewriteMimeType

public HttpRequest setRewriteMimeType(String rewriteMimeType)
Parameters:
rewriteMimeType - The assumed content type of the response to be rewritten. Overrides any values set in the Content-Type response header. TODO: Move this to new rewriting facility.

getMethod

public String getMethod()

getUri

public Uri getUri()

getHeaders

public Map<String,List<String>> getHeaders()
Returns:
All headers to be sent in this request.

getHeaders

public List<String> getHeaders(String name)
Parameters:
name - The header to fetch
Returns:
A list of headers with that name (may be empty).

getHeader

public String getHeader(String name)
Returns:
The first set header with the given name or null if not set. If you need multiple values for the header, use getHeaders().

getContentType

public String getContentType()
Returns:
The content type of the request (determined from request headers)

getPostBody

public InputStream getPostBody()
Returns:
An input stream that can be used to read the post body.

getPostBodyAsString

public String getPostBodyAsString()
Returns:
The post body as a string, assuming UTF-8 encoding. TODO: We should probably tolerate other encodings, based on the Content-Type header.

getPostBodyLength

public int getPostBodyLength()
Retrieves the total length of the post body.

Returns:
The length of the post body.

getIgnoreCache

public boolean getIgnoreCache()
Returns:
True if caching should be ignored for this request.

getCacheTtl

public int getCacheTtl()
Returns:
The amount of time to cache any response objects for, in seconds.

getGadget

public Uri getGadget()
Returns:
The uri of gadget responsible for making this request.

getParam

public String getParam(String paramName)

getParamAsInteger

public Integer getParamAsInteger(String paramName)

setParam

public <T> void setParam(String paramName,
                         T paramValue)

getParams

public Map<String,String> getParams()

getContainer

public String getContainer()
Returns:
The container responsible for making this request.

getSecurityToken

public SecurityToken getSecurityToken()
Returns:
The security token used to make this request.

getOAuthArguments

public OAuthArguments getOAuthArguments()
Returns:
arguments for OAuth and signed fetch

getFollowRedirects

public boolean getFollowRedirects()
Returns:
true if redirects should be followed.

getAuthType

public AuthType getAuthType()
Returns:
The type of authentication being used for this request.

getRewriteMimeType

public String getRewriteMimeType()
Returns:
The content type to assume when rewriting. TODO: Move this to new rewriting facility.

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2007-2012. All Rights Reserved.