github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgNet/kmgHttp/context_test.go (about)

     1  package kmgHttp
     2  
     3  import (
     4  	"bytes"
     5  	"net/http"
     6  	"net/http/httptest"
     7  	"testing"
     8  
     9  	"github.com/bronze1man/kmg/kmgTest"
    10  )
    11  
    12  func TestAlipayContentTypeBug(ot *testing.T) {
    13  	// 正常的(浏览器生成的) Content-Type: application/x-www-form-urlencoded; charset=UTF-8
    14  	// 支付宝的 Content-Type: application/x-www-form-urlencoded; text/html; charset=utf-8
    15  	w := httptest.NewRecorder()
    16  	req, err := http.NewRequest("POST", "http://www.google.com/123", bytes.NewBufferString("a=b&c=d"))
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  	// 正常的
    21  	req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
    22  	c := NewContextFromHttp(w, req)
    23  	kmgTest.Equal(c.InStr("a"), "b")
    24  	kmgTest.Equal(c.InStr("c"), "d")
    25  
    26  	//支付宝的
    27  	req, err = http.NewRequest("POST", "http://www.google.com/123", bytes.NewBufferString("a=b&c=d"))
    28  	if err != nil {
    29  		panic(err)
    30  	}
    31  	req.Header.Set("Content-Type", "application/x-www-form-urlencoded; text/html; charset=utf-8")
    32  	c = NewContextFromHttp(w, req)
    33  	kmgTest.Equal(c.InStr("a"), "b")
    34  	kmgTest.Equal(c.InStr("c"), "d")
    35  }