Jump to content
fatih

? in URLs results in HTTP 400

Recommended Posts

Technically, https://test.com?test is an invalid URL, since there is no path included in the URL,

 

Without the query parameter, ICS would add path / automatically, so probably should do so for the query parameter as well, that is what my Firefox browser seems to do.

 

Will fix it next week. 

 

If you want to do it yourself, in THttpCli.DoRequestAsync change:

 

if FPath = '' then FPath := '/';    to 

if Pos('/', FPath) <> 1 then FPath := '/' + FPath;

 

Angus

 

Share this post


Link to post
Posted (edited)
4 hours ago, Angus Robertson said:

Technically, https://test.com?test is an invalid URL, since there is no path included in the URL,

That is not correct.  Technically, the path component is allowed to be empty in any url, per RFC 3986 sections 3 and 3.3:

      URI         = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

      hier-part   = "//" authority path-abempty
                  / path-absolute
                  / path-rootless
                  / path-empty
      path-abempty  = *( "/" segment )
      path-absolute = "/" [ segment-nz *( "/" segment ) ]
      path-noscheme = segment-nz-nc *( "/" segment )
      path-rootless = segment-nz *( "/" segment )
      path-empty    = 0<pchar>

RFC 2616 section 3.2.2 tried to restrict an HTTP url to require a non-empty absolute path if the query component is present:

http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]

But, RFC 2616 section 5.1.2 does allow the path in an HTTP url to be empty:

Quote

Note that the absolute path cannot be empty; if none is present in the original URI, it MUST be given as "/" (the server root).

RFC 7230 sections 2.7.1 and 2.7.2 loosen the restriction to allow the path in HTTP and HTTPS urls to be empty:

     http-URI = "http:" "//" authority path-abempty [ "?" query ]
                [ "#" fragment ]
     https-URI = "https:" "//" authority path-abempty [ "?" query ]
                 [ "#" fragment ]
4 hours ago, Angus Robertson said:

If you want to do it yourself, in THttpCli.DoRequestAsync change:

 

if FPath = '' then FPath := '/';    to 

if Pos('/', FPath) <> 1 then FPath := '/' + FPath;

Why would you an inefficient "Pos" check instead of using something like StartsText() instead?  Or simply: "if (FPath = '') or (FPath[1] <> '/')" ?

Edited by Remy Lebeau
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×