Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Problemas ao responder arquivos estáticos #379

Open
Labels
bugSomething isn't working

Description

Bom dia !

Estamos utilizando o horse para responder arquivos estáticos para a pagina de origem, ao qual respondemos enviando a Stream no Response.

Mas como temos referencia a 10+ arquivos, aleatoriamente, ocorre a exceção: EIdSocketError Software caused connection abort, e mesmo as vezes não ocorrendo este erro, também aleatoriamente, alguns dos arquivos estáticos não são carregados e não ocorre erro algum.

Tentamos utilizar o middleware ServerStatic, mas ocorre a mesma situação.

image

Abaixo segue o fonte implementado:

.Use( procedure (Req: THorseRequest; Res: THorseResponse; Next: TProc) begin // Verifique se a solicitação é para um arquivo estático if StartsText('/Paginas/', Req.RawWebRequest.PathInfo) then begin var FileName := ReplaceStr(ExtractFilePath(ParamStr(0)) + Req.RawWebRequest.PathInfo,'/','\'); // Verifique se o arquivo solicitado existe if FileExists(FileName) then begin // Abra o arquivo solicitado e envie seu conteúdo como resposta var FileStream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone); try Res.RawWebResponse.ContentType := MIMETypeFromFile(FileName); //Delimita quanto tempo o arquivo vai ser mantido em cache em segundos Res.RawWebResponse.SetCustomHeader('Cache-Control', 'max-age=3600'); Res.RawWebResponse.ContentStream := FileStream; Res.RawWebResponse.StatusCode := 200; Res.Status(THTTPStatus.OK); Res.RawWebResponse.SendResponse; except on E: Exception do begin FileStream.Free; Res.RawWebResponse.StatusCode := 500; Res.Status(THTTPStatus.InternalServerError); Res.Send('Erro ao servir arquivo estático: ' + E.Message); end; end; end else begin // Se o arquivo não existir, retorne um erro 404 (Não encontrado) Res.RawWebResponse.StatusCode := 404; Res.Status(THTTPStatus.NotFound); Res.Send('Arquivo não encontrado'); end; end; end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /