FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScriptSolidServer/test/range.test.js at patchAppend · bourgeoa/JavaScriptSolidServer · GitHub
bourgeoa
JavaScriptSolidServer
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScriptSolidServer
/
test
/
range.test.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
145 lines (124 loc) · 4.46 KB
Breadcrumbs
JavaScriptSolidServer
/
test
/
range.test.js
Copy path
File metadata and controls
145 lines (124 loc) · 4.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Range Request Tests
*
* Tests HTTP Range header support for partial content delivery.
*/
import
{
describe
,
it
,
before
,
after
}
from
'node:test'
;
import
assert
from
'node:assert'
;
import
{
startTestServer
,
stopTestServer
,
request
,
createTestPod
,
assertStatus
}
from
'./helpers.js'
;
describe
(
'Range Requests'
,
(
)
=>
{
const
testContent
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
;
// 36 bytes
before
(
async
(
)
=>
{
await
startTestServer
(
)
;
await
createTestPod
(
'rangetest'
)
;
// Create a test file with known content
await
request
(
'/rangetest/public/test.txt'
,
{
method
:
'PUT'
,
headers
:
{
'Content-Type'
:
'text/plain'
}
,
body
:
testContent
,
auth
:
'rangetest'
}
)
;
}
)
;
after
(
async
(
)
=>
{
await
stopTestServer
(
)
;
}
)
;
describe
(
'Accept-Ranges header'
,
(
)
=>
{
it
(
'should include Accept-Ranges: bytes for files'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/test.txt'
)
;
assertStatus
(
res
,
200
)
;
assert
.
strictEqual
(
res
.
headers
.
get
(
'Accept-Ranges'
)
,
'bytes'
)
;
}
)
;
it
(
'should include Accept-Ranges: none for containers'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/'
)
;
assertStatus
(
res
,
200
)
;
assert
.
strictEqual
(
res
.
headers
.
get
(
'Accept-Ranges'
)
,
'none'
)
;
}
)
;
}
)
;
describe
(
'Range header parsing'
,
(
)
=>
{
it
(
'should return 206 for valid range bytes=0-9'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/test.txt'
,
{
headers
:
{
'Range'
:
'bytes=0-9'
}
}
)
;
assertStatus
(
res
,
206
)
;
const
body
=
await
res
.
text
(
)
;
assert
.
strictEqual
(
body
,
'ABCDEFGHIJ'
)
;
assert
.
strictEqual
(
res
.
headers
.
get
(
'Content-Range'
)
,
'bytes 0-9/36'
)
;
assert
.
strictEqual
(
res
.
headers
.
get
(
'Content-Length'
)
,
'10'
)
;
}
)
;
it
(
'should return 206 for open-ended range bytes=30-'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/test.txt'
,
{
headers
:
{
'Range'
:
'bytes=30-'
}
}
)
;
assertStatus
(
res
,
206
)
;
const
body
=
await
res
.
text
(
)
;
assert
.
strictEqual
(
body
,
'456789'
)
;
assert
.
strictEqual
(
res
.
headers
.
get
(
'Content-Range'
)
,
'bytes 30-35/36'
)
;
}
)
;
it
(
'should return 206 for suffix range bytes=-6'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/test.txt'
,
{
headers
:
{
'Range'
:
'bytes=-6'
}
}
)
;
assertStatus
(
res
,
206
)
;
const
body
=
await
res
.
text
(
)
;
assert
.
strictEqual
(
body
,
'456789'
)
;
assert
.
strictEqual
(
res
.
headers
.
get
(
'Content-Range'
)
,
'bytes 30-35/36'
)
;
}
)
;
it
(
'should clamp end to file size for range exceeding file'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/test.txt'
,
{
headers
:
{
'Range'
:
'bytes=30-1000'
}
}
)
;
assertStatus
(
res
,
206
)
;
const
body
=
await
res
.
text
(
)
;
assert
.
strictEqual
(
body
,
'456789'
)
;
assert
.
strictEqual
(
res
.
headers
.
get
(
'Content-Range'
)
,
'bytes 30-35/36'
)
;
}
)
;
}
)
;
describe
(
'Multi-range requests'
,
(
)
=>
{
it
(
'should ignore multi-range and return 200 with full content'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/test.txt'
,
{
headers
:
{
'Range'
:
'bytes=0-5,10-15'
}
}
)
;
// Multi-range is not supported, should fall back to 200
assertStatus
(
res
,
200
)
;
const
body
=
await
res
.
text
(
)
;
assert
.
strictEqual
(
body
,
testContent
)
;
}
)
;
}
)
;
describe
(
'Invalid ranges'
,
(
)
=>
{
it
(
'should return 200 for invalid range format'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/test.txt'
,
{
headers
:
{
'Range'
:
'invalid'
}
}
)
;
// Invalid format, ignore Range header
assertStatus
(
res
,
200
)
;
}
)
;
it
(
'should return 200 for non-bytes range unit'
,
async
(
)
=>
{
const
res
=
await
request
(
'/rangetest/public/test.txt'
,
{
headers
:
{
'Range'
:
'chars=0-10'
}
}
)
;
assertStatus
(
res
,
200
)
;
}
)
;
}
)
;
describe
(
'RDF resources'
,
(
)
=>
{
it
(
'should ignore Range header for RDF resources'
,
async
(
)
=>
{
// Create an RDF resource
await
request
(
'/rangetest/public/data.jsonld'
,
{
method
:
'PUT'
,
headers
:
{
'Content-Type'
:
'application/ld+json'
}
,
body
:
JSON
.
stringify
(
{
'@id'
:
'#test'
,
'http://example.org/name'
:
'Test'
}
)
,
auth
:
'rangetest'
}
)
;
const
res
=
await
request
(
'/rangetest/public/data.jsonld'
,
{
headers
:
{
'Range'
:
'bytes=0-10'
}
}
)
;
// RDF resources don't support range requests
assertStatus
(
res
,
200
)
;
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL