Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
1310054121
|
|||
49d423915c
|
@@ -6,11 +6,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CorsMiddleware(header []string) gin.HandlerFunc {
|
func CorsMiddleware(allowheader []string, exposeheader []string) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Headers", strings.Join(header, ", "))
|
c.Writer.Header().Set("Access-Control-Allow-Headers", strings.Join(allowheader, ", "))
|
||||||
|
if len(exposeheader) > 0 {
|
||||||
|
c.Writer.Header().Set("Access-Control-Expose-Headers", strings.Join(exposeheader, ", "))
|
||||||
|
}
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, PATCH, DELETE, COUNT")
|
c.Writer.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, PATCH, DELETE, COUNT")
|
||||||
|
|
||||||
if c.Request.Method == "OPTIONS" {
|
if c.Request.Method == "OPTIONS" {
|
||||||
|
@@ -22,6 +22,7 @@ type GinWrapper struct {
|
|||||||
opt Options
|
opt Options
|
||||||
allowCors bool
|
allowCors bool
|
||||||
corsAllowHeader []string
|
corsAllowHeader []string
|
||||||
|
corsExposeHeader []string
|
||||||
ginDebug bool
|
ginDebug bool
|
||||||
bufferBody bool
|
bufferBody bool
|
||||||
requestTimeout time.Duration
|
requestTimeout time.Duration
|
||||||
@@ -43,6 +44,7 @@ type ginRouteSpec struct {
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
AllowCors *bool // Add cors handler to allow all CORS requests on the default http methods
|
AllowCors *bool // Add cors handler to allow all CORS requests on the default http methods
|
||||||
CorsAllowHeader *[]string // override the default values of Access-Control-Allow-Headers (AllowCors must be true)
|
CorsAllowHeader *[]string // override the default values of Access-Control-Allow-Headers (AllowCors must be true)
|
||||||
|
CorsExposeHeader *[]string // return Access-Control-Expose-Headers (AllowCors must be true)
|
||||||
GinDebug *bool // Set gin.debug to true (adds more logs)
|
GinDebug *bool // Set gin.debug to true (adds more logs)
|
||||||
SuppressGinLogs *bool // Suppress our custom gin logs (even if GinDebug == true)
|
SuppressGinLogs *bool // Suppress our custom gin logs (even if GinDebug == true)
|
||||||
BufferBody *bool // Buffers the input body stream, this way the ginext error handler can later include the whole request body
|
BufferBody *bool // Buffers the input body stream, this way the ginext error handler can later include the whole request body
|
||||||
@@ -78,6 +80,7 @@ func NewEngine(opt Options) *GinWrapper {
|
|||||||
suppressGinLogs: langext.Coalesce(opt.SuppressGinLogs, false),
|
suppressGinLogs: langext.Coalesce(opt.SuppressGinLogs, false),
|
||||||
allowCors: langext.Coalesce(opt.AllowCors, false),
|
allowCors: langext.Coalesce(opt.AllowCors, false),
|
||||||
corsAllowHeader: langext.Coalesce(opt.CorsAllowHeader, []string{"Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", "accept", "origin", "Cache-Control", "X-Requested-With"}),
|
corsAllowHeader: langext.Coalesce(opt.CorsAllowHeader, []string{"Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", "accept", "origin", "Cache-Control", "X-Requested-With"}),
|
||||||
|
corsExposeHeader: langext.Coalesce(opt.CorsExposeHeader, []string{}),
|
||||||
ginDebug: ginDebug,
|
ginDebug: ginDebug,
|
||||||
bufferBody: langext.Coalesce(opt.BufferBody, false),
|
bufferBody: langext.Coalesce(opt.BufferBody, false),
|
||||||
requestTimeout: langext.Coalesce(opt.Timeout, 24*time.Hour),
|
requestTimeout: langext.Coalesce(opt.Timeout, 24*time.Hour),
|
||||||
@@ -90,7 +93,7 @@ func NewEngine(opt Options) *GinWrapper {
|
|||||||
engine.RedirectTrailingSlash = false
|
engine.RedirectTrailingSlash = false
|
||||||
|
|
||||||
if wrapper.allowCors {
|
if wrapper.allowCors {
|
||||||
engine.Use(CorsMiddleware(wrapper.corsAllowHeader))
|
engine.Use(CorsMiddleware(wrapper.corsAllowHeader, wrapper.corsExposeHeader))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ginDebug && !wrapper.suppressGinLogs {
|
if ginDebug && !wrapper.suppressGinLogs {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.486"
|
const GoextVersion = "0.0.488"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-07-18T17:29:18+0200"
|
const GoextVersionTimestamp = "2024-07-22T15:16:28+0200"
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -284,6 +285,13 @@ func (b *WPDFBuilder) Image(img *PDFImageRef, opts ...*PDFImageOpt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dataimg.ColorModel() != color.RGBAModel && dataimg.ColorModel() != color.NRGBAModel {
|
||||||
|
// the image cannto be 16bpp or similar - otherwise fpdf errors out
|
||||||
|
dataImgRGBA := image.NewNRGBA(image.Rect(0, 0, dataimg.Bounds().Dx(), dataimg.Bounds().Dy()))
|
||||||
|
draw.Draw(dataImgRGBA, dataImgRGBA.Bounds(), dataimg, dataimg.Bounds().Min, draw.Src)
|
||||||
|
dataimg = dataImgRGBA
|
||||||
|
}
|
||||||
|
|
||||||
bfr, imgMime, err := imageext.EncodeImage(dataimg, compression)
|
bfr, imgMime, err := imageext.EncodeImage(dataimg, compression)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.b.SetError(err)
|
b.b.SetError(err)
|
||||||
|
Reference in New Issue
Block a user