Diocp HTTPServer 支持SVG(Diocp httpserver supports SVG)

Diocp是一个很强大,很稳定的服务端,但是里面的HTTPServer并不支持SVG文件,这里记录一下,以免以后忘记了

diocp_ex_http_common.pas 单元的GetContentTypeFromFileExt函数,改为以下代码

function GetContentTypeFromFileExt(const pvFileExt, pvDefault: string): String;
var
  lvExt: String;
begin
  lvExt := LowerCase(pvFileExt);
  ///新增对svg的支持
{$REGION '支持svg文件'}
  if lvExt = '.svg' then
  begin
    Result := 'image/svg+xml';
  end else
{$ENDREGION}

  if lvExt = '.js' then
  begin
    Result := 'application/javascript';
  end
  else if lvExt = '.css' then
  begin
    Result := 'text/css';
  end else if lvExt = '.apk' then
  begin
    Result := 'application/vnd.android.package-archive'
  end
  else if lvExt = '.json' then
  begin
    Result := 'application/json;charset=UTF-8';
  end
  else if (lvExt = '.html') or (lvExt = '.htm') then
  begin
    Result := 'text/html;charset=UTF-8';
  end
  else if (lvExt = '.jpg') or (lvExt = '.jpeg') then
  begin
    Result := 'image/jpeg';
  end
  else if (lvExt = '.gif') then
  begin
    Result := 'image/gif';
  end
  else if (lvExt = '.png') then
  begin
    Result := 'image/png';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.m3u', -1) = 0 then
  begin
    Result := 'audio/mpegurl';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.mp3', -1) = 0 then
  begin
    Result := 'audio/mp3';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.mp4', -1) = 0 then
  begin
    Result := 'audio/mp4';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.wma', -1) = 0 then
  begin
    Result := 'audio/wma';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.wav', -1) = 0 then
  begin
    Result := 'audio/wav';

  end
  else
  begin
    Result := pvDefault;
  end;
end;
————————

Diocp is a very powerful and stable server, but the HTTP server inside does not support SVG files. Record it here to avoid forgetting it in the future

diocp_ex_http_common.pas 单元的GetContentTypeFromFileExt函数,改为以下代码

function GetContentTypeFromFileExt(const pvFileExt, pvDefault: string): String;
var
  lvExt: String;
begin
  lvExt := LowerCase(pvFileExt);
  ///新增对svg的支持
{$REGION '支持svg文件'}
  if lvExt = '.svg' then
  begin
    Result := 'image/svg+xml';
  end else
{$ENDREGION}

  if lvExt = '.js' then
  begin
    Result := 'application/javascript';
  end
  else if lvExt = '.css' then
  begin
    Result := 'text/css';
  end else if lvExt = '.apk' then
  begin
    Result := 'application/vnd.android.package-archive'
  end
  else if lvExt = '.json' then
  begin
    Result := 'application/json;charset=UTF-8';
  end
  else if (lvExt = '.html') or (lvExt = '.htm') then
  begin
    Result := 'text/html;charset=UTF-8';
  end
  else if (lvExt = '.jpg') or (lvExt = '.jpeg') then
  begin
    Result := 'image/jpeg';
  end
  else if (lvExt = '.gif') then
  begin
    Result := 'image/gif';
  end
  else if (lvExt = '.png') then
  begin
    Result := 'image/png';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.m3u', -1) = 0 then
  begin
    Result := 'audio/mpegurl';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.mp3', -1) = 0 then
  begin
    Result := 'audio/mp3';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.mp4', -1) = 0 then
  begin
    Result := 'audio/mp4';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.wma', -1) = 0 then
  begin
    Result := 'audio/wma';
  end else if CompareStrIgnoreCase(PChar(lvExt), '.wav', -1) = 0 then
  begin
    Result := 'audio/wav';

  end
  else
  begin
    Result := pvDefault;
  end;
end;