Skip to content
Permalink
Browse files

fix base64 encoded json when params are provided

  • Loading branch information...
tj committed Jan 25, 2018
1 parent 9cfeb90 commit c69257601f8b9cbf03ba38252a87800417520c8d
Showing with 32 additions and 6 deletions.
  1. +13 −6 internal/proxy/response.go
  2. +19 −0 internal/proxy/response_test.go
@@ -3,6 +3,7 @@ package proxy
import (
"bytes"
"encoding/base64"
"mime"
"net/http"
"strings"
)
@@ -93,15 +94,21 @@ func isBinary(h http.Header) bool {

// isTextMime returns true if the content type represents textual data.
func isTextMime(kind string) bool {
// TODO: refactor textual mime type stuff
switch {
case strings.HasSuffix(kind, "svg+xml"):
mt, _, err := mime.ParseMediaType(kind)
if err != nil {
return false
}

if strings.HasPrefix(mt, "text/") {
return true
case strings.HasPrefix(kind, "text/"):
}

switch mt {
case "svg+xml":
return true
case strings.HasPrefix(kind, "application/") && strings.HasSuffix(kind, "json"):
case "application/json":
return true
case strings.HasPrefix(kind, "application/") && strings.HasSuffix(kind, "xml"):
case "application/xml":
return true
default:
return false
@@ -0,0 +1,19 @@
package proxy

import (
"testing"

"github.com/tj/assert"
)

func Test_JSON_isTextMime(t *testing.T) {
assert.Equal(t, isTextMime("application/json"), true)
assert.Equal(t, isTextMime("application/json; charset=utf-8"), true)
assert.Equal(t, isTextMime("Application/JSON"), true)
}

func Test_XML_isTextMime(t *testing.T) {
assert.Equal(t, isTextMime("application/xml"), true)
assert.Equal(t, isTextMime("application/xml; charset=utf-8"), true)
assert.Equal(t, isTextMime("ApPlicaTion/xMl"), true)
}

0 comments on commit c692576

Please sign in to comment.
You can’t perform that action at this time.