-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(as-sdk): correctly serialise request bodies
Closes: #72
- Loading branch information
1 parent
e3230b6
commit 02c6530
Showing
6 changed files
with
111 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
import { JSON } from 'json-as/assembly'; | ||
import { HttpFetchOptions, HttpFetch, HttpResponse } from "./http"; | ||
import { HttpFetchOptions, HttpFetchAction, HttpResponse } from './http'; | ||
import { call_result_write, proxy_http_fetch } from './bindings/seda_v1'; | ||
import { PromiseStatus } from './promise'; | ||
|
||
export function proxyHttpFetch(url: string, options: HttpFetchOptions = new HttpFetchOptions()): PromiseStatus<HttpResponse, HttpResponse> { | ||
const action = new HttpFetch(url, options); | ||
const actionStr = JSON.stringify(action); | ||
export function proxyHttpFetch( | ||
url: string, | ||
options: HttpFetchOptions = new HttpFetchOptions() | ||
): PromiseStatus<HttpResponse, HttpResponse> { | ||
const action = new HttpFetchAction(url, options); | ||
const actionStr = JSON.stringify(action); | ||
|
||
const buffer = String.UTF8.encode(actionStr); | ||
const utf8ptr = changetype<usize>(buffer); | ||
const buffer = String.UTF8.encode(actionStr); | ||
const utf8ptr = changetype<usize>(buffer); | ||
|
||
const responseLength = proxy_http_fetch(utf8ptr, buffer.byteLength); | ||
const responseBuffer = new ArrayBuffer(responseLength); | ||
const responseBufferPtr = changetype<usize>(responseBuffer); | ||
const responseLength = proxy_http_fetch(utf8ptr, buffer.byteLength); | ||
const responseBuffer = new ArrayBuffer(responseLength); | ||
const responseBufferPtr = changetype<usize>(responseBuffer); | ||
|
||
call_result_write(responseBufferPtr, responseLength); | ||
call_result_write(responseBufferPtr, responseLength); | ||
|
||
const response = String.UTF8.decode(responseBuffer); | ||
const response = String.UTF8.decode(responseBuffer); | ||
|
||
return PromiseStatus.fromStr( | ||
response, | ||
new HttpResponse(), | ||
new HttpResponse(), | ||
); | ||
} | ||
return PromiseStatus.fromStr( | ||
response, | ||
new HttpResponse(), | ||
new HttpResponse() | ||
); | ||
} |