From 80ee81cf212030bdc3e8f53cea7ea0468d67210b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 18 Jul 2016 19:50:53 +0200 Subject: [PATCH 1/9] Added page about multipart stream builder --- components/multipart-stream-builder.rst | 4 ++++ index.rst | 1 + 2 files changed, 5 insertions(+) create mode 100644 components/multipart-stream-builder.rst diff --git a/components/multipart-stream-builder.rst b/components/multipart-stream-builder.rst new file mode 100644 index 0000000..e2e9329 --- /dev/null +++ b/components/multipart-stream-builder.rst @@ -0,0 +1,4 @@ +Multipart Stream Builder +======================== + +TODO \ No newline at end of file diff --git a/index.rst b/index.rst index d7b23d0..1e65596 100644 --- a/index.rst +++ b/index.rst @@ -83,6 +83,7 @@ for discussion around a future HTTP client PSR. components/adapter-integration-tests components/promise discovery + components/multipart-stream-builder .. toctree:: :hidden: From 1de855644b6002d0b06f7ad25d26edab034b427c Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 18 Jul 2016 20:13:46 +0200 Subject: [PATCH 2/9] Added multipart stream example --- components/multipart-stream-builder.rst | 60 ++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/components/multipart-stream-builder.rst b/components/multipart-stream-builder.rst index e2e9329..59c4357 100644 --- a/components/multipart-stream-builder.rst +++ b/components/multipart-stream-builder.rst @@ -1,4 +1,62 @@ Multipart Stream Builder ======================== -TODO \ No newline at end of file +A multipart stream is a special kind of stream that could be used when transferring files over HTTP. There is currently no PSR-7 support for multipart streams as they are considered to be normal streams with a special content. A multipart stream HTTP request may look like this: + +.. code-block:: http + + POST / HTTP1/1 + User-Agent: curl/7.21.2 (x86_64-apple-darwin) + Host: localhost:8080 + Accept: */* + Content-Length: 1143 + Expect: 100-continue + Content-Type: multipart/form-data; boundary=----------------------------83ff53821b7c + + ------------------------------83ff53821b7c + Content-Disposition: form-data; name="img"; filename="a.png" + Content-Type: application/octet-stream + + ?PNG + + IHD?wS??iCCPICC Profilex?T?kA?6n??Zk?x?"IY?hE?6?bk + Y?<ߡ)??????9Nyx?+=?Y"|@5-?M?S?%?@?H8??qR>?׋??inf???O?????b??N?????~N??>?!? + ??V?J?p?8?da?sZHO?Ln?}&???wVQ?y?g????E??0 + ?? + IDAc????????-IEND?B`? + ------------------------------83ff53821b7c + Content-Disposition: form-data; name="foo" + + bar + ------------------------------83ff53821b7c-- + + +In the request above you see a set of HTTP headers and a body with two streams. The body starts and ends with a "boundary" and it is also this boundary that separates the streams. + +Building a multipart stream +``````````````````````````` + +To build a multipart stream you may use the ``MultipartStreamBuilder``. It is not coupled to any stream implementation so it needs a ``StreamFactory`` to create the streams. + +.. code-block:: php + + $streamFactory = StreamFactoryDiscovery::find(); + $builder = new MultipartStreamBuilder($streamFactory); + $builder + ->addResource('foo', $stream) + ->addResource('bar', fopen($filePath, 'r'), ['filename' => 'bar.png']) + ->addResource('baz', 'string', ['headers' => ['Content-Type' => 'text/plain']]); + + $multipartStream = $builder->build(); + $boundary = $builder->getBoundary(); + + $request = MessageFactoryDiscovery::find()->createRequest( + 'POST', + 'http://example.com', + ['Content-Type' => 'multipart/form-data; boundary='.$boundary], + $multipartStream + ); + + $response = HttpClientDiscovery::find()->sendRequest($request); + +The second parameter of ``MultipartStreamBuilder::addResource()`` is the content of the stream. The supported input is the same as ``StreamFactory::createStream()``. From 49d0d3c59da12a50b724745d02aedc984bab4a56 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 18 Jul 2016 22:00:09 +0200 Subject: [PATCH 3/9] Added word "multipart" to spelling list --- spelling_word_list.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/spelling_word_list.txt b/spelling_word_list.txt index f6fc044..f54f2f4 100644 --- a/spelling_word_list.txt +++ b/spelling_word_list.txt @@ -15,6 +15,7 @@ namespace plugin plugins matchers +multipart param params Puli From 72175aa92e2976ca80e269aabc0997af17b65741 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 18 Jul 2016 22:12:41 +0200 Subject: [PATCH 4/9] bugfix --- components/multipart-stream-builder.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/multipart-stream-builder.rst b/components/multipart-stream-builder.rst index 59c4357..c620af8 100644 --- a/components/multipart-stream-builder.rst +++ b/components/multipart-stream-builder.rst @@ -3,7 +3,7 @@ Multipart Stream Builder A multipart stream is a special kind of stream that could be used when transferring files over HTTP. There is currently no PSR-7 support for multipart streams as they are considered to be normal streams with a special content. A multipart stream HTTP request may look like this: -.. code-block:: http +.. code-block:: none POST / HTTP1/1 User-Agent: curl/7.21.2 (x86_64-apple-darwin) From eb35e85234cb1f2aa7a35029937f691aaf969e74 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 09:29:47 +0200 Subject: [PATCH 5/9] minor --- components/multipart-stream-builder.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/multipart-stream-builder.rst b/components/multipart-stream-builder.rst index c620af8..f42c3e0 100644 --- a/components/multipart-stream-builder.rst +++ b/components/multipart-stream-builder.rst @@ -1,7 +1,7 @@ Multipart Stream Builder ======================== -A multipart stream is a special kind of stream that could be used when transferring files over HTTP. There is currently no PSR-7 support for multipart streams as they are considered to be normal streams with a special content. A multipart stream HTTP request may look like this: +A multipart stream is a special kind of stream that is used to transfer files over HTTP. There is currently no PSR-7 support for multipart streams as they are considered to be normal streams with a special content. A multipart stream HTTP request may look like this: .. code-block:: none From f1acbb4b22ee17be7d4795e3ccc3f479d2b41b6a Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 09:30:40 +0200 Subject: [PATCH 6/9] Added info about the boundary --- components/multipart-stream-builder.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/multipart-stream-builder.rst b/components/multipart-stream-builder.rst index f42c3e0..95757e1 100644 --- a/components/multipart-stream-builder.rst +++ b/components/multipart-stream-builder.rst @@ -31,7 +31,7 @@ A multipart stream is a special kind of stream that is used to transfer files ov ------------------------------83ff53821b7c-- -In the request above you see a set of HTTP headers and a body with two streams. The body starts and ends with a "boundary" and it is also this boundary that separates the streams. +In the request above you see a set of HTTP headers and a body with two streams. The body starts and ends with a "boundary" and it is also this boundary that separates the streams. That boundary also needs to be specified in the ``Content-Type`` header. Building a multipart stream ``````````````````````````` From 4b1fc520220014626a9166fc6ad6f6c64bbf3267 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 10:27:03 +0200 Subject: [PATCH 7/9] Added output from stream builder --- components/multipart-stream-builder.rst | Bin 2489 -> 2318 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/components/multipart-stream-builder.rst b/components/multipart-stream-builder.rst index 95757e14ef962f4f00a191929092a8a986ce3d92..f6607a98eabf8510f808601c39e2250920dcd461 100644 GIT binary patch delta 450 zcmdlf+$Xdlg;7f1P|uJ{0SG+ui%YB&QY#X33vyERlJj#Xe_=FKGBvkINi|L~NHtD2 zG2;R&)YU~1ocy2Jz#e3PbADb)YF>%1PikIzNrshzp(#YYqe5POQEp<6LUBn^YGN)9 zGqmfI5{s0q71AUdj)n<`R2HOKDP-m*rl;xy^*}6s zzkhFlpF3E)6qsaSU;xve9xg#Zwg?C_0tp77%J(_@_bLEsAdk<}#WAFUF&QKZM$D#$ z44Ocu6%dPw0|}5GPgg$|Ak!%UNPta63m32$s{2Y(D@ybWauPH1fPtoMm6TY8-E+`@ U28LHA&@Z5{MKgPI8cQ%M0BkaecK`qY delta 642 zcmb7B%}(1u5LT$TaHJ9^4z49Cezb|5Kw`qrM{uIX6@;__L^!l;Hk)9@SsTYFjs)ZZ zDsg}(;0=&CA)cbA9{VcYtS>zwn8VJenQy+C*}0v4{`lBV{V+4;j3(`9z(Z2%auF3Z zb{Tq^LON@vv)W>8<$vZ^2@L{|lQs>9u2@nPRevD4p3kUvK7p2D87fg?j0ZBcoLRn` znwvLQb1Gbk1I}dFGz`Lg5xL@$-`}Ln6Y`2#xlU&-XJyS+fz2qHSI9E;KmY!BYGv&9 zyZVOKaXl_*pKs|j9f+>3lx#VK+?O1V0$$W63%ZO(t}ik^i+Dr^QOIdO>56*oOM;wg z8N&wP+IHQsZLJ>q6ZIH}=#`Kcz-bRLbf<~)3dVV~da7F!n|~jcplrQ1im|eVrhc`v zMljw-0}I$e)dDWQZ{yD|sV_Q`d!YC&pr*i$bldm@r3f73D*{+(Qw&b42iOz1{w#^Z z<8K(DD^U{_AUTVMq)Z;$DVLbilMit!wK8_klH|L7*C?ntS~OJt?X^!Y9~#sD02-F3 AM*si- From 3eaa8a92847d56e2794848b3d969f176a52f1028 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 10:28:28 +0200 Subject: [PATCH 8/9] Removed binary data with placeholder --- components/multipart-stream-builder.rst | Bin 2318 -> 2269 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/components/multipart-stream-builder.rst b/components/multipart-stream-builder.rst index f6607a98eabf8510f808601c39e2250920dcd461..e5b4dc32a8fadb20054d3a3917e34be7455cfde8 100644 GIT binary patch delta 56 rcmeAZx+}QhER%Y4ED}u0%u6h)R7goINkkR~vM29lRNU;we1a7KTVE8v delta 105 zcmcaB*eA5%EK>vn0|S==5O{jH1OeG1Aj}9P7~b#S3q%S)4CL^6x;TbZFeXC;fh4o3 kA%iB6wgO@?aUcQG;_2$=0%STR0Ex+a85K8+GM``t05bk3$^ZZW From 3cb2d196d84bb9f859ad40965d8b840b7e8883ad Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 19 Jul 2016 10:29:40 +0200 Subject: [PATCH 9/9] Updated placeholder --- components/multipart-stream-builder.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/multipart-stream-builder.rst b/components/multipart-stream-builder.rst index e5b4dc3..120e508 100644 --- a/components/multipart-stream-builder.rst +++ b/components/multipart-stream-builder.rst @@ -19,9 +19,10 @@ A multipart stream is a special kind of stream that is used to transfer files ov Content-Length: 71 Content-Type: image/png - �PNG + ?PNG  - [][][][][][][binary data][][][][][][][] + ??? + IHDR??? ??? ?????? ???? IDATxc???51?)?:??????IEND?B`? --578de3b0e3c46 Content-Type: text/plain Content-Disposition: form-data; name="baz"