@@ -108,13 +108,23 @@ func TestRouteServePOST201WithParams(t *testing.T) {
108108 assert .Equal (t , "true" , r .QP ["param2" ])
109109 assert .Equal (t , "false" , r .QP ["param3" ])
110110 assert .Equal (t , []string {"x" , "y" }, r .QAP ["param4" ])
111+ assert .Equal (t , "12345" , r .Req .Context ().Value (CtxFFRequestIDKey {}).(string ))
112+ assert .Equal (t , "custom-value" , r .Req .Context ().Value (CtxHeadersKey {}).(http.Header ).Get ("X-Custom-Header" ))
111113 return map [string ]interface {}{"output1" : "value2" }, nil
112114 },
113115 }}, "" , nil )
114116 defer done ()
117+ SetRequestIDHeader ("x-unittest-req-id" ) // tests custom req header
115118
116119 b , _ := json .Marshal (map [string ]interface {}{"input1" : "value1" })
117- res , err := http .Post (fmt .Sprintf ("http://%s/test/stuff?param1=thing¶m2¶m3=false¶m4=x¶m4=y" , s .Addr ()), "application/json" , bytes .NewReader (b ))
120+
121+ req , err := http .NewRequest (http .MethodPost , fmt .Sprintf ("http://%s/test/stuff?param1=thing¶m2¶m3=false¶m4=x¶m4=y" , s .Addr ()), bytes .NewReader (b ))
122+ require .NoError (t , err )
123+ req .Header .Set ("Content-Type" , "application/json" )
124+ req .Header .Set ("X-Custom-Header" , "custom-value" ) // tests custom header
125+ req .Header .Set ("x-unittest-req-id" , "12345" ) // tests custom req header
126+
127+ res , err := http .DefaultClient .Do (req )
118128 assert .NoError (t , err )
119129 assert .Equal (t , 201 , res .StatusCode )
120130 var resJSON map [string ]interface {}
@@ -134,13 +144,19 @@ func TestRouteServePOST201WithParamsLargeNumber(t *testing.T) {
134144 JSONOutputCodes : []int {201 },
135145 JSONHandler : func (r * APIRequest ) (output interface {}, err error ) {
136146 assert .Equal (t , r .Input , map [string ]interface {}{"largeNumberParam" : json .Number ("10000000000000000000000000001" )})
147+ assert .Equal (t , "12345" , r .Req .Context ().Value (CtxFFRequestIDKey {}).(string ))
137148 // Echo the input back as the response
138149 return r .Input , nil
139150 },
140151 }}, "" , nil )
141152 defer done ()
142153
143- res , err := http .Post (fmt .Sprintf ("http://%s/test/stuff" , s .Addr ()), "application/json" , bytes .NewReader ([]byte (largeParamLiteral )))
154+ req , err := http .NewRequest (http .MethodPost , fmt .Sprintf ("http://%s/test/stuff" , s .Addr ()), bytes .NewReader ([]byte (largeParamLiteral )))
155+ require .NoError (t , err )
156+ req .Header .Set ("Content-Type" , "application/json" )
157+ req .Header .Set (DefaultRequestIDHeader , "12345" ) // tests client setting req header
158+
159+ res , err := http .DefaultClient .Do (req )
144160 assert .NoError (t , err )
145161 assert .Equal (t , 201 , res .StatusCode )
146162 var resJSON map [string ]interface {}
0 commit comments