Class HTTPHC4Impl

    • Constructor Detail

    • Method Detail

      • handleMethod

        protected void handleMethod​(String method,
                                    HTTPSampleResult result,
                                    HttpRequestBase httpRequest,
                                    HttpContext localContext)
                             throws IOException
        Calls #sendPostData(HttpPost) if method is POST and #sendEntityData(HttpEntityEnclosingRequestBase) if method is PUT or PATCH

        Field HTTPSampleResult#queryString of result is modified in the 2 cases

        Parameters:
        method - String HTTP method
        result - HTTPSampleResult
        httpRequest - HttpRequestBase
        localContext - HttpContext
        Throws:
        IOException - when posting data fails due to I/O
      • createSampleResult

        protected HTTPSampleResult createSampleResult​(URL url,
                                                      String method)
        Create HTTPSampleResult filling url, method and SampleLabel. Monitor field is computed calling isMonitor()
        Parameters:
        url - URL
        method - HTTP Method
        Returns:
        HTTPSampleResult
      • setupRequest

        protected void setupRequest​(URL url,
                                    HttpRequestBase httpRequest,
                                    HTTPSampleResult res)
                             throws IOException
        Setup following elements on httpRequest:
        • ConnRoutePNames.LOCAL_ADDRESS enabling IP-SPOOFING
        • Socket and connection timeout
        • Redirect handling
        • Keep Alive header or Connection Close
        • Calls setConnectionHeaders to setup headers
        • Calls setConnectionCookie to setup Cookie
        Parameters:
        url - URL of the request
        httpRequest - http request for the request
        res - sample result to set cookies on
        Throws:
        IOException - if hostname/ip to use could not be figured out
      • setDefaultRequestHeaders

        protected void setDefaultRequestHeaders​(HttpRequest request)
        Set any default request headers to include
        Parameters:
        request - the HttpRequest to be used
      • setConnectionCookie

        protected String setConnectionCookie​(HttpRequest request,
                                             URL url,
                                             CookieManager cookieManager)
        Extracts all the required cookies for that particular URL request and sets them in the HttpMethod passed in.
        Parameters:
        request - HttpRequest for the request
        url - URL of the request
        cookieManager - the CookieManager containing all the cookies
        Returns:
        a String containing the cookie details (for the response) May be null
      • setConnectionHeaders

        protected void setConnectionHeaders​(HttpRequestBase request,
                                            URL url,
                                            HeaderManager headerManager,
                                            CacheManager cacheManager)
        Extracts all the required non-cookie headers for that particular URL request and sets them in the HttpMethod passed in
        Parameters:
        request - HttpRequest which represents the request
        url - URL of the URL request
        headerManager - the HeaderManager containing all the cookies for this UrlConfig
        cacheManager - the CacheManager (may be null)
      • sendPostData

        protected String sendPostData​(HttpPost post)
                               throws IOException
        Parameters:
        post - HttpPost
        Returns:
        String posted body if computable
        Throws:
        IOException - if sending the data fails due to I/O
      • sendEntityData

        protected String sendEntityData​(HttpEntityEnclosingRequestBase entity)
                                 throws IOException
        Creates the entity data to be sent.

        If there is a file entry with a non-empty MIME type we use that to set the request Content-Type header, otherwise we default to whatever header is present from a Header Manager.

        If the content charset HTTPAbstractImpl.getContentEncoding() is null or empty we use the HC4 default provided by HTTP#DEF_CONTENT_CHARSET which is ISO-8859-1.

        Parameters:
        entity - to be processed, e.g. PUT or PATCH
        Returns:
        the entity content, may be empty
        Throws:
        UnsupportedEncodingException - for invalid charset name
        IOException - cannot really occur for ByteArrayOutputStream methods
      • getCharsetWithDefault

        protected String getCharsetWithDefault​(HttpParams putParams)
        If contentEncoding is not set by user, then Platform encoding will be used to convert to String
        Parameters:
        putParams - HttpParams
        Returns:
        String charset
      • interrupt

        public boolean interrupt()
        Description copied from interface: Interruptible
        Interrupt the current operation if possible.
        Returns:
        true if there was an operation to interrupt.