Github user kxepal commented on a diff in the pull request:

    https://github.com/apache/couchdb-chttpd/pull/114#discussion_r60698407
  
    --- Diff: src/chttpd_db.erl ---
    @@ -1628,6 +1633,44 @@ bulk_get_open_doc_revs1(Db, Props, _, {DocId, Revs, 
Options}) ->
                 {DocId, Results, Options}
         end.
     
    +maybe_remove_exceed_docs(DocArray0) ->
    +    case config:get_boolean("couchdb", "use_max_document_size", false) of
    +        true ->
    +            Max = config:get_integer("couchdb", "max_document_size",
    +                16777216),
    +            {ExceedDocs, DocsArray} = lists:splitwith(fun (Doc) ->
    +                exceed_doc_size(Doc, Max)
    +            end, DocArray0),
    +            ExceedErrs = lists:map (fun ({Doc}) ->
    +            DocId = case couch_util:get_value(<<"_id">>, Doc) of
    +                undefined -> <<"no id generated since update failed">>;
    +                Id0 -> Id0
    +            end,
    +            Reason = lists:concat(["Document exceeded max_document_size:",
    +                " of ", Max, " bytes"]),
    +            {[{id, DocId}, {error, <<"request_entity_too_large">>},
    +                {reason, ?l2b(Reason)}]}
    +            end, ExceedDocs),
    +            {ExceedErrs, DocsArray};
    +        false ->
    +            {[], DocArray0}
    +    end.
    +
    +exceed_doc_size(JsonBody, MaxSize) ->
    +    size(term_to_binary(JsonBody)) > MaxSize.
    --- End diff --
    
    N.B.: need to test how `size(term_to_binary(JsonBody))` will be different 
from `size(?JSON_ENCODE(JsonBody))`. Quick checking shows, that it produces 
greater number, but I wonder how much deviation will be for something bigger.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to