Skip to content
Permalink
Browse files

Merge pull request #224 from intercloud/fix/216

fix(216): fix presence of sign = in header values
  • Loading branch information
hunterlong committed Jan 13, 2020
2 parents 72f1889 + 7f9e639 commit e7e8852aee375467f27cb23a8cca7459383e74e3
Showing with 22 additions and 2 deletions.
  1. +0 −1 source/wiki.go
  2. +1 −1 utils/utils.go
  3. +21 −0 utils/utils_test.go

Large diffs are not rendered by default.

@@ -337,7 +337,7 @@ func HttpRequest(url, method string, content interface{}, headers []string, body

verifyHost := req.URL.Hostname()
for _, h := range headers {
keyVal := strings.Split(h, "=")
keyVal := strings.SplitN(h, "=", 2)
if len(keyVal) == 2 {
if keyVal[0] != "" && keyVal[1] != "" {
if strings.ToLower(keyVal[0]) == "host" {
@@ -19,6 +19,7 @@ import (
"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
"time"
)
@@ -163,3 +164,23 @@ func TestRandomString(t *testing.T) {
func TestDeleteDirectory(t *testing.T) {
assert.Nil(t, DeleteDirectory(Directory+"/logs"))
}

func TestHttpRequest(t *testing.T) {
// Start a local HTTP server
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
// Test request parameters
assert.Equal(t, req.URL.String(), "/")
assert.Equal(t, req.Header["Aaa"], []string{"bbbb="})
assert.Equal(t, req.Header["Ccc"], []string{"ddd"})
// Send response to be tested
rw.Write([]byte(`OK`))
}))
// Close the server when test finishes
defer server.Close()

body, resp, err := HttpRequest(server.URL, "GET", "application/json", []string{"aaa=bbbb=", "ccc=ddd"}, nil, 2*time.Second)

assert.Nil(t, err)
assert.Equal(t, []byte("OK"), body)
assert.Equal(t, resp.StatusCode, 200)
}

0 comments on commit e7e8852

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