1010import com .azure .core .http .HttpResponse ;
1111import com .azure .core .test .http .MockHttpResponse ;
1212import com .azure .core .util .BinaryData ;
13- import com .azure .storage .common .implementation .Constants ;
1413import org .junit .jupiter .api .Test ;
1514import reactor .core .publisher .Flux ;
1615import reactor .test .StepVerifier ;
@@ -65,7 +64,7 @@ public void preservesRequestStatusCodeAndHeaders() {
6564 HttpHeaders h = new HttpHeaders ().set (HttpHeaderName .CONTENT_LENGTH , "100" ).set (CUSTOM_HEADER , "value" );
6665 MockHttpResponse original = mockResponse (206 , h , bytes ("encoded" ));
6766
68- DecodedResponse wrapper = new DecodedResponse (original , fluxOf (bytes ("decoded" )), 100L , 80L );
67+ DecodedResponse wrapper = new DecodedResponse (original , fluxOf (bytes ("decoded" )), 80L );
6968
7069 assertSame (original .getRequest (), wrapper .getRequest ());
7170 assertEquals (206 , wrapper .getStatusCode ());
@@ -77,7 +76,7 @@ public void preservesRequestStatusCodeAndHeaders() {
7776 @ Test
7877 public void getHeaderValueByStringReturnsHeaderValue () {
7978 HttpHeaders h = headers (CUSTOM_HEADER , "value" );
80- DecodedResponse wrapper = new DecodedResponse (mockResponse (200 , h , new byte [0 ]), fluxOf (new byte [0 ]), 0L , 0L );
79+ DecodedResponse wrapper = new DecodedResponse (mockResponse (200 , h , new byte [0 ]), fluxOf (new byte [0 ]), 0L );
8180
8281 assertEquals ("value" , wrapper .getHeaderValue (CUSTOM_HEADER .getCaseInsensitiveName ()));
8382 assertNull (wrapper .getHeaderValue ("nonexistent" ));
@@ -87,7 +86,7 @@ public void getHeaderValueByStringReturnsHeaderValue() {
8786 public void getBodyReturnsDecodedFlux () {
8887 byte [] decoded = bytes ("decoded body" );
8988 DecodedResponse wrapper
90- = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L , 0L );
89+ = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L );
9190
9291 StepVerifier .create (wrapper .getBody ().reduce (new ByteArrayOutputStream (), (sink , buf ) -> {
9392 byte [] copy = new byte [buf .remaining ()];
@@ -101,7 +100,7 @@ public void getBodyReturnsDecodedFlux() {
101100 public void getBodyAsByteArrayReturnsDecodedBytes () {
102101 byte [] decoded = bytes ("decoded body" );
103102 DecodedResponse wrapper
104- = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L , 0L );
103+ = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L );
105104
106105 StepVerifier .create (wrapper .getBodyAsByteArray ())
107106 .expectNextMatches (b -> Arrays .equals (decoded , b ))
@@ -114,7 +113,7 @@ public void getBodyAsStringDefaultsToUtf8WhenNoCharsetSpecified() {
114113 // BOM nor a Content-Type charset parameter is present. This test pins the "no headers, no BOM" path.
115114 String text = "héllo wörld – ✓" ;
116115 DecodedResponse wrapper = new DecodedResponse (mockResponse (200 , new HttpHeaders (), new byte [0 ]),
117- fluxOf (text .getBytes (StandardCharsets .UTF_8 )), 0L , 0L );
116+ fluxOf (text .getBytes (StandardCharsets .UTF_8 )), 0L );
118117
119118 StepVerifier .create (wrapper .getBodyAsString ()).expectNext (text ).verifyComplete ();
120119 }
@@ -127,7 +126,7 @@ public void getBodyAsStringHonorsCharsetFromContentTypeHeader() {
127126 String text = "ümlaut" ;
128127 byte [] iso = text .getBytes (StandardCharsets .ISO_8859_1 );
129128 HttpHeaders h = new HttpHeaders ().set (HttpHeaderName .CONTENT_TYPE , "text/plain; charset=ISO-8859-1" );
130- DecodedResponse wrapper = new DecodedResponse (mockResponse (200 , h , new byte [0 ]), fluxOf (iso ), 0L , 0L );
129+ DecodedResponse wrapper = new DecodedResponse (mockResponse (200 , h , new byte [0 ]), fluxOf (iso ), 0L );
131130
132131 StepVerifier .create (wrapper .getBodyAsString ()).expectNext (text ).verifyComplete ();
133132 }
@@ -143,7 +142,7 @@ public void getBodyAsStringDetectsUtf8BomAndStripsIt() {
143142 System .arraycopy (bom , 0 , withBom , 0 , bom .length );
144143 System .arraycopy (payload , 0 , withBom , bom .length , payload .length );
145144 DecodedResponse wrapper
146- = new DecodedResponse (mockResponse (200 , new HttpHeaders (), new byte [0 ]), fluxOf (withBom ), 0L , 0L );
145+ = new DecodedResponse (mockResponse (200 , new HttpHeaders (), new byte [0 ]), fluxOf (withBom ), 0L );
147146
148147 StepVerifier .create (wrapper .getBodyAsString ()).expectNext (text ).verifyComplete ();
149148 }
@@ -153,7 +152,7 @@ public void getBodyAsStringDecodesUsingProvidedCharset() {
153152 String text = "ümlaut" ;
154153 byte [] latin1 = text .getBytes (StandardCharsets .ISO_8859_1 );
155154 DecodedResponse wrapper
156- = new DecodedResponse (mockResponse (200 , new HttpHeaders (), new byte [0 ]), fluxOf (latin1 ), 0L , 0L );
155+ = new DecodedResponse (mockResponse (200 , new HttpHeaders (), new byte [0 ]), fluxOf (latin1 ), 0L );
157156
158157 StepVerifier .create (wrapper .getBodyAsString (StandardCharsets .ISO_8859_1 )).expectNext (text ).verifyComplete ();
159158 }
@@ -163,7 +162,7 @@ public void inheritedGetBodyAsInputStreamUsesDecodedBytes() throws IOException {
163162 // Base getBodyAsInputStream() routes through getBodyAsByteArray(), so the override is exercised end-to-end.
164163 byte [] decoded = bytes ("decoded stream" );
165164 DecodedResponse wrapper
166- = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L , 0L );
165+ = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L );
167166
168167 try (InputStream stream = wrapper .getBodyAsInputStream ().block ()) {
169168 assertNotNull (stream );
@@ -175,7 +174,7 @@ public void inheritedGetBodyAsInputStreamUsesDecodedBytes() throws IOException {
175174 public void inheritedWriteBodyToWritesDecodedBytes () throws IOException {
176175 byte [] decoded = bytes ("write me" );
177176 DecodedResponse wrapper
178- = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L , 0L );
177+ = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L );
179178
180179 ByteArrayOutputStream sink = new ByteArrayOutputStream ();
181180 try (WritableByteChannel channel = Channels .newChannel (sink )) {
@@ -189,7 +188,7 @@ public void inheritedWriteBodyToWritesDecodedBytes() throws IOException {
189188 public void inheritedBufferReturnsResponseBackedByDecodedBytes () {
190189 byte [] decoded = bytes ("buffered" );
191190 DecodedResponse wrapper
192- = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L , 0L );
191+ = new DecodedResponse (mockResponse (200 , new HttpHeaders (), bytes ("encoded" )), fluxOf (decoded ), 0L );
193192
194193 HttpResponse buffered = wrapper .buffer ();
195194 assertNotNull (buffered );
@@ -204,30 +203,29 @@ public void inheritedGetBodyAsBinaryDataReturnsDecodedBytes() {
204203 // must contain the decoded payload, not the original wire body. A divergent Content-Length header is set
205204 // to make the wire vs decoded distinction explicit and guard against regressions in header forwarding.
206205 byte [] decoded = bytes ("decoded payload" );
207- long originalSize = decoded .length + 32 ;
208- HttpHeaders h = new HttpHeaders ().set (HttpHeaderName .CONTENT_LENGTH , String .valueOf (originalSize ));
209- DecodedResponse wrapper = new DecodedResponse ( mockResponse ( 200 , h , bytes ( "encoded wire body" )), fluxOf ( decoded ),
210- originalSize , decoded . length );
206+ long decodedSize = decoded .length ;
207+ HttpHeaders h = new HttpHeaders ().set (HttpHeaderName .CONTENT_LENGTH , String .valueOf (decodedSize + 32 ));
208+ DecodedResponse wrapper
209+ = new DecodedResponse ( mockResponse ( 200 , h , bytes ( "encoded wire body" )), fluxOf ( decoded ), decodedSize );
211210
212211 BinaryData data = wrapper .getBodyAsBinaryData ();
213212 assertNotNull (data );
214213 assertArrayEquals (decoded , data .toBytes ());
215214 }
216215
217216 @ Test
218- public void contentLengthIsOverriddenToDecodedSizeAndOriginalIsPreserved () {
219- long originalSize = 500L ;
217+ public void contentLengthIsOverriddenToDecodedSize () {
218+ long wireSize = 500L ;
220219 long decodedSize = 300L ;
221- HttpHeaders h = new HttpHeaders ().set (HttpHeaderName .CONTENT_LENGTH , String .valueOf (originalSize ))
220+ HttpHeaders h = new HttpHeaders ()
221+ .set (HttpHeaderName .CONTENT_LENGTH , String .valueOf (wireSize ))
222222 .set (CUSTOM_HEADER , "preserve-me" );
223- DecodedResponse wrapper
224- = new DecodedResponse ( mockResponse ( 200 , h , new byte [ 0 ]), fluxOf ( new byte [ 0 ]), originalSize , decodedSize );
223+ DecodedResponse wrapper = new DecodedResponse ( mockResponse ( 200 , h , new byte [ 0 ]), fluxOf ( new byte [ 0 ]),
224+ decodedSize );
225225
226226 assertEquals (String .valueOf (decodedSize ), wrapper .getHeaders ().getValue (HttpHeaderName .CONTENT_LENGTH ));
227- assertEquals (String .valueOf (originalSize ),
228- wrapper .getHeaders ().getValue (Constants .HeaderConstants .ORIGINAL_CONTENT_LENGTH_HEADER_NAME ));
229227 assertEquals ("preserve-me" , wrapper .getHeaders ().getValue (CUSTOM_HEADER ));
230- // Deprecated getHeaderValue must reflect the same overrides .
228+ // Deprecated getHeaderValue must reflect the same override .
231229 assertEquals (String .valueOf (decodedSize ),
232230 wrapper .getHeaderValue (HttpHeaderName .CONTENT_LENGTH .getCaseInsensitiveName ()));
233231 }
0 commit comments