mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
handle serve raw case
This commit is contained in:
parent
8dac935cd8
commit
40478215d0
4 changed files with 56 additions and 43 deletions
|
@ -19,6 +19,8 @@ const (
|
|||
headerETag = "ETag"
|
||||
headerLastModified = "Last-Modified"
|
||||
headerIfModifiedSince = "If-Modified-Since"
|
||||
|
||||
rawMime = "text/plain; charset=utf-8"
|
||||
)
|
||||
|
||||
// upstreamIndexPages lists pages that may be considered as index pages for directories.
|
||||
|
@ -41,13 +43,13 @@ type Options struct {
|
|||
// Used for debugging purposes.
|
||||
Host string
|
||||
|
||||
DefaultMimeType string
|
||||
ForbiddenMimeTypes map[string]bool
|
||||
TryIndexPages bool
|
||||
BranchTimestamp time.Time
|
||||
TryIndexPages bool
|
||||
BranchTimestamp time.Time
|
||||
// internal
|
||||
appendTrailingSlash bool
|
||||
redirectIfExists string
|
||||
|
||||
ServeRaw bool
|
||||
}
|
||||
|
||||
// Upstream requests a file from the Gitea API at GiteaRoot and writes it to the request context.
|
||||
|
@ -80,7 +82,10 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client) (fin
|
|||
}
|
||||
log.Debug().Msg("preparations")
|
||||
|
||||
reader, res, err := giteaClient.ServeRawContent(o.generateUriClientArgs())
|
||||
reader, res, err := giteaClient.ServeRawContent(o.TargetOwner, o.TargetRepo, o.TargetBranch, o.TargetPath)
|
||||
if reader != nil {
|
||||
defer reader.Close()
|
||||
}
|
||||
log.Debug().Msg("acquisition")
|
||||
|
||||
// Handle errors
|
||||
|
@ -142,13 +147,14 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client) (fin
|
|||
}
|
||||
log.Debug().Msg("error handling")
|
||||
|
||||
// Set the MIME type
|
||||
mimeType := o.getMimeTypeByExtension()
|
||||
ctx.Response().Header.Set(headerContentType, mimeType)
|
||||
|
||||
// Set ETag
|
||||
// Set ETag & MIME
|
||||
if res != nil {
|
||||
ctx.Response().Header.Set(headerETag, res.Header.Get(headerETag))
|
||||
if o.ServeRaw {
|
||||
ctx.Response().Header.Set(headerContentType, res.Header.Get(headerContentType))
|
||||
} else {
|
||||
ctx.Response().Header.Set(headerContentType, rawMime)
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.Response().StatusCode != http.StatusNotFound {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue