#1 2021-02-23 08:48:52

uian2000
Member
Registered: 2014-05-06
Posts: 68

HttpGet of mormot2 didn't encode address properly.

Hi ab,

I've used mormot2 as working toolbox.
I've making use of THttpServer as a server, while using TWebBrowser as client.
They can work around very well.

When I fetch some data from THttpServer with HttpGet, Uri.Address was truncated before blank.

I've make an additional step, which might be a default behavior of HttpGet.

var
  uri: TUri;
begin
  if not uri.From(aUrl) then Exit;
  HttpGet(Format('%s://%s:%s/%s',[uri.Schema, uri.Server, uri.Port, UrlEncode(uri.Address)]));
end;

Last edited by uian2000 (2021-02-23 08:52:55)

Offline

#2 2021-02-23 15:32:25

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: HttpGet of mormot2 didn't encode address properly.

I don't understand, HttpGet() already calls TUri.From().

Offline

#3 2021-02-23 16:19:18

uian2000
Member
Registered: 2014-05-06
Posts: 68

Re: HttpGet of mormot2 didn't encode address properly.

Address part of uri was not encoded.

when I make a request like this.

HttpGet('http://127.0.0.1/hello world');

Server side Ctxt.Url will be

'/hello'

But if it was made by a TWebBrowser.Navigate(), that Ctxt.Url will be

'/hello%20world'

Last edited by uian2000 (2021-02-23 16:54:03)

Offline

#4 2021-02-23 17:24:14

tbo
Member
Registered: 2015-04-20
Posts: 335

Re: HttpGet of mormot2 didn't encode address properly.

Try this:

const
  URL_TEMPLATE = 'http://127.0.0.1/%';
var
  content: SockString;  
begin
  content := HttpGet(StringToAnsi7(FormatString(URL_TEMPLATE, ['hello world'])));
...

With best regards
Thomas

Offline

#5 2021-02-23 20:14:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: HttpGet of mormot2 didn't encode address properly.

I am not able to reproduce the problem with mORMot 2.

And there is no SockString type in mORMot 2...

There is something wrong on your side.

Offline

#6 2021-02-23 22:00:42

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: HttpGet of mormot2 didn't encode address properly.

As I understand it, he wants the url passed to the HttpGet method to be encoded automatically.

But this would not be correct, because if the url is already encoded it will be encoded twice.

The correct thing is to leave the url encode for the application and not for the HttpGet and related  methods.

Offline

#7 2021-02-23 22:02:05

uian2000
Member
Registered: 2014-05-06
Posts: 68

Re: HttpGet of mormot2 didn't encode address properly.

thx @tbo, will try your approach.

thx @ab, I've post a sample here
Pastebin-uMain.pas.
Pastebin-uMain.dfm.
pls check it.

Delphi XE,Windows 7 X64

thank you.
big_smile

Last edited by uian2000 (2021-02-24 05:30:50)

Offline

#8 2021-02-24 08:20:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: HttpGet of mormot2 didn't encode address properly.

I still don't get it.

The URI should be properly encoded on client side to work.
If you keep spaces in the URI, then it won't be correct for sure.
HttpGet() don't make any correction, it just passes the supplied value, and 'http://127.0.0.1/Hello World' is not a valid URL.

Offline

#9 2021-02-25 04:21:18

uian2000
Member
Registered: 2014-05-06
Posts: 68

Re: HttpGet of mormot2 didn't encode address properly.

Because TWebBrowser.Navigate() automatically executes UrlEncode, I thought HttpGet should behave the same way.

If httpGet itself is positioned to simply make http requests, that's right.

Offline

#10 2021-02-25 06:28:58

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,544
Website

Re: HttpGet of mormot2 didn't encode address properly.

We should ALWAYS UrlEncode an user input. TWebBrowser.Navigate()  simulates the browser address line where user input address, so it UrlEncode it
In opposite to this HttpGet is called by developer, if developer know address is come from used input he MUST UrlEncode it, if address is a constant in sources and not contains special characters - not.

If HttpGet will UrlEncode address this brake existed code in case argument is already UrlEncoded (as it should be) 

So the current behavior is correct

Offline

#11 2021-02-25 13:30:34

uian2000
Member
Registered: 2014-05-06
Posts: 68

Re: HttpGet of mormot2 didn't encode address properly.

Thank you @mpv, your explanation is very convincing.

Thank you @ab, you've build this awesome framework.

Offline

Board footer

Powered by FluxBB