Content Types and Respose fixes for restheadpsec

This commit is contained in:
Hein 2025-11-07 10:55:42 +02:00
parent eefed23766
commit 1adca4c49b
2 changed files with 23 additions and 22 deletions

View File

@ -695,7 +695,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
if options.CleanJSON { if options.CleanJSON {
data = h.cleanJSON(data) data = h.cleanJSON(data)
} }
w.SetHeader("Content-Type", "application/json")
// Format response based on response format option // Format response based on response format option
switch options.ResponseFormat { switch options.ResponseFormat {
case "simple": case "simple":

View File

@ -19,21 +19,21 @@ type ExtendedRequestOptions struct {
CleanJSON bool CleanJSON bool
// Advanced filtering // Advanced filtering
SearchColumns []string SearchColumns []string
CustomSQLWhere string CustomSQLWhere string
CustomSQLOr string CustomSQLOr string
// Joins // Joins
Expand []ExpandOption Expand []ExpandOption
// Advanced features // Advanced features
AdvancedSQL map[string]string // Column -> SQL expression AdvancedSQL map[string]string // Column -> SQL expression
ComputedQL map[string]string // Column -> CQL expression ComputedQL map[string]string // Column -> CQL expression
Distinct bool Distinct bool
SkipCount bool SkipCount bool
SkipCache bool SkipCache bool
FetchRowNumber *string FetchRowNumber *string
PKRow *string PKRow *string
// Response format // Response format
ResponseFormat string // "simple", "detail", "syncfusion" ResponseFormat string // "simple", "detail", "syncfusion"
@ -42,16 +42,16 @@ type ExtendedRequestOptions struct {
AtomicTransaction bool AtomicTransaction bool
// Cursor pagination // Cursor pagination
CursorForward string CursorForward string
CursorBackward string CursorBackward string
} }
// ExpandOption represents a relation expansion configuration // ExpandOption represents a relation expansion configuration
type ExpandOption struct { type ExpandOption struct {
Relation string Relation string
Columns []string Columns []string
Where string Where string
Sort string Sort string
} }
// decodeHeaderValue decodes base64 encoded header values // decodeHeaderValue decodes base64 encoded header values
@ -85,12 +85,13 @@ func (h *Handler) parseOptionsFromHeaders(r common.Request) ExtendedRequestOptio
options := ExtendedRequestOptions{ options := ExtendedRequestOptions{
RequestOptions: common.RequestOptions{ RequestOptions: common.RequestOptions{
Filters: make([]common.FilterOption, 0), Filters: make([]common.FilterOption, 0),
Sort: make([]common.SortOption, 0), Sort: make([]common.SortOption, 0),
Preload: make([]common.PreloadOption, 0), Preload: make([]common.PreloadOption, 0),
}, },
AdvancedSQL: make(map[string]string), AdvancedSQL: make(map[string]string),
ComputedQL: make(map[string]string), ComputedQL: make(map[string]string),
Expand: make([]ExpandOption, 0), Expand: make([]ExpandOption, 0),
ResponseFormat: "simple", // Default response format
} }
// Get all headers // Get all headers
@ -212,9 +213,9 @@ func (h *Handler) parseNotSelectFields(options *ExtendedRequestOptions, value st
func (h *Handler) parseFieldFilter(options *ExtendedRequestOptions, headerKey, value string) { func (h *Handler) parseFieldFilter(options *ExtendedRequestOptions, headerKey, value string) {
colName := strings.TrimPrefix(headerKey, "x-fieldfilter-") colName := strings.TrimPrefix(headerKey, "x-fieldfilter-")
options.Filters = append(options.Filters, common.FilterOption{ options.Filters = append(options.Filters, common.FilterOption{
Column: colName, Column: colName,
Operator: "eq", Operator: "eq",
Value: value, Value: value,
}) })
} }
@ -223,9 +224,9 @@ func (h *Handler) parseSearchFilter(options *ExtendedRequestOptions, headerKey,
colName := strings.TrimPrefix(headerKey, "x-searchfilter-") colName := strings.TrimPrefix(headerKey, "x-searchfilter-")
// Use ILIKE for fuzzy search // Use ILIKE for fuzzy search
options.Filters = append(options.Filters, common.FilterOption{ options.Filters = append(options.Filters, common.FilterOption{
Column: colName, Column: colName,
Operator: "ilike", Operator: "ilike",
Value: "%" + value + "%", Value: "%" + value + "%",
}) })
} }
@ -407,7 +408,7 @@ func (h *Handler) parseSorting(options *ExtendedRequestOptions, value string) {
} }
options.Sort = append(options.Sort, common.SortOption{ options.Sort = append(options.Sort, common.SortOption{
Column: colName, Column: colName,
Direction: direction, Direction: direction,
}) })
} }