org.apache.jmeter.protocol.http.util

## Class ConversionUtils

- java.lang.Object
- - org.apache.jmeter.protocol.http.util.ConversionUtils

-     public class ConversionUtils
      extends java.lang.Object

  General purpose conversion utilities related to HTTP/HTML

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConversionUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `escapeIllegalURLCharacters(java.lang.String url)`
    `static java.lang.String` | `getEncodingFromContentType(java.lang.String contentType)` Extract the encoding (charset) from the Content-Type, e.g.
    `static java.net.URL` | `makeRelativeURL(java.net.URL baseURL, java.lang.String location)` Generate an absolute URL from a possibly relative location, allowing for extraneous leading "../" segments.
    `static java.lang.String` | `removeSlashDotDot(java.lang.String url)` collapses absolute or relative URLs containing '/..' converting `http://host/path1/..`
    `static java.net.URI` | `sanitizeUrl(java.net.URL url)` Checks a URL and encodes it if necessary, i.e. if it is not currently correctly encoded.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ConversionUtils

          public ConversionUtils()

  - ### Method Detail

    - #### getEncodingFromContentType

          public static java.lang.String getEncodingFromContentType(java.lang.String contentType)

      Extract the encoding (charset) from the Content-Type, e.g. "text/html; charset=utf-8".
      Parameters:
        `contentType` - string from which the encoding should be extracted
      Returns:
        the charset encoding - or `null`, if none was found or the charset is not supported
      Throws:
        `java.nio.charset.IllegalCharsetNameException` - if the found charset is not supported

    - #### makeRelativeURL

          public static java.net.URL makeRelativeURL(java.net.URL baseURL,
                                                     java.lang.String location)
                                              throws java.net.MalformedURLException

      Generate an absolute URL from a possibly relative location, allowing for extraneous leading "../" segments. The Java `URL.URL(URL, String)` constructor does not remove these.
      Parameters:
        `baseURL` - the base URL which is used to resolve missing protocol/host in the location
        `location` - the location, possibly with extraneous leading "../"
      Returns:
        URL with extraneous ../ removed
      Throws:
        `java.net.MalformedURLException` - when the given `URL` is malformed
      See Also:
        Bug 46690 - handling of 302 redirects with invalid relative paths

    - #### escapeIllegalURLCharacters

          public static java.lang.String escapeIllegalURLCharacters(java.lang.String url)
                                                             throws java.lang.Exception

      Parameters:
        `url` - String Url to escape
      Returns:
        String cleaned up url
      Throws:
        `java.lang.Exception` - when given `url` leads to a malformed URL or URI

    - #### sanitizeUrl

          public static java.net.URI sanitizeUrl(java.net.URL url)
                                          throws java.net.URISyntaxException

      Checks a URL and encodes it if necessary, i.e. if it is not currently correctly encoded. Warning: it may not work on all unencoded URLs.
      Parameters:
        `url` - non-encoded URL
      Returns:
        URI which has been encoded as necessary
      Throws:
        `java.net.URISyntaxException` - if parts of the url form a non valid URI

    - #### removeSlashDotDot

          public static java.lang.String removeSlashDotDot(java.lang.String url)

      collapses absolute or relative URLs containing '/..' converting `http://host/path1/../path2` to `http://host/path2` or `/one/two/../three` to `/one/three`
      Parameters:
        `url` - in which the '/..'s should be removed
      Returns:
        collapsed URL
      See Also:
        Bug 49083 - collapse /.. in redirect URLs

Copyright © 1998-2018 Apache Software Foundation. All Rights Reserved.