@@ -93,7 +93,7 @@ describe('HTTP Gateway', function () {
93
93
( cb ) => {
94
94
const expectedMultihash = 'QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
95
95
96
- http . api . node . files . add ( Buffer . from ( 'hello world' + '\n' ) , ( err , res ) => {
96
+ http . api . node . files . add ( Buffer . from ( 'hello world' + '\n' ) , { cidVersion : 0 } , ( err , res ) => {
97
97
expect ( err ) . to . not . exist ( )
98
98
const file = res [ 0 ]
99
99
expect ( file . path ) . to . equal ( expectedMultihash )
@@ -144,6 +144,10 @@ describe('HTTP Gateway', function () {
144
144
} , ( res ) => {
145
145
expect ( res . statusCode ) . to . equal ( 400 )
146
146
expect ( res . result . Message ) . to . be . a ( 'string' )
147
+ expect ( res . headers [ 'cache-control' ] ) . to . equal ( 'no-cache' )
148
+ expect ( res . headers [ 'etag' ] ) . to . equal ( undefined )
149
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( undefined )
150
+ expect ( res . headers [ 'suborigin' ] ) . to . equal ( undefined )
147
151
done ( )
148
152
} )
149
153
} )
@@ -155,21 +159,49 @@ describe('HTTP Gateway', function () {
155
159
} , ( res ) => {
156
160
expect ( res . statusCode ) . to . equal ( 400 )
157
161
expect ( res . result . Message ) . to . be . a ( 'string' )
162
+ expect ( res . headers [ 'cache-control' ] ) . to . equal ( 'no-cache' )
163
+ expect ( res . headers [ 'etag' ] ) . to . equal ( undefined )
164
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( undefined )
165
+ expect ( res . headers [ 'suborigin' ] ) . to . equal ( undefined )
158
166
done ( )
159
167
} )
160
168
} )
161
169
162
- it ( 'valid hash ' , ( done ) => {
170
+ it ( 'valid CIDv0 ' , ( done ) => {
163
171
gateway . inject ( {
164
172
method : 'GET' ,
165
173
url : '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o'
166
174
} , ( res ) => {
167
175
expect ( res . statusCode ) . to . equal ( 200 )
168
176
expect ( res . rawPayload ) . to . eql ( Buffer . from ( 'hello world' + '\n' ) )
169
177
expect ( res . payload ) . to . equal ( 'hello world' + '\n' )
178
+ expect ( res . headers [ 'cache-control' ] ) . to . equal ( 'public, max-age=29030400, immutable' )
179
+ expect ( res . headers [ 'etag' ] ) . to . equal ( '"QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o"' )
180
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( '/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o' )
181
+ expect ( res . headers [ 'suborigin' ] ) . to . equal ( 'ipfs000bafybeicg2rebjoofv4kbyovkw7af3rpiitvnl6i7ckcywaq6xjcxnc2mby' )
182
+
183
+ done ( )
184
+ } )
185
+ } )
186
+
187
+ /* TODO when support for CIDv1 lands
188
+ it('valid CIDv1', (done) => {
189
+ gateway.inject({
190
+ method: 'GET',
191
+ url: '/ipfs/TO-DO'
192
+ }, (res) => {
193
+ expect(res.statusCode).to.equal(200)
194
+ expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n'))
195
+ expect(res.payload).to.equal('hello world' + '\n')
196
+ expect(res.headers['etag']).to.equal(TO-DO)
197
+ expect(res.headers['x-ipfs-path']).to.equal(TO-DO)
198
+ expect(res.headers['suborigin']).to.equal(TO-DO)
199
+ expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable')
200
+
170
201
done()
171
202
})
172
203
})
204
+ */
173
205
174
206
it ( 'stream a large file' , ( done ) => {
175
207
let bigFileHash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
@@ -193,6 +225,10 @@ describe('HTTP Gateway', function () {
193
225
} , ( res ) => {
194
226
expect ( res . statusCode ) . to . equal ( 200 )
195
227
expect ( res . headers [ 'content-type' ] ) . to . equal ( 'image/jpeg' )
228
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( '/ipfs/' + kitty )
229
+ expect ( res . headers [ 'cache-control' ] ) . to . equal ( 'public, max-age=29030400, immutable' )
230
+ expect ( res . headers [ 'etag' ] ) . to . equal ( '"Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u"' )
231
+ expect ( res . headers [ 'suborigin' ] ) . to . equal ( 'ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4' )
196
232
197
233
let fileSignature = fileType ( res . rawPayload )
198
234
expect ( fileSignature . mime ) . to . equal ( 'image/jpeg' )
@@ -239,6 +275,10 @@ describe('HTTP Gateway', function () {
239
275
} , ( res ) => {
240
276
expect ( res . statusCode ) . to . equal ( 200 )
241
277
expect ( res . headers [ 'content-type' ] ) . to . equal ( 'text/html; charset=utf-8' )
278
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( '/ipfs/' + dir )
279
+ expect ( res . headers [ 'cache-control' ] ) . to . equal ( 'no-cache' )
280
+ expect ( res . headers [ 'etag' ] ) . to . equal ( undefined )
281
+ expect ( res . headers [ 'suborigin' ] ) . to . equal ( 'ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4' )
242
282
243
283
// check if the cat picture is in the payload as a way to check
244
284
// if this is an index of this directory
@@ -256,6 +296,11 @@ describe('HTTP Gateway', function () {
256
296
url : '/ipfs/' + dir
257
297
} , ( res ) => {
258
298
expect ( res . statusCode ) . to . equal ( 200 )
299
+ expect ( res . headers [ 'content-type' ] ) . to . equal ( 'text/html; charset=utf-8' )
300
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( '/ipfs/' + dir )
301
+ expect ( res . headers [ 'cache-control' ] ) . to . equal ( 'public, max-age=29030400, immutable' )
302
+ expect ( res . headers [ 'etag' ] ) . to . equal ( '"Qma6665X5k3zti8nKy7gmXK2BndNDSkgmANpV6k3FUjUeg"' )
303
+ expect ( res . headers [ 'suborigin' ] ) . to . equal ( 'ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe' )
259
304
expect ( res . rawPayload ) . to . deep . equal ( directoryContent [ 'index.html' ] )
260
305
done ( )
261
306
} )
@@ -269,6 +314,11 @@ describe('HTTP Gateway', function () {
269
314
url : '/ipfs/' + dir
270
315
} , ( res ) => {
271
316
expect ( res . statusCode ) . to . equal ( 200 )
317
+ expect ( res . headers [ 'content-type' ] ) . to . equal ( 'text/html; charset=utf-8' )
318
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( '/ipfs/' + dir )
319
+ expect ( res . headers [ 'cache-control' ] ) . to . equal ( 'public, max-age=29030400, immutable' )
320
+ expect ( res . headers [ 'etag' ] ) . to . equal ( '"QmUBKGqJWiJYMrNed4bKsbo1nGYGmY418WCc2HgcwRvmHc"' )
321
+ expect ( res . headers [ 'suborigin' ] ) . to . equal ( 'ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe' )
272
322
expect ( res . rawPayload ) . to . deep . equal ( directoryContent [ 'nested-folder/nested.html' ] )
273
323
done ( )
274
324
} )
@@ -283,6 +333,7 @@ describe('HTTP Gateway', function () {
283
333
} , ( res ) => {
284
334
expect ( res . statusCode ) . to . equal ( 301 )
285
335
expect ( res . headers [ 'location' ] ) . to . equal ( '/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/' )
336
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( undefined )
286
337
done ( )
287
338
} )
288
339
} )
@@ -296,6 +347,7 @@ describe('HTTP Gateway', function () {
296
347
} , ( res ) => {
297
348
expect ( res . statusCode ) . to . equal ( 302 )
298
349
expect ( res . headers [ 'location' ] ) . to . equal ( '/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html' )
350
+ expect ( res . headers [ 'x-ipfs-path' ] ) . to . equal ( undefined )
299
351
done ( )
300
352
} )
301
353
} )
0 commit comments