#1 mORMot 1 » How lengthy reads should be processed with THttpClientSocket » 2019-02-07 12:03:09

egold2005
Replies: 1

I am still trying to get any meaningful help on this wonderful resource....

How do i use THttpClientSocket when overring TSqlHttpServer.Request method to create a kind of proxy?

       FClient := THttpClientSocket.Open('localhost', '8095');

       result := FClient.Request(Ctxt.URL, Ctxt.Method, 10000, Ctxt.InHeaders, Ctxt.InContent, Ctxt.InContentType, TRUE);

       Ctxt.OutContent := FClient.Content;
       Ctxt.OutContentType := FClient.ContentType;

       Ctxt.OutCustomHeaders := '';
       for vIdx := Low(FClient.Headers) to High(FClient.Headers) do
          Ctxt.OutCustomHeaders := Ctxt.OutCustomHeaders + #13#10 + FClient.Headers[vIdx];


The end point services are RESTful services, i need to be able to handle GET/POST/DELETE etc

The code above works fine for small responses, but when it comes to lengthy datasets returns it seems the response data never gets through.

Should i somehow create a loop to add to Ctxt.OutContent or it should be handled in some other way?

#2 Re: mORMot 1 » THttpClientSocket.Content is empty after POST request » 2019-02-06 13:29:02

ab wrote:

Your headers are missing a #13#10 between the lines.

Is it what you mean? This does not work properly either...

       Ctxt.OutCustomHeaders := '';
       for vIdx := Low(vClient.Headers) to High(vClient.Headers) do
          Ctxt.OutCustomHeaders := Ctxt.OutCustomHeaders + #13#10 + vClient.Headers[vIdx];

#3 mORMot 1 » THttpClientSocket.Content is empty after POST request » 2019-02-05 12:35:52

egold2005
Replies: 2

Hello,

I am testing the framework for the purpose of creating a proxy server to a number of internal REST services.

I am overriding TSqlHttpServer.Request method with the following code

    vURL := Ctxt.URL;
    GetServiceConnectionPoint(vURL, vAddress, vPort);
    vClient := THttpClientSocket.Open(vAddress, vPort);
    try
       result := vClient.Request(Ctxt.URL, Ctxt.Method, 5000, Ctxt.InHeaders, Ctxt.InContent, Ctxt.InContentType, TRUE);
       Ctxt.OutContent := vClient.Content;
       Ctxt.OutContentType := vClient.ContentType;

       Ctxt.OutCustomHeaders := '';
       for vIdx := Low(vClient.Headers) to High(vClient.Headers) do
          Ctxt.OutCustomHeaders := Ctxt.OutCustomHeaders + vClient.Headers[vIdx];
    finally
      vClient.free;
    end;

This works fine for a number of scenarios like .Get and .Delete, but it does not return anything in .Content for some POST requests, while the end point does return the content.

Any advice, other than read the docs and samples (i did that already).

Thanx alot.

#4 Re: mORMot 1 » Basic authorization with THttpClientSocket » 2019-02-04 08:41:55

I can not find any references to THttpClientSocket, neither in documentation nor samples.

What is the proper flow of method calls?

Should i use .Open constructor to specify the IP and port of the server and then use .Get and pass auth?

I end up with 505 error and i now see this is being raised inside THttpClientSocket.Request method.

#5 mORMot 1 » Error 505 with THttpClientSocket » 2019-02-01 14:41:17

egold2005
Replies: 0

Hello,

I am using the following code to make a request and getting error 505

    vBase64 := TBase64Encoding.Create;
    try
      vUsername := 'Dispatch';
      vPassword := '1234';
      vLogin := vUsername + ':' + vPassword;
      vAuth := 'Authorization: Bearer ' + vBase64.Encode(vLogin);
    finally
      vBase64.Free
    end;

    FClient.Open('127.0.0.1', '8095', cslTCP, 0, FALSE);

    //FClient.HeaderAdd(vAuth);
    result := FClient.Get(vURL, 5000, vAuth);

With setup like this, do i get HTTP 1.1 request or do i need some other settings?

Thanx,

#6 Re: mORMot 1 » Overriding TSQLHttpServer.Request method » 2019-01-31 12:03:00

ab wrote:

If you want to handle several /root1/... /root2/.. and so on, then TSQLHttpServer.Request is where to override.

This is exactly what i need and seems like i figured it out correctly.

I am using internal THttpClientSocket to communicate to end points. What is the proper flow of methods when working with it, should i call .Open first?

Basically i am trying to get the following code working in Request

    result := FClient.Get(vURL);
    Ctxt.OutContent := FClient.Content;
    Ctxt.OutContentType := FClient.ContentType;

But this is for GET method, should i use similar structures for others?

When i connect to end point in browser it opens up auth dialog so i can supply username/password.

Are these being usually handled in PUT? Sorry this is not essentially a framework questions, but rather HTTP-related in general....

Thanx alot.

#7 Re: mORMot 1 » Basic authorization with THttpClientSocket » 2019-01-31 11:29:10

pvn0 wrote:

Why are you not using the default available authentication classes?

Because i have no idea about the framework yet and the classes it offers.

What classes should i use? Any sample code available?

Thanx.

#8 Re: mORMot 1 » Overriding TSQLHttpServer.Request method » 2019-01-31 10:16:59

ab wrote:

I would rather combine the proxy at TSQLRestServer.URI level, not at HTTP level.

As i said i am completely new to the framework, so this says nothing to me actually...

Why would i better do it this way? What methods should i override etc?

Thanks.

#9 mORMot 1 » Basic authorization with THttpClientSocket » 2019-01-30 13:40:15

egold2005
Replies: 5

I am new to this stuff and trying to pass login/password.

Should i do that before calling .Open?

    vUsername := 'Dispatch';
    vPassword := '1234';
    vLogin := vUsername + ':' + vPassword;

    vBase64 := TBase64Encoding.Create;
    try
      vAuth := 'Authorization: Basic ' + vBase64.Encode(vLogin);
    finally
      vBase64.Free
    end;

    FClient.HeaderAdd(vAuth);
    FClient.Open('127.0.0.1', '8095');

    result := FClient.Get(vURL);

Thanx alot.

#10 mORMot 1 » Overriding TSQLHttpServer.Request method » 2019-01-30 12:35:42

egold2005
Replies: 4

Hello,

I am about to create a kind of proxy-service for a number of internal REST services, so this proxy would act as single entry point.

I determined i have to override TSQLHttpServer.Request method for that, is this approach feasible?

If so, i would need a client-side component to make a request to internal REST services and return the results to the caller.

Is there such a component in the framework? Any advice and sample code are greatly appreciated.

Thanx,
Eugene.

#11 Re: mORMot 1 » Basic non-SQL RESTful service with mORMot » 2019-01-29 11:15:53

Okay, I have found 04 - HTTP Client-Server sample and I think this will get me started in correct direction.

#12 Re: mORMot 1 » Basic non-SQL RESTful service with mORMot » 2019-01-29 10:55:23

Okay, so for "better design" I inherit from TSQLRestServerFullMemory then, right?


What method do I override to deal with URI and redirect based on certain keywords found?

Also can I avoid "root" and have it like http://localhost:888/id1 etc?


Thank you.

#13 Re: mORMot 1 » Basic non-SQL RESTful service with mORMot » 2019-01-29 09:28:12

Is there any demos/sample code available?


I am studying the docs and determined it would make sense to use TSQLRestServerRemoteDB to create a proxy, but the docs do not give enough information to get into that stuff...

#14 Re: mORMot 1 » Basic non-SQL RESTful service with mORMot » 2019-01-28 13:59:26

Thank you, I got it running.

Now when I hit it at http://127.0.0.1:888/root I get

{
"errorCode":400,
"errorText":"Bad Request"
}

Where do I put the server logic?

Basically what I want to do is, determine the URI part, like "root" or "id1" or "id2" etc, and based on that ID to pass the request to another URL.

How do I go about that?

Thanx once again!

#15 Re: mORMot 1 » Basic non-SQL RESTful service with mORMot » 2019-01-28 13:36:50

I modified the sample code like this. I do not have TSQLServerFullMemory class in my installation it seems...

When I run this, I get Access is denied. I think this is something to do with permissions....

#16 mORMot 1 » Basic non-SQL RESTful service with mORMot » 2019-01-28 12:17:32

egold2005
Replies: 9

Hello,

I am new to this stuff and I am about to create a kind of proxy RESTful service with mORMot.

I saw some sample code and it always refers TSQLHttpServer component.

Is there a way I can create non-SQL server?

Any suggestions are greatly appreciated.

Thanx a lot.

Board footer

Powered by FluxBB