Diocp HTTPServer 支持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;

  

 

posted @ 2022-01-14 00:12  似水@流年  阅读(74)  评论(0编辑  收藏  举报
悠悠记得当天笑 仿佛入迷 又带一点惘 种种喜悦 令人为你鼓掌 眉飞色舞千千样 你是个妙人 是个少年狂