@@ -1086,6 +1086,113 @@ test('Issue#3128 - Support if-match', async t => {
1086
1086
await t . completed
1087
1087
} )
1088
1088
1089
+ test ( 'Issue#3128 - Support if-match (disabled)' , async t => {
1090
+ t = tspl ( t , { plan : 9 } )
1091
+
1092
+ const chunks = [ ]
1093
+ let counter = 0
1094
+
1095
+ // Took from: https://github.com/nxtedition/nxt-lib/blob/4b001ebc2f22cf735a398f35ff800dd553fe5933/test/undici/retry.js#L47
1096
+ let x = 0
1097
+ const server = createServer ( ( req , res ) => {
1098
+ if ( x === 0 ) {
1099
+ t . deepStrictEqual ( req . headers . range , 'bytes=0-3' )
1100
+ res . setHeader ( 'etag' , 'asd' )
1101
+ res . write ( 'abc' )
1102
+ setTimeout ( ( ) => {
1103
+ res . destroy ( )
1104
+ } , 1e2 )
1105
+ } else if ( x === 1 ) {
1106
+ t . deepStrictEqual ( req . headers . range , 'bytes=3-' )
1107
+ t . equal ( req . headers [ 'if-match' ] , undefined )
1108
+
1109
+ res . setHeader ( 'content-range' , 'bytes 3-6/6' )
1110
+ res . setHeader ( 'etag' , 'asd' )
1111
+ res . statusCode = 206
1112
+ res . end ( 'def' )
1113
+ }
1114
+ x ++
1115
+ } )
1116
+
1117
+ const dispatchOptions = {
1118
+ retryOptions : {
1119
+ retry : function ( err , _ , done ) {
1120
+ counter ++
1121
+
1122
+ if ( err . code && err . code === 'UND_ERR_DESTROYED' ) {
1123
+ return done ( false )
1124
+ }
1125
+
1126
+ if ( err . statusCode === 206 ) return done ( err )
1127
+
1128
+ setTimeout ( done , 800 )
1129
+ } ,
1130
+ ifMatch : false
1131
+ } ,
1132
+ method : 'GET' ,
1133
+ path : '/' ,
1134
+ headers : {
1135
+ 'content-type' : 'application/json'
1136
+ }
1137
+ }
1138
+
1139
+ server . listen ( 0 , ( ) => {
1140
+ const client = new Client ( `http://localhost:${ server . address ( ) . port } ` )
1141
+ const handler = new RetryHandler ( dispatchOptions , {
1142
+ dispatch : ( ...args ) => {
1143
+ return client . dispatch ( ...args )
1144
+ } ,
1145
+ handler : {
1146
+ onRequestSent ( ) {
1147
+ t . ok ( true , 'pass' )
1148
+ } ,
1149
+ onConnect ( ) {
1150
+ t . ok ( true , 'pass' )
1151
+ } ,
1152
+ onBodySent ( ) {
1153
+ t . ok ( true , 'pass' )
1154
+ } ,
1155
+ onHeaders ( status , _rawHeaders , resume , _statusMessage ) {
1156
+ t . strictEqual ( status , 200 )
1157
+ return true
1158
+ } ,
1159
+ onData ( chunk ) {
1160
+ chunks . push ( chunk )
1161
+ return true
1162
+ } ,
1163
+ onComplete ( ) {
1164
+ t . strictEqual ( Buffer . concat ( chunks ) . toString ( 'utf-8' ) , 'abcdef' )
1165
+ t . strictEqual ( counter , 1 )
1166
+ } ,
1167
+ onError ( ) {
1168
+ t . fail ( )
1169
+ }
1170
+ }
1171
+ } )
1172
+
1173
+ client . dispatch (
1174
+ {
1175
+ method : 'GET' ,
1176
+ path : '/' ,
1177
+ headers : {
1178
+ 'content-type' : 'application/json' ,
1179
+ Range : 'bytes=0-3'
1180
+ }
1181
+ } ,
1182
+ handler
1183
+ )
1184
+
1185
+ after ( async ( ) => {
1186
+ await client . close ( )
1187
+
1188
+ server . close ( )
1189
+ await once ( server , 'close' )
1190
+ } )
1191
+ } )
1192
+
1193
+ await t . completed
1194
+ } )
1195
+
1089
1196
test ( 'Issue#3128 - Should ignore weak etags' , async t => {
1090
1197
t = tspl ( t , { plan : 9 } )
1091
1198
@@ -1192,7 +1299,7 @@ test('Issue#3128 - Should ignore weak etags', async t => {
1192
1299
await t . completed
1193
1300
} )
1194
1301
1195
- test ( 'Weak etags are ignored on range-requests' , { only : true } , async t => {
1302
+ test ( 'Weak etags are ignored on range-requests' , async t => {
1196
1303
t = tspl ( t , { plan : 9 } )
1197
1304
1198
1305
const chunks = [ ]
0 commit comments