Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-02

fphttpclient get an url with colon

10 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner

Hi,

When I use TFPHTTPClient to fetch a page with a colon in the file name it appends a slash "/". For example:

  Client:=TFPHTTPClient.Create(nil);
  Response:=TMemoryStream.Create;
  Client.Get('http://wiki.lazarus.freepascal.org/Image:Acs_demos.jpg',Response);

It fetches "/Image:Acs_demos.jpg/".

The / is appended in ParseURI when extracting the document name. For some reason it stops at a colon:

  // now s is 'hier-part' per RFC3986
  // Extract the document name (nasty...)
  for i := Length(s) downto 1 do
    if s[i] = '/' then
    begin
      ...
    end else if s[i] = ':' then
      break
    else
      ...

Why?

Mattias

Reply by email

Unknown author
to Mattias Gaertner
Mattias Gaertner wrote 27 lines
Hi, When I use TFPHTTPClient to fetch a page with a colon in the file name it appends a slash "/". For example: Client:=TFPHTTPClient.Create(nil); Response:=TMemoryStream.Create; Client.Get('http://wiki.lazarus.freepascal.org/Image:Acs_demos.jpg',Response); It fetches "/Image:Acs_demos.jpg/". The / is appended in ParseURI when extracting the document name. For some reason it stops at a colon: // now s is 'hier-part' per RFC3986 // Extract the document name (nasty...) for i := Length(s) downto 1 do if s[i] = '/' then begin ... end else if s[i] = ':' then break else ... Why?

Probably some misguided attempt at handling file:///c:/something

You can remove that code.

Michael.

Reply by email

Unknown author
to Unknown author
Show quoted text 35 lines
On Fri, 17 Feb 2012, Mattias Gaertner wrote: > Hi, > > When I use TFPHTTPClient to fetch a page with a colon in the file name > it appends a slash "/". For example: > > Client:=TFPHTTPClient.Create(nil); > Response:=TMemoryStream.Create; > Client.Get('http://wiki.lazarus.freepascal.org/Image:Acs_demos.jpg',Response); > > It fetches "/Image:Acs_demos.jpg/". > > The / is appended in ParseURI when extracting the document name. For > some reason it stops at a colon: > > // now s is 'hier-part' per RFC3986 > // Extract the document name (nasty...) > > for i := Length(s) downto 1 do > if s[i] = '/' then > begin > ... > end else if s[i] = ':' then > break > else > ... > > Why? Probably some misguided attempt at handling file:///c:/something You can remove that code.

Thinking about it, maybe it was designed to also handle That should be checked.

Michael.

Reply by email

Mattias Gaertner
to Alberto Narduzzi
Show quoted text 5 lines
The fact it appends a slash at the end is probably because it thinks it's a path... But, just out of curiosity... isn't it a malformed *http* url if it contains a colon?

I doubt that mediawiki uses malformed urls.
And any browser and http client uses it without warning.

Mattias

Reply by email

Alberto Narduzzi
to Mattias Gaertner
I doubt that mediawiki uses malformed urls. And any browser and http client uses it without warning.

as I said, it was out of curiosity.

Googling around anyway, shows that there are some special characters out there (obviously), which are meant to compose the url itself: colon, slash, dot, q.mark, ampersand, percent, etc. etc.

To use them in a url for your special purposes, you should at least escape them; if not for anything else, at least for those not-so-smart browsers (or http-client components...).

Try replacing the colon with %3A and see if the component adds a slash at the end as well. It should not IMHO.

Anyway, "http://wiki.lazarus.freepascal.org?Image=Acs_demos.jpg" is not that ugly. Probably it's not so sophisticated, but can do the very same job.

Cheers, A.

Reply by email

Mattias Gaertner
to Alberto Narduzzi
Show quoted text 18 lines
> I doubt that mediawiki uses malformed urls. > And any browser and http client uses it without warning. as I said, it was out of curiosity. Googling around anyway, shows that there are some special characters out there (obviously), which are meant to compose the url itself: colon, slash, dot, q.mark, ampersand, percent, etc. etc. To use them in a url for your special purposes, you should at least escape them; if not for anything else, at least for those not-so-smart browsers (or http-client components...). Try replacing the colon with %3A and see if the component adds a slash at the end as well. It should not IMHO. Anyway, "http://wiki.lazarus.freepascal.org?Image=Acs_demos.jpg" is not that ugly. Probably it's not so sophisticated, but can do the very same job.

Yes, this is a workaround.

But my question is why only the fphttpclient has a problem with colon while all others support it. I hope this can be changed somehow. I don't know if in ParseURI or in fphttpclient.

Mattias

Reply by email

Michael Van Canneyt
to Mattias Gaertner: On Fri, 17 Feb 2012 22:03:25 +0200 Yes, this is a workaround. But my question is why only…
Mattias Gaertner wrote 27 lines
On Fri, 17 Feb 2012 22:03:25 +0200 Alberto Narduzzi wrote: >> I doubt that mediawiki uses malformed urls. >> And any browser and http client uses it without warning. > > as I said, it was out of curiosity. > > Googling around anyway, shows that there are some special characters out > there (obviously), which are meant to compose the url itself: colon, > slash, dot, q.mark, ampersand, percent, etc. etc. > > To use them in a url for your special purposes, you should at least > escape them; if not for anything else, at least for those not-so-smart > browsers (or http-client components...). > > Try replacing the colon with %3A and see if the component adds a slash > at the end as well. It should not IMHO. > > Anyway, "http://wiki.lazarus.freepascal.org?Image=Acs_demos.jpg" is not > that ugly. Probably it's not so sophisticated, but can do the very same job. Yes, this is a workaround. But my question is why only the fphttpclient has a problem with colon while all others support it. I hope this can be changed somehow. I don't know if in ParseURI or in fphttpclient.

ParseURI, most likely.
fphttpclient doesn't do any processing of the URL except passing it to ParseURI.

Michael.

Reply by email