Class LowLevelHttpRequest

java.lang.Object
com.google.api.client.http.LowLevelHttpRequest
Direct Known Subclasses:
ApacheHttpRequest, HttpHeaders.HeaderParsingFakeLevelHttpRequest, MockLowLevelHttpRequest, NetHttpRequest

public abstract class LowLevelHttpRequest extends Object
Low-level HTTP request.

This allows providing a different implementation of the HTTP request that is more compatible with the Java environment used.

Implementation has no fields and therefore thread-safe, but sub-classes are not necessarily thread-safe.

Since:
1.0
  • Field Details

    • contentLength

      private long contentLength
      Content length or less than zero if not known.
    • contentEncoding

      private String contentEncoding
      Content encoding (for example "gzip") or null for none.
    • contentType

      private String contentType
      Content type or null for none.
    • streamingContent

      private StreamingContent streamingContent
      Streaming content or null for no content.
  • Constructor Details

    • LowLevelHttpRequest

      public LowLevelHttpRequest()
  • Method Details

    • addHeader

      public abstract void addHeader(String name, String value) throws IOException
      Adds a header to the HTTP request.

      Note that multiple headers of the same name need to be supported, in which case addHeader(java.lang.String, java.lang.String) will be called for each instance of the header.

      Parameters:
      name - header name
      value - header value
      Throws:
      IOException
    • setContentLength

      public final void setContentLength(long contentLength) throws IOException
      Sets the content length or less than zero if not known.

      Default value is -1.

      Throws:
      IOException - I/O exception
      Since:
      1.14
    • getContentLength

      public final long getContentLength()
      Returns the content length or less than zero if not known.
      Since:
      1.14
    • setContentEncoding

      public final void setContentEncoding(String contentEncoding) throws IOException
      Sets the content encoding (for example "gzip") or null for none.
      Throws:
      IOException - I/O exception
      Since:
      1.14
    • getContentEncoding

      public final String getContentEncoding()
      Returns the content encoding (for example "gzip") or null for none.
      Since:
      1.14
    • setContentType

      public final void setContentType(String contentType) throws IOException
      Sets the content type or null for none.
      Throws:
      IOException - I/O exception
      Since:
      1.14
    • getContentType

      public final String getContentType()
      Returns the content type or null for none.
      Since:
      1.14
    • setStreamingContent

      public final void setStreamingContent(StreamingContent streamingContent) throws IOException
      Sets the streaming content or null for no content.
      Throws:
      IOException - I/O exception
      Since:
      1.14
    • getStreamingContent

      public final StreamingContent getStreamingContent()
      Returns the streaming content or null for no content.
      Since:
      1.14
    • setTimeout

      public void setTimeout(int connectTimeout, int readTimeout) throws IOException
      Sets the connection and read timeouts.

      Default implementation does nothing, but subclasses should normally override.

      Parameters:
      connectTimeout - timeout in milliseconds to establish a connection or 0 for an infinite timeout
      readTimeout - Timeout in milliseconds to read data from an established connection or 0 for an infinite timeout
      Throws:
      IOException - I/O exception
      Since:
      1.4
    • execute

      public abstract LowLevelHttpResponse execute() throws IOException
      Executes the request and returns a low-level HTTP response object.
      Throws:
      IOException