From 1adca4c49b910d20ce04ca688af035fa7f4aea8e Mon Sep 17 00:00:00 2001 From: Hein Date: Fri, 7 Nov 2025 10:55:42 +0200 Subject: [PATCH] Content Types and Respose fixes for restheadpsec --- pkg/restheadspec/handler.go | 2 +- pkg/restheadspec/headers.go | 43 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/pkg/restheadspec/handler.go b/pkg/restheadspec/handler.go index 4128fcc..5bff8f8 100644 --- a/pkg/restheadspec/handler.go +++ b/pkg/restheadspec/handler.go @@ -695,7 +695,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{ if options.CleanJSON { data = h.cleanJSON(data) } - + w.SetHeader("Content-Type", "application/json") // Format response based on response format option switch options.ResponseFormat { case "simple": diff --git a/pkg/restheadspec/headers.go b/pkg/restheadspec/headers.go index c6774b4..32d7aa7 100644 --- a/pkg/restheadspec/headers.go +++ b/pkg/restheadspec/headers.go @@ -19,21 +19,21 @@ type ExtendedRequestOptions struct { CleanJSON bool // Advanced filtering - SearchColumns []string + SearchColumns []string CustomSQLWhere string - CustomSQLOr string + CustomSQLOr string // Joins Expand []ExpandOption // Advanced features - AdvancedSQL map[string]string // Column -> SQL expression - ComputedQL map[string]string // Column -> CQL expression - Distinct bool - SkipCount bool - SkipCache bool + AdvancedSQL map[string]string // Column -> SQL expression + ComputedQL map[string]string // Column -> CQL expression + Distinct bool + SkipCount bool + SkipCache bool FetchRowNumber *string - PKRow *string + PKRow *string // Response format ResponseFormat string // "simple", "detail", "syncfusion" @@ -42,16 +42,16 @@ type ExtendedRequestOptions struct { AtomicTransaction bool // Cursor pagination - CursorForward string + CursorForward string CursorBackward string } // ExpandOption represents a relation expansion configuration type ExpandOption struct { Relation string - Columns []string - Where string - Sort string + Columns []string + Where string + Sort string } // decodeHeaderValue decodes base64 encoded header values @@ -85,12 +85,13 @@ func (h *Handler) parseOptionsFromHeaders(r common.Request) ExtendedRequestOptio options := ExtendedRequestOptions{ RequestOptions: common.RequestOptions{ Filters: make([]common.FilterOption, 0), - Sort: make([]common.SortOption, 0), + Sort: make([]common.SortOption, 0), Preload: make([]common.PreloadOption, 0), }, - AdvancedSQL: make(map[string]string), - ComputedQL: make(map[string]string), - Expand: make([]ExpandOption, 0), + AdvancedSQL: make(map[string]string), + ComputedQL: make(map[string]string), + Expand: make([]ExpandOption, 0), + ResponseFormat: "simple", // Default response format } // Get all headers @@ -212,9 +213,9 @@ func (h *Handler) parseNotSelectFields(options *ExtendedRequestOptions, value st func (h *Handler) parseFieldFilter(options *ExtendedRequestOptions, headerKey, value string) { colName := strings.TrimPrefix(headerKey, "x-fieldfilter-") options.Filters = append(options.Filters, common.FilterOption{ - Column: colName, + Column: colName, Operator: "eq", - Value: value, + Value: value, }) } @@ -223,9 +224,9 @@ func (h *Handler) parseSearchFilter(options *ExtendedRequestOptions, headerKey, colName := strings.TrimPrefix(headerKey, "x-searchfilter-") // Use ILIKE for fuzzy search options.Filters = append(options.Filters, common.FilterOption{ - Column: colName, + Column: colName, 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{ - Column: colName, + Column: colName, Direction: direction, }) }