Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition to IMarsRequest #102

Open
gmurt opened this issue Nov 20, 2020 · 8 comments
Open

Addition to IMarsRequest #102

gmurt opened this issue Nov 20, 2020 · 8 comments

Comments

@gmurt
Copy link

gmurt commented Nov 20, 2020

Hi Andrea,

I've just updated my MARS from a very old version (I was 200 commits behind I think!) and I had to make some changes to make my code compatible with the latest source.

My code used 3 properties of TWebRequest which are not available in IMarsRequest. I made the changes below... Is there any chance you could add these into the codebase?

Thanks!,
Graham

MARS.Core.RequestAndResponse.Interfaces

  IMARSRequest = interface
...
    property ContentFields: TStrings read GetContentFields;
    property QueryFields: TStrings read GetQueryFields;
    property RemoteIP: string read GetRemoteIP;
end;

MARS.http.Server.Indy

function TMARSWebRequest.GetQueryFields: TStrings;
begin
  Result := FWebRequest.QueryFields;
end;

function TMARSWebRequest.GetContentFields: TStrings;
begin
  Result := FWebRequest.ContentFields;
end;

function TMARSWebRequest.GetRemoteIP: string;
begin
  Result := FWebRequest.RemoteIP;
end;
@andrea-magni
Copy link
Owner

What about using TArray instead of TStrings? Lifetime management would be easier...

@andrea-magni
Copy link
Owner

I'm also going to add UserAgent.

andrea-magni added a commit that referenced this issue Nov 23, 2020
As pointed out by @gmurt, some data about the request was no longer accessible through IMARSRequest interface.
Added ContentFields, QueryFields, RemoteIP and UserAgent properties to IMARSRequest
andrea-magni added a commit that referenced this issue Nov 23, 2020
As pointed out by @gmurt, some data about the request was no longer accessible through IMARSRequest interface.
Added ContentFields, QueryFields, RemoteIP and UserAgent properties to IMARSRequest
@gmurt
Copy link
Author

gmurt commented Nov 23, 2020

Great! thank you Andrea! I don't know if a TArray would have helped as I use the Names[..] and Values[..] of the TStrings properies which. Thanks for exposing these ;-)

@gmurt gmurt closed this as completed Nov 23, 2020
@andrea-magni
Copy link
Owner

Please let me know if it works as expected.

Example:

    [Context] FReq: IMARSRequest;

 Result :=
    'Content fields: ' + sLineBreak + string.join(sLineBreak, FReq.ContentFields)
  + sLineBreak +
    'Query fields: ' + sLineBreak + string.join(sLineBreak, FReq.QueryFields)
  + sLineBreak +
    'User Agent: ' + FReq.UserAgent
  + sLineBreak +
    'Remote IP: ' + FReq.RemoteIP;

If you need to access data in name/value pairs it will be easy to setup a TStringList and add data with AddStrings method.
Maybe a better option would be to use TPair<string, string> instead of TArray, especially for Query string entries.
What do you think about it?

@andrea-magni andrea-magni reopened this Nov 23, 2020
@gmurt
Copy link
Author

gmurt commented Nov 23, 2020

Apologies, I didn't mean to close the issue.

@gmurt
Copy link
Author

gmurt commented Nov 25, 2020

Hi Andrea,

Sorry, I've only now got around to testing this. I've pulled the latest source and just have a quick question... I have code for pulling values from the query string like this...

ALicCode := ARequest.QueryFields.Values['liccode'];

This is not compatible with the latest changes as QueryFields is now a TArray<>, what's the best way to get the value of a parameter? I'm only now starting to learn and use the power of Generics myself so I'm sure there's an easy way to do this which I'm not seeing.

@gmurt
Copy link
Author

gmurt commented Nov 25, 2020

Ah, forget this, I've just re-read your comment above. So the best option is to copy to a string list in my code? That's fine, just so I know I'm not missing anything obvious.

@gmurt
Copy link
Author

gmurt commented Nov 25, 2020

If it was possible to add the TPair<string,string>or something similar it would help as access by param name in lots of places in my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants