MCPcopy Create free account
hub / github.com/angular/dev-infra / bodyMixinMethods

Function bodyMixinMethods

github-actions/saucelabs/set-saucelabs-env.js:5791–5851  ·  view source on GitHub ↗
(instance)

Source from the content-addressed store, hash-verified

5789 length: body.length,
5790 source: body.source
5791 };
5792 }
5793 function throwIfAborted(state) {
5794 if (state.aborted) {
5795 throw new DOMException("The operation was aborted.", "AbortError");
5796 }
5797 }
5798 function bodyMixinMethods(instance) {
5799 const methods = {
5800 blob() {
5801 return consumeBody(this, (bytes) => {
5802 let mimeType = bodyMimeType(this);
5803 if (mimeType === null) {
5804 mimeType = "";
5805 } else if (mimeType) {
5806 mimeType = serializeAMimeType(mimeType);
5807 }
5808 return new Blob2([bytes], { type: mimeType });
5809 }, instance);
5810 },
5811 arrayBuffer() {
5812 return consumeBody(this, (bytes) => {
5813 return new Uint8Array(bytes).buffer;
5814 }, instance);
5815 },
5816 text() {
5817 return consumeBody(this, utf8DecodeBytes, instance);
5818 },
5819 json() {
5820 return consumeBody(this, parseJSONFromBytes, instance);
5821 },
5822 formData() {
5823 return consumeBody(this, (value) => {
5824 const mimeType = bodyMimeType(this);
5825 if (mimeType !== null) {
5826 switch (mimeType.essence) {
5827 case "multipart/form-data": {
5828 const parsed = multipartFormDataParser(value, mimeType);
5829 if (parsed === "failure") {
5830 throw new TypeError("Failed to parse body as FormData.");
5831 }
5832 const fd = new FormData();
5833 fd[kState] = parsed;
5834 return fd;
5835 }
5836 case "application/x-www-form-urlencoded": {
5837 const entries = new URLSearchParams(value.toString());
5838 const fd = new FormData();
5839 for (const [name, value2] of entries) {
5840 fd.append(name, value2);
5841 }
5842 return fd;
5843 }
5844 }
5845 }
5846 throw new TypeError(
5847 'Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".'
5848 );

Callers 1

mixinBodyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected