开发者

Indy IdHTTPServer GET response parameters randomly missing

开发者 https://www.devze.com 2023-03-27 01:34 出处:网络
I\'m writing a Delphi-based Windows server for a tablet-based HTML client. Most files are served out unprocessed, as you would expect of a web server, but a handful of special keywords are being inte

I'm writing a Delphi-based Windows server for a tablet-based HTML client.

Most files are served out unprocessed, as you would expect of a web server, but a handful of special keywords are being interpreted as special commands that interface with other software on the server.

Most of the time, everything is fine. But then, seemingly at random, I'd get an access violation, and it would be while trying to retrieve one of the GET parameters.

This was driving me mad, so I encapsulated the entire thing down into a function and just started testing for the existence of the TIdHTTPRequestInfo data (shown here as the public property Request inside the class):

function TELSCommand.GETValue(key:AnsiString):AnsiString;
begin
    if not Assigned(Request) then begin
        Log.e('WHERE IS REQUEST?');
        Result := '';
        Exit;
    end;

    if not Assigned(Request.Params) then begin
        Log.e('WHERE IS REQUEST PARAMS?');
        Result := '';
        Exit;
    end;

    if (Request.Params.IndexOfName(key) >= 0) then
        Result := Request.Params.Values[key]
    else
        Result := '';
end;

I didn't actually expect either of the two Assigned() checks to get triggered, but, randomly, the second one will get tripped, and I'll see "WHERE IS REQUEST PARAMS?" in my log file after hitting F5 (slowly, I'm not hammering the server).

When I throw down a breakpoint inside the block and inspect the value of Request when it hits that point, the entire TIdHTTPRequestInfo structure is filled with default, empty data. If I check the browser to see what request it sent, it's what I would expect... (generally just a request for "/details?id=222", for example).

I should note that I'm developing on Windows 开发者_JAVA技巧7 64-bit, so I'm constantly paranoid of things like this being caused by it. More than once I've hit snags that turned out to be because of 64-bit wackiness.

Additional info: Indy 9, Delphi 2007.

Hopefully this was clear enough to understand. I'm not looking for specific answers, since I haven't provided nearly enough; I'm just looking for suggestions on where to go from here. Much appreciated! :)


RequestInfo.Params is created in the Constructor and there's a FreeAndNil() in the Destructor so once the Request is Free'd, the Assigned() will fail on this property.

Given that, and based on the confused info of your scenario, I would assume you have some threading issues where you are referencing a dangling Request instance that isn't yet NIL'ed but the Params property has been. Sometimes you get lucky and it works, and sometimes it blows an AV.

Alternately, you are manually NIL'ing the .Params property somehow in your code. Perhaps you are passing this TStringList object around and something else is releasing it accidentally. Indy won't be free'ing this until the Request is done.

All and all, you are correct as you haven't provided enough information and the question should probably be closed.

0

精彩评论

暂无评论...
验证码 换一张
取 消