From 583b7578564015ce1b405d502761311db819ffd1 Mon Sep 17 00:00:00 2001 From: Chris Keller Date: Sun, 19 Jan 2025 21:40:27 -0700 Subject: [PATCH] Fix the client to accept text/plain (#111) I think the QRZ.com API started returning this recently, and the OpenAPI generated client is not set up to accept that out of the box. --- client.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 9297729..a4a118d 100644 --- a/client.go +++ b/client.go @@ -41,6 +41,8 @@ var ( jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) formCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:html|x-www-form-urlencoded))`) + // k0swe customizations + textPlainCheck = regexp.MustCompile(`(?i:(?:text/plain))`) ) // APIClient manages communication with the QRZ Logbook API API v1.0.0 @@ -396,7 +398,14 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err } return nil } - return errors.New("undefined response type") + // k0swe customizations + if textPlainCheck.MatchString(contentType) { + if err = unmarshalForm(b, v); err != nil { + return err + } + return nil + } + return errors.New("undefined response type " + contentType) } // Add a file to the multipart request