@@ -2626,18 +2626,20 @@ func TestExcessBody(t *testing.T) {
2626
2626
testExcessBodyStream (t , 8088 )
2627
2627
testExcessBodyRPCUnexpected (t , 8088 )
2628
2628
testExcessBodyStreamUnexpected (t , 8088 )
2629
+ // testExcessBodyRPCWithBody(t, 8088)
2630
+ // testExcessBodyStreamWithBody(t, 8088)
2631
+ // testExcessBodyRPCWithBodyUnexpected(t, 8088)
2632
+ // testExcessBodyStreamWithBodyUnexpected(t, 8088)
2629
2633
}
2630
2634
2631
2635
func testExcessBodyRPC (t * testing.T , port int ) {
2632
- apiURL := fmt .Sprintf ("http://localhost:%d/rpc/no -body/rpc" , port )
2636
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess -body/rpc" , port )
2633
2637
2634
2638
ctx := context .Background ()
2635
2639
ctx , cancel := context .WithCancel (ctx )
2636
2640
defer cancel ()
2637
2641
2638
- body := strings .NewReader ("{}" )
2639
-
2640
- req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , body )
2642
+ req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , nil )
2641
2643
if err != nil {
2642
2644
t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2643
2645
return
@@ -2658,15 +2660,13 @@ func testExcessBodyRPC(t *testing.T, port int) {
2658
2660
}
2659
2661
2660
2662
func testExcessBodyStream (t * testing.T , port int ) {
2661
- apiURL := fmt .Sprintf ("http://localhost:%d/rpc/no -body/stream" , port )
2663
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess -body/stream" , port )
2662
2664
2663
2665
ctx := context .Background ()
2664
2666
ctx , cancel := context .WithCancel (ctx )
2665
2667
defer cancel ()
2666
2668
2667
- body := strings .NewReader ("{}" )
2668
-
2669
- req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , body )
2669
+ req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , nil )
2670
2670
if err != nil {
2671
2671
t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2672
2672
return
@@ -2687,20 +2687,75 @@ func testExcessBodyStream(t *testing.T, port int) {
2687
2687
}
2688
2688
2689
2689
func testExcessBodyRPCUnexpected (t * testing.T , port int ) {
2690
- apiURL := fmt .Sprintf ("http://localhost:%d/rpc/no -body/rpc/unexpected " , port )
2690
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess -body/rpc" , port )
2691
2691
2692
2692
ctx := context .Background ()
2693
2693
ctx , cancel := context .WithCancel (ctx )
2694
2694
defer cancel ()
2695
2695
2696
- body := strings .NewReader ("{}... " )
2696
+ body := strings .NewReader ("{}" )
2697
2697
2698
2698
req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , body )
2699
2699
if err != nil {
2700
2700
t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2701
2701
return
2702
2702
}
2703
2703
2704
+ resp , err := http .DefaultClient .Do (req )
2705
+ if err != nil {
2706
+ t .Errorf ("http.DefaultClient.Do(req) failed with %v; want success" , err )
2707
+ return
2708
+ }
2709
+ defer resp .Body .Close ()
2710
+
2711
+ if resp .StatusCode != http .StatusBadRequest {
2712
+ t .Errorf ("unexpected status code: %d" , resp .StatusCode )
2713
+ return
2714
+ }
2715
+ }
2716
+
2717
+ func testExcessBodyStreamUnexpected (t * testing.T , port int ) {
2718
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess-body/stream" , port )
2719
+
2720
+ ctx := context .Background ()
2721
+ ctx , cancel := context .WithCancel (ctx )
2722
+ defer cancel ()
2723
+
2724
+ body := strings .NewReader ("{}" )
2725
+
2726
+ req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , body )
2727
+ if err != nil {
2728
+ t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2729
+ return
2730
+ }
2731
+
2732
+ resp , err := http .DefaultClient .Do (req )
2733
+ if err != nil {
2734
+ t .Errorf ("http.DefaultClient.Do(req) failed with %v; want success" , err )
2735
+ return
2736
+ }
2737
+ defer resp .Body .Close ()
2738
+
2739
+ if resp .StatusCode != http .StatusBadRequest {
2740
+ t .Errorf ("unexpected status code: %d" , resp .StatusCode )
2741
+ return
2742
+ }
2743
+ }
2744
+
2745
+ func testExcessBodyRPCWithBody (t * testing.T , port int ) {
2746
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess-body/rpc/with-body" , port )
2747
+
2748
+ ctx := context .Background ()
2749
+ ctx , cancel := context .WithCancel (ctx )
2750
+ defer cancel ()
2751
+
2752
+ body := strings .NewReader ("{}" )
2753
+ req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , body )
2754
+ if err != nil {
2755
+ t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2756
+ return
2757
+ }
2758
+
2704
2759
go http .DefaultClient .Do (req )
2705
2760
2706
2761
// Wait for the server to start processing the request.
@@ -2715,15 +2770,14 @@ func testExcessBodyRPCUnexpected(t *testing.T, port int) {
2715
2770
}
2716
2771
}
2717
2772
2718
- func testExcessBodyStreamUnexpected (t * testing.T , port int ) {
2719
- apiURL := fmt .Sprintf ("http://localhost:%d/rpc/no -body/stream/unexpected " , port )
2773
+ func testExcessBodyStreamWithBody (t * testing.T , port int ) {
2774
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess -body/stream/with-body " , port )
2720
2775
2721
2776
ctx := context .Background ()
2722
2777
ctx , cancel := context .WithCancel (ctx )
2723
2778
defer cancel ()
2724
2779
2725
- body := strings .NewReader ("{}..." )
2726
-
2780
+ body := strings .NewReader ("{}" )
2727
2781
req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , body )
2728
2782
if err != nil {
2729
2783
t .Errorf ("http.NewRequest() failed with %v; want success" , err )
@@ -2743,3 +2797,109 @@ func testExcessBodyStreamUnexpected(t *testing.T, port int) {
2743
2797
t .Errorf ("server context not done" )
2744
2798
}
2745
2799
}
2800
+
2801
+ func testExcessBodyRPCWithBodyNil (t * testing.T , port int ) {
2802
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess-body/rpc/with-body" , port )
2803
+
2804
+ ctx := context .Background ()
2805
+ ctx , cancel := context .WithCancel (ctx )
2806
+ defer cancel ()
2807
+
2808
+ req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , nil )
2809
+ if err != nil {
2810
+ t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2811
+ return
2812
+ }
2813
+
2814
+ resp , err := http .DefaultClient .Do (req )
2815
+ if err != nil {
2816
+ t .Errorf ("http.DefaultClient.Do(req) failed with %v; want success" , err )
2817
+ return
2818
+ }
2819
+
2820
+ if resp .StatusCode != http .StatusBadRequest {
2821
+ t .Errorf ("unexpected status code: %d" , resp .StatusCode )
2822
+ return
2823
+ }
2824
+ }
2825
+
2826
+ func testExcessBodyStreamWithBodyNil (t * testing.T , port int ) {
2827
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess-body/stream/with-body" , port )
2828
+
2829
+ ctx := context .Background ()
2830
+ ctx , cancel := context .WithCancel (ctx )
2831
+ defer cancel ()
2832
+
2833
+ req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , nil )
2834
+ if err != nil {
2835
+ t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2836
+ return
2837
+ }
2838
+
2839
+ resp , err := http .DefaultClient .Do (req )
2840
+ if err != nil {
2841
+ t .Errorf ("http.DefaultClient.Do(req) failed with %v; want success" , err )
2842
+ return
2843
+ }
2844
+
2845
+ if resp .StatusCode != http .StatusBadRequest {
2846
+ t .Errorf ("unexpected status code: %d" , resp .StatusCode )
2847
+ return
2848
+ }
2849
+ }
2850
+
2851
+ func testExcessBodyRPCWithBodyUnexpected (t * testing.T , port int ) {
2852
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess-body/rpc" , port )
2853
+
2854
+ ctx := context .Background ()
2855
+ ctx , cancel := context .WithCancel (ctx )
2856
+ defer cancel ()
2857
+
2858
+ body := strings .NewReader ("{}." )
2859
+
2860
+ req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , body )
2861
+ if err != nil {
2862
+ t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2863
+ return
2864
+ }
2865
+
2866
+ resp , err := http .DefaultClient .Do (req )
2867
+ if err != nil {
2868
+ t .Errorf ("http.DefaultClient.Do(req) failed with %v; want success" , err )
2869
+ return
2870
+ }
2871
+ defer resp .Body .Close ()
2872
+
2873
+ if resp .StatusCode != http .StatusBadRequest {
2874
+ t .Errorf ("unexpected status code: %d" , resp .StatusCode )
2875
+ return
2876
+ }
2877
+ }
2878
+
2879
+ func testExcessBodyStreamWithBodyUnexpected (t * testing.T , port int ) {
2880
+ apiURL := fmt .Sprintf ("http://localhost:%d/rpc/excess-body/stream" , port )
2881
+
2882
+ ctx := context .Background ()
2883
+ ctx , cancel := context .WithCancel (ctx )
2884
+ defer cancel ()
2885
+
2886
+ body := strings .NewReader ("{}." )
2887
+
2888
+ req , err := http .NewRequestWithContext (ctx , "POST" , apiURL , body )
2889
+ if err != nil {
2890
+ t .Errorf ("http.NewRequest() failed with %v; want success" , err )
2891
+ return
2892
+ }
2893
+
2894
+ resp , err := http .DefaultClient .Do (req )
2895
+ if err != nil {
2896
+ t .Errorf ("http.DefaultClient.Do(req) failed with %v; want success" , err )
2897
+ return
2898
+ }
2899
+ defer resp .Body .Close ()
2900
+
2901
+ if resp .StatusCode != http .StatusBadRequest {
2902
+ t .Errorf ("unexpected status code: %d" , resp .StatusCode )
2903
+ return
2904
+ }
2905
+ }
0 commit comments