Forum Discussion

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    HTTP::uri [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end
    

    Take it in bits.

    HTTP::uri - sets (Or gets) the URI for the request. There are 3 HTTP::uri calls in here. The first sets the URI. The second & third are being used to GET the URI and use it as a parameter to the string function.

    string (function). Being used twice

    string range - returns a range (substring) of the supplied parameter.

    string first - returns the index of the first match for the requested substring.

    So...

    [string first "/" [HTTP::uri] 1]
    

    returns the index of the 'first' '/' in the URI (Or -1 if not found) starting at position 1 (i.e. the SECOND character in the URI) - note the start position is important. Specifying 1 for the start position of the URI will normally mean you get the SECOND '/' in the URI since we'd expect it to always start with a '/'

    string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end
    

    returns a substring from the URI that starts at the first '/' that is NOT in the first position of the string, and continues to the end of the URI.

    Effect

    The statement in question is stripping out everything in the URI that is before the second '/'

    e.g.

    /my/url/
    

    would be altered to

    /url/
    

    .