-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add http_request_next method (large asset support) #129
Merged
ericswanson-dfinity
merged 7 commits into
next
from
ericswanson/126-http-server-chunked-assets
Mar 19, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e12dd87
feat: add http_get_chunk (large asset support)
ericswanson-dfinity 43c19be
Merge remote-tracking branch 'origin/next' into ericswanson/126-http-…
ericswanson-dfinity a2f62ad
Use http_request_next to match updated design
ericswanson-dfinity 4559048
tiny doc update
ericswanson-dfinity 1e11dc3
Remove HttpRequest parameter from http_request_next
ericswanson-dfinity 60ba952
format
ericswanson-dfinity a3f7fe5
Add TODO
ericswanson-dfinity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use crate::call::{AsyncCaller, SyncCaller}; | ||
use candid::de::ArgumentDecoder; | ||
use candid::parser::value::IDLValue; | ||
use candid::ser::IDLBuilder; | ||
use candid::CandidType; | ||
use ic_agent::{Agent, AgentError}; | ||
|
@@ -192,6 +193,25 @@ impl Argument { | |
} | ||
} | ||
|
||
/// Add an IDLValue Argument. If the current value of Argument is Raw, will set the | ||
/// result to an error. If the current value is an error, will do nothing. | ||
pub fn push_value_arg(&mut self, arg: IDLValue) { | ||
match self.0 { | ||
Ok(ArgumentType::Idl(ref mut idl_builder)) => { | ||
let result = idl_builder.value_arg(&arg); | ||
if let Err(e) = result { | ||
self.0 = Err(AgentError::CandidError(Box::new(e))) | ||
} | ||
} | ||
Ok(ArgumentType::Raw(_)) => { | ||
self.0 = Err(AgentError::MessageError( | ||
"Cannot overwrite a Raw Argument with a non-raw argument.".to_owned(), | ||
)) | ||
} | ||
_ => {} | ||
} | ||
} | ||
|
||
/// Set the argument as raw, replacing any value that was there before. If the | ||
/// current argument was an error, does nothing. | ||
pub fn set_raw_arg(&mut self, arg: Vec<u8>) { | ||
|
@@ -258,6 +278,17 @@ impl<'agent, 'canister: 'agent, Interface> SyncCallBuilder<'agent, 'canister, In | |
self | ||
} | ||
|
||
/// Add an argument to the candid argument list. This requires Candid arguments, if | ||
/// there is a raw argument set (using [with_arg_raw]), this will fail. | ||
/// TODO: make this method unnecessary https://github.com/dfinity/agent-rs/issues/132 | ||
pub fn with_value_arg( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above. |
||
mut self, | ||
arg: IDLValue, | ||
) -> SyncCallBuilder<'agent, 'canister, Interface> { | ||
self.arg.push_value_arg(arg); | ||
self | ||
} | ||
|
||
/// Replace the argument with raw argument bytes. This will overwrite the current | ||
/// argument set, so calling this method twice will discard the first argument. | ||
pub fn with_arg_raw(mut self, arg: Vec<u8>) -> SyncCallBuilder<'agent, 'canister, Interface> { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDLValue
implements CandidType, so you should be able to usepush_idl_arg
with anIDLValue
. Was there any issue with using that other function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
IDLValue::ty()
calls unreachable() : https://github.com/dfinity/candid/blob/master/rust/candid/src/parser/value.rs#L326called from here: https://github.com/dfinity/candid/blob/master/rust/candid/src/ser.rs#L28