Jump to content
RadStudio 10.3.1 was released today Read more... ×
Stuart Clennett

Error when accessing TMARSNetClient ResponseStatusCode when endpoint is blacklisted

Recommended Posts

Hi,

 

I use Charles proxy's black list function to test my apps response to a blocked connection.    Charles can either return a 403 or just "drop the connection".  

 

When I set Charles to "drop the connection", the call to fHTTPClient.Post  (in TMARSNetClient.Post)  raises an exception and as a result fLastReponse remains nil.   Therefore subsequent calls to TMARSNetClient.ResponseCode or TMARSNetClient.ResponseText raise an Access Violation.

 

I have temporarily patched the code in MARS.Client.Client.Net.pas in the ResponseText & ResponseStatusCode functions by returning 0  (zero) for the response code & an empty string for the response text if the fLastResponse var is unassigned (code below).

 

The exception raised is an ENetHTTPClientException with message "Error receiving data (12152). Server returned an invalid or unrecognized response".

 

Kind regards,

 

Stuart

--

Delphi Berlin 10.1

Windows 10

 

function TMARSNetClient.ResponseStatusCode: Integer;
begin
  if assigned(fLastResponse) then
    Result := FLastResponse.StatusCode
  else
    result := 0;
end;

function TMARSNetClient.ResponseText: string;
begin
  if assigned(FLastResponse) then
    Result := FLastResponse.StatusText
  else
    result := '';
end;

 

Share this post


Link to post

Thanks again for spotting this bug. If you like your contribution to this project to be more visible, please set up a GitHub account (if you haven't yet) and add a pull request for this (or future) corrections. I can obviously apply your changes to MARS but your contribution will not be tracked by GitHub (even if I always try to mention the author in the commit message in this situations).

 

I have merged your changes with this commit ( https://github.com/andrea-magni/MARS/commit/9f45d60e7adb65a36432840baf2cf3e526a8f518 ) and also fixed LastCmdSuccess method. I went for returning -1 in ResponseStatusCode when FLastResponse is not available (rather than zero).

 

BTW I didn't know about Charles proxy ( https://www.charlesproxy.com/ ) I had some troubles configuring WireShark and Fiddler inside a VM but I can see Charles runs perfectly with no clue. Seems very nice so far, thanks!

Share this post


Link to post

Hi Andrea,

 

Thanks for sorting this.  I do have a github account (stuartclennett), but I'm not very familiar with git (aside from commit - push - checkout), so I wouldn't be very confident in dealing with pull-requests as yet.  Thanks for mentioning me though.

 

Should I add any bugs to the github issues directly rather than here in future?

 

Thanks

 

 

Share this post


Link to post
1 hour ago, Stuart Clennett said:

Thanks for sorting this.  I do have a github account (stuartclennett), but I'm not very familiar with git (aside from commit - push - checkout), so I wouldn't be very confident in dealing with pull-requests as yet.  Thanks for mentioning me though.

 

It's easy, basically:

1) fork your copy of MARS repository (stuartclennet/MARS)

2) clone that instead of mine (andrea-magni/MARS)

3) commit your changes there and push to your GitHub repository

4) create a Pull Request (from the GitHub web interface or using other tools, I tend to use the web interface or the TortoiseGit functionalities) and I will have a chance to review your PR and merge it to the official MARS repository

 

This way your contribution will show up both in your account and in the contributors list of MARS official repository.

 

1 hour ago, Stuart Clennett said:

Should I add any bugs to the github issues directly rather than here in future?

 

As you like, I get notified by email when someone post here as well when someone opens a new issue on github.

If it is clearly a bug, then I woul open a github issue, if there's room for discussion maybe I would post here.

 

Thanks.

Sincerely,

Andrea

 

  • 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
×