You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 3. Set response’s response’s status to init["status"].
130
+
if(init.status!=null){
131
+
getResponse(response).status=init.status;
132
+
}
70
133
71
-
// Let type be null.
72
-
lettype=null
134
+
// 4. Set response’s response’s status message to init["statusText"].
135
+
if(init.statusText!=null){
136
+
getResponse(response).statusText=init.statusText;
137
+
}
73
138
74
-
// Switch on object:
75
-
if(Blob.prototype.isPrototypeOf(object)){
76
-
// Blob:
77
-
// 1. Set source to object.
78
-
// 2. Set length to object’s size.
79
-
// 3. If object’s type attribute is not the empty byte sequence, set type to its value.
80
-
stream=object.stream();
81
-
stream=object
82
-
length=object.size
83
-
}elseif(object==="string"){
84
-
// byte sequence:
85
-
// 1. Set source to object.
86
-
source=object
87
-
}
139
+
// 5. If init["headers"] exists, then fill response’s headers with init["headers"].
140
+
if(init.headers!=null){
141
+
// TODO: get headerlist
142
+
getResponse(response).headers=init.headers;
143
+
}
88
144
145
+
// 6. If body is non-null, then:
146
+
if(body!=null){
147
+
// 1. If response’s status is a null body status, then throw a TypeError.
148
+
// NOTE: 101 and 103 are included in null body status due to their use elsewhere. They do not affect this step.
149
+
if(nullBodyStatus(response.status)){
150
+
thrownewTypeError(
151
+
"Response with null body status cannot have body",
152
+
);
153
+
}
154
+
// 2. Set response’s body to body’s body.
155
+
getResponse(response).body=body.body;
156
+
// 3. If body’s type is non-null and response’s header list does not contain `Content-Type`, then append (`Content-Type`, body’s type) to response’s header list.
157
+
}
158
+
}
89
159
160
+
/**
161
+
* TODO: when implemented module, move to ext/fetch/body
162
+
* To extract a body with type from a byte sequence or BodyInit object object,
163
+
* with an optional boolean keepalive (default false)
// 2. If object is a ReadableStream object, then set stream to object.
170
+
// TODO: implement ReadableStream
171
+
// 3. Otherwise, if object is a Blob object, set stream to the result of running object’s get stream.
172
+
// 4. Otherwise, set stream to a new ReadableStream object, and set up stream with byte reading support.
173
+
// 5. Assert: stream is a ReadableStream object.
90
174
175
+
// 6, Let action be null.
176
+
let_action=null;
91
177
178
+
// 7. Let source be null.
179
+
letsource=null;
92
180
93
-
// BufferSource
94
-
// Set source to a copy of the bytes held by object.
181
+
// 8. Let length be null.
182
+
letlength=null;
95
183
96
-
// FormData
97
-
// Set action to this step: run the multipart/form-data encoding algorithm, with object’s entry list and UTF-8.
184
+
// Let type be null.
185
+
lettype=null;
98
186
99
-
// Set source to object.
187
+
// Switch on object:
188
+
if(typeofobject=="string"){
189
+
// scalar value string:
190
+
// Set source to the UTF-8 encoding of object.
191
+
// Set type to `text/plain;charset=UTF-8`.
192
+
source=object;
193
+
type="text/plain;charset=UTF-8";
194
+
}else{
195
+
console.error("TODO: these doesn't yet supported");
196
+
// Blob
197
+
// Set source to object.
198
+
// Set length to object’s size.
199
+
// If object’s type attribute is not the empty byte sequence, set type to its value.
100
200
101
-
// Set length to unclear, see html/6424 for improving this.
201
+
// byte sequence:
202
+
// Set source to object.
102
203
103
-
// Set type to `multipart/form-data; boundary=`, followed by the multipart/form-data boundary string generated by the multipart/form-data encoding algorithm.
204
+
// BufferSource:
205
+
// Set source to a copy of the bytes held by object.
104
206
105
-
// URLSearchParams
106
-
// Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list.
207
+
// FormData:
208
+
// Set action to this step: run the multipart/form-data encoding algorithm, with object’s entry list and UTF-8.
107
209
108
-
// Set type to `application/x-www-form-urlencoded;charset=UTF-8`.
210
+
// Set source to object.
109
211
110
-
// scalar value string
111
-
// Set source to the UTF-8 encoding of object.
212
+
// Set length to unclear, see html/6424 for improving this.
112
213
113
-
// Set type to `text/plain;charset=UTF-8`.
214
+
// Set type to `multipart/form-data; boundary=`, followed by the multipart/form-data boundary string generated by the multipart/form-data encoding algorithm.
114
215
115
-
// ReadableStream
116
-
// If keepalive is true, then throw a TypeError.
216
+
// URLSearchParams:
217
+
// Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list.
117
218
118
-
// If object is disturbed or locked, then throw a TypeError.
219
+
// Set type to `application/x-www-form-urlencoded;charset=UTF-8`.
119
220
120
-
// If source is a byte sequence, then set action to a step that returns source and length to source’s length.
221
+
// ReadableStream:
222
+
// If keepalive is true, then throw a TypeError.
223
+
// If object is disturbed or locked, then throw a TypeError.
224
+
}
121
225
122
-
// If action is non-null, then run these steps in parallel:
226
+
// 11. If source is a byte sequence, then set action to a step that returns source and length to source’s length.
123
227
124
-
// Run action.
228
+
// 12. If action is non-null, then run these steps in parallel:
229
+
// 1. Run action.
230
+
// Whenever one or more bytes are available and stream is not errored, enqueue the result of creating a Uint8Array from the available bytes into stream.
231
+
// When running action is done, close stream.
125
232
126
-
// Whenever one or more bytes are available and stream is not errored, enqueue the result of creating a Uint8Array from the available bytes into stream.
233
+
// 13. Let body be a body whose stream is stream, source is source, and length is length.
234
+
constbody={ stream, source, length };
127
235
128
-
// When running action is done, close stream.
236
+
// 14. Return (body, type).
237
+
return[body,type];
238
+
}
129
239
130
-
// Let body be a body whose stream is stream, source is source, and length is length.
0 commit comments