-
Notifications
You must be signed in to change notification settings - Fork 168
Improve /add interop #380
base: master
Are you sure you want to change the base?
Improve /add interop #380
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,15 +143,7 @@ where | |
let content_type = field.content_type().map_err(AddError::Header)?; | ||
|
||
let next = match content_type { | ||
"application/octet-stream" => { | ||
|
||
// files are of the form "file-{1,2,3,..}" | ||
let _ = if field_name != "file" && !field_name.starts_with("file-") { | ||
Err(AddError::UnsupportedField(field_name.to_string())) | ||
} else { | ||
Ok(()) | ||
}?; | ||
|
||
"application/octet-stream" | "text/plain" => { | ||
let mut adder = FileAdder::default(); | ||
// how many bytes we have stored as blocks | ||
let mut total_written = 0u64; | ||
|
@@ -376,10 +368,14 @@ impl<D: fmt::Display> serde::Serialize for Quoted<D> { | |
#[cfg(test)] | ||
mod tests { | ||
use crate::v0::root_files::add; | ||
use ipfs::Node; | ||
use rand::distributions::Alphanumeric; | ||
use rand::Rng; | ||
use std::iter; | ||
|
||
#[tokio::test(max_threads = 1)] | ||
async fn add_single_block_file() { | ||
let ipfs = tokio_ipfs().await; | ||
let ipfs = Node::new("0").await; | ||
|
||
// this is from interface-ipfs-core, pretty much simplest add a buffer test case | ||
// but the body content is from the pubsub test case I copied this from | ||
|
@@ -408,15 +404,37 @@ mod tests { | |
); | ||
} | ||
|
||
async fn tokio_ipfs() -> ipfs::Ipfs<ipfs::TestTypes> { | ||
let options = ipfs::IpfsOptions::inmemory_with_generated_keys(); | ||
let (ipfs, fut) = ipfs::UninitializedIpfs::new(options, None) | ||
.await | ||
.start() | ||
.await | ||
.unwrap(); | ||
// copied from js-ipfs/packages/ipfs/test/http-api/inject/files.js | ||
#[tokio::test(max_threads = 1)] | ||
async fn js_multipart_test() { | ||
let ipfs = Node::new("0").await; | ||
let mut rng = rand::thread_rng(); | ||
|
||
let response = warp::test::request() | ||
.path("/add") | ||
.header( | ||
"Content-Type", | ||
"multipart/form-data; boundary=----------287032381131322", | ||
) | ||
.body( | ||
format!( | ||
"\r\n\ | ||
------------287032381131322\r\n\ | ||
Content-Disposition: form-data; name=\"test\"; filename=\"test.txt\"\r\n\ | ||
Content-Type: text/plain\r\n\ | ||
\r\n\ | ||
{}\r\n\ | ||
------------287032381131322--", | ||
iter::repeat(()) | ||
.map(|_| rng.sample(Alphanumeric)) | ||
.take(1024 * 1024 * 2) | ||
.collect::<String>() | ||
) | ||
.into_bytes(), | ||
) | ||
.reply(&add(&ipfs)) | ||
.await; | ||
|
||
tokio::spawn(fut); | ||
ipfs | ||
assert_eq!(response.status(), 200); | ||
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. is this test case is just to accept the text/plain as I guess js-ipfs accepts it? accepting text/plain sounds really strange be honest ... wouldn't that require some charset wrangling as well? I guess there's no issues if you assume ascii or utf8 but ... Why? 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. this was the way |
||
} | ||
} |
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.
not sure if this is a good idea to be removed. I mean if you think of a html form which is pretty much the basis for http multipart and fields with different names kinda should be different things so I'd like to retain some validation OR targeting here. Or are the go-ipfs and js-ipfs using random field names here? I'd rather see them "enumerated" here.
my comment is a bit off here, I think js-ipfs-http-client does the file-N.