2

环境:Ubuntu 12.04 LTS、Indy 10.5.9 rev 4885、Lazarus 1.0.4 / FPC 2.6.0。

使用我的简单 TIdHTTPServer 测试程序,Web 浏览器只显示最后一个字符 ('!') 而不是应该是 'Hello world!' 的完整响应。

我可以看到在函数ToBytes(IdGlobal.pas 中的第 6059 行)中,传递的 AValue 参数中的文本仍然正确,ASrcEncoding 是 TIdASCIIEncoding 而 ADestEncoding 是“ISO-8559-1”。执行第 6061 行 (LBytes := TIdTextEncoding.Convert(ASrcEncoding, ADestEncoding, LBytes);) 后,LBytes 数组包含 #33 后跟零。

我的示例项目:

program MyHTTPServer;

uses
  cthreads,
  IdHTTPServer, IdCustomHTTPServer, IdContext, IdSocketHandle, IdGlobal,
  SysUtils;

type
  TMyServer = class (TIdHTTPServer)
  public
    procedure InitComponent; override;
    procedure OnGet(AContext: TIdContext;
    ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  end;

procedure Demo;
var
  Server: TMyServer;
begin
  Server := TMyServer.Create(nil);
  try
    Server.Active := True;
    WriteLn('Hit any key to terminate.');
    ReadLn;
  finally
    Server.Free;
  end;
end;

procedure TMyServer.InitComponent;
var
  Binding: TIdSocketHandle;
begin
  inherited;

  OnCommandGet := OnGet;

  Bindings.Clear;
  Binding := Bindings.Add;
  Binding.IP := '127.0.0.1';
  Binding.Port := 8080;
  Binding.IPVersion := Id_IPv4;
end;

procedure TMyServer.OnGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin    
  AResponseInfo.ContentText := 'Hello world!';
end;

begin
  IdGlobal.GIdIconvUseTransliteration := True;

  Demo;
end.
4

1 回答 1

1

The problem is fixed in SVN trunk revision 4889.

于 2012-12-16T11:04:11.097 回答