From 5d8f00df643b91eecbde88a5b13934d05db41e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Mon, 23 May 2022 13:47:20 +0200 Subject: [PATCH] Add content type assertion fallback for JSON file imports --- compose/service/import_session.go | 2 +- pkg/envoy/json/decoder.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compose/service/import_session.go b/compose/service/import_session.go index 30c72adef..533af907c 100644 --- a/compose/service/import_session.go +++ b/compose/service/import_session.go @@ -84,7 +84,7 @@ func (svc *importSession) Create(ctx context.Context, f io.ReadSeeker, name, con } f.Seek(0, 0) - if jd.CanDecodeFile(f) { + if jd.CanDecodeFile(f) || jd.CanDecodeMime(contentType) { f.Seek(0, 0) return jd.Decode(ctx, f, do) } diff --git a/pkg/envoy/json/decoder.go b/pkg/envoy/json/decoder.go index e6f1a0c1f..c9dafbc9b 100644 --- a/pkg/envoy/json/decoder.go +++ b/pkg/envoy/json/decoder.go @@ -48,6 +48,10 @@ func (d *decoder) CanDecodeFile(f io.Reader) bool { return d.CanDecodeExt(ext) } +func (d *decoder) CanDecodeMime(m string) bool { + return m == "application/json" || m == "application/jsonlines" +} + func (d *decoder) CanDecodeExt(ext string) bool { pt := strings.Split(ext, ".") ext = strings.TrimSpace(pt[len(pt)-1])