Class HttpRequestFactory


  • public final class HttpRequestFactory
    extends Object
    Thread-safe light-weight HTTP request factory layer on top of the HTTP transport that has an optional HTTP request initializer for initializing requests.

    For example, to use a particular authorization header across all requests, use:

      public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
        return transport.createRequestFactory(new HttpRequestInitializer() {
          public void initialize(HttpRequest request) throws IOException {
            request.getHeaders().setAuthorization("...");
          }
        });
      }
     
    Since:
    1.4
    Author:
    Yaniv Inbar
    • Method Detail

      • getTransport

        public HttpTransport getTransport()
        Returns the HTTP transport.
        Since:
        1.5
      • getInitializer

        public HttpRequestInitializer getInitializer()
        Returns the HTTP request initializer or null for none.

        This initializer is invoked before setting its method, URL, or content.

        Since:
        1.5
      • buildRequest

        public HttpRequest buildRequest​(String requestMethod,
                                        GenericUrl url,
                                        HttpContent content)
                                 throws IOException
        Builds a request for the given HTTP method, URL, and content.
        Parameters:
        requestMethod - HTTP request method
        url - HTTP request URL or null for none
        content - HTTP request content or null for none
        Returns:
        new HTTP request
        Throws:
        IOException
        Since:
        1.12
      • buildDeleteRequest

        public HttpRequest buildDeleteRequest​(GenericUrl url)
                                       throws IOException
        Builds a DELETE request for the given URL.
        Parameters:
        url - HTTP request URL or null for none
        Returns:
        new HTTP request
        Throws:
        IOException
      • buildGetRequest

        public HttpRequest buildGetRequest​(GenericUrl url)
                                    throws IOException
        Builds a GET request for the given URL.
        Parameters:
        url - HTTP request URL or null for none
        Returns:
        new HTTP request
        Throws:
        IOException
      • buildPostRequest

        public HttpRequest buildPostRequest​(GenericUrl url,
                                            HttpContent content)
                                     throws IOException
        Builds a POST request for the given URL and content.
        Parameters:
        url - HTTP request URL or null for none
        content - HTTP request content or null for none
        Returns:
        new HTTP request
        Throws:
        IOException
      • buildPutRequest

        public HttpRequest buildPutRequest​(GenericUrl url,
                                           HttpContent content)
                                    throws IOException
        Builds a PUT request for the given URL and content.
        Parameters:
        url - HTTP request URL or null for none
        content - HTTP request content or null for none
        Returns:
        new HTTP request
        Throws:
        IOException
      • buildPatchRequest

        public HttpRequest buildPatchRequest​(GenericUrl url,
                                             HttpContent content)
                                      throws IOException
        Builds a PATCH request for the given URL and content.
        Parameters:
        url - HTTP request URL or null for none
        content - HTTP request content or null for none
        Returns:
        new HTTP request
        Throws:
        IOException
      • buildHeadRequest

        public HttpRequest buildHeadRequest​(GenericUrl url)
                                     throws IOException
        Builds a HEAD request for the given URL.
        Parameters:
        url - HTTP request URL or null for none
        Returns:
        new HTTP request
        Throws:
        IOException