@@ -709,6 +709,72 @@ public async Task SendAsync_CorrectlyCopiesHeadersToIndividualRequests(
709
709
Assert . Contains ( deleteRequest , responseContent ) ;
710
710
Assert . Contains ( postRequest , responseContent ) ;
711
711
}
712
+
713
+ [ Fact ]
714
+ public async Task SendAsync_CorrectlyHandlesCookieHeader ( )
715
+ {
716
+ var batchRef = $ "batch_{ Guid . NewGuid ( ) } ";
717
+ var changesetRef = $ "changeset_{ Guid . NewGuid ( ) } ";
718
+ var endpoint = "http://localhost" ;
719
+
720
+ Type [ ] controllers = new [ ] { typeof ( BatchTestCustomersController ) , typeof ( BatchTestOrdersController ) , } ;
721
+ var server = TestServerFactory . Create ( controllers , ( config ) =>
722
+ {
723
+ var builder = ODataConventionModelBuilderFactory . Create ( config ) ;
724
+ builder . EntitySet < BatchTestOrder > ( "BatchTestOrders" ) ;
725
+
726
+ config . MapODataServiceRoute ( "odata" , null , builder . GetEdmModel ( ) , new DefaultODataBatchHandler ( ) ) ;
727
+ config . Expand ( ) ;
728
+ config . EnableDependencyInjection ( ) ;
729
+ } ) ;
730
+
731
+ var client = TestServerFactory . CreateClient ( server ) ;
732
+
733
+ var orderId = 2 ;
734
+ var createOrderPayload = $@ "{{""@odata.type"":""Microsoft.AspNet.OData.Test.Batch.BatchTestOrder"",""Id"":{ orderId } ,""Amount"":50}}";
735
+
736
+ var batchRequest = new HttpRequestMessage ( HttpMethod . Post , $ "{ endpoint } /$batch") ;
737
+ batchRequest . Headers . Accept . Add ( MediaTypeWithQualityHeaderValue . Parse ( "text/plain" ) ) ;
738
+
739
+ // Add cookie (for example IdentityServer adds antiforgery after login)
740
+ batchRequest . Headers . TryAddWithoutValidation ( "Cookie" , ".AspNetCore.Antiforgery.9TtSrW0hzOs=" + Guid . NewGuid ( ) ) ;
741
+
742
+ var batchContent = $@ "
743
+ --{ batchRef }
744
+ Content-Type: multipart/mixed;boundary={ changesetRef }
745
+
746
+ --{ changesetRef }
747
+ Content-Type: application/http
748
+ Content-Transfer-Encoding: binary
749
+ Content-ID: 1
750
+
751
+ POST { endpoint } /BatchTestOrders HTTP/1.1
752
+ Content-Type: application/json;type=entry
753
+ Prefer: return=representation
754
+
755
+ { createOrderPayload }
756
+ --{ changesetRef } --
757
+ --{ batchRef }
758
+ Content-Type: application/http
759
+ Content-Transfer-Encoding: binary
760
+
761
+ GET { endpoint } /BatchTestOrders({ orderId } ) HTTP/1.1
762
+ Content-Type: application/json;type=entry
763
+ Prefer: return=representation
764
+
765
+ --{ batchRef } --
766
+ " ;
767
+
768
+ var httpContent = new StringContent ( batchContent ) ;
769
+ httpContent . Headers . ContentType = MediaTypeHeaderValue . Parse ( $ "multipart/mixed;boundary={ batchRef } ") ;
770
+ httpContent . Headers . ContentLength = batchContent . Length ;
771
+ batchRequest . Content = httpContent ;
772
+ var response = await client . SendAsync ( batchRequest ) ;
773
+
774
+ ExceptionAssert . DoesNotThrow ( ( ) => response . EnsureSuccessStatusCode ( ) ) ;
775
+
776
+ // TODO: assert somehow?
777
+ }
712
778
#endif
713
779
}
714
780
@@ -810,6 +876,12 @@ public IEnumerable<BatchTestOrder> Get()
810
876
return BatchTestOrder . Orders ;
811
877
}
812
878
879
+ [ EnableQuery ]
880
+ public SingleResult < BatchTestOrder > Get ( [ FromODataUri ] int key )
881
+ {
882
+ return SingleResult . Create ( BatchTestOrder . Orders . Where ( d => d . Id . Equals ( key ) ) . AsQueryable ( ) ) ;
883
+ }
884
+
813
885
public ITestActionResult Post ( [ FromBody ] BatchTestOrder order )
814
886
{
815
887
BatchTestOrder . Orders . Add ( order ) ;
0 commit comments