You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/01/27 20:02:54 UTC

[GitHub] [couchdb] nickva commented on a change in pull request #3340: Fix PUT of multipart/related attachments support for Transfer-Encoding: chunked

nickva commented on a change in pull request #3340:
URL: https://github.com/apache/couchdb/pull/3340#discussion_r565592179



##########
File path: src/couch/src/couch_httpd.erl
##########
@@ -589,7 +589,8 @@ recv_chunked(#httpd{mochi_req=MochiReq}, MaxChunkSize, ChunkFun, InitState) ->
     % Fun is called once with each chunk
     % Fun({Length, Binary}, State)
     % called with Length == 0 on the last time.
-    MochiReq:stream_body(MaxChunkSize, ChunkFun, InitState).
+    MochiReq:stream_body(MaxChunkSize, ChunkFun, InitState,
+        config:get_integer("httpd", "max_http_request_size", 4294967296)).

Review comment:
       Good call!

##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1242,6 +1242,14 @@ bulk_get_multipart_boundary() ->
 receive_request_data(Req) ->
     receive_request_data(Req, chttpd:body_length(Req)).
 
+receive_request_data(Req, Len) when Len == chunked ->
+    ChunkFun = fun({_Length, Binary}, _State) ->
+        self() ! {chunk, Req, Binary}

Review comment:
       I wonder if we need to pass the `Req` object around here for every chunk read as it's quite large. Was it done to match and assert later one that we only receive the message from the same request? Instead, we could create a `Ref` just so it's explicit. Perhaps something like:
   
   ```erlang
       Ref = make_ref(),
       ChunkFun = fun({_Length, Binary}, _State) ->
           self() ! {chunk, Ref, Binary}
       end,
       couch_httpd:recv_chunked(Req, 4096, ChunkFun, ok),
       GetChunk = fun GC() -> receive {chunk, Ref, Binary} -> {Binary, GC} end end,
       {receive {chunk, Ref, Binary} -> Binary end, GetChunk};
   ```
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org