anchor.diff:                      CType ->
                           list_to_binary(CType)
                       end,
  -                data = ?COUCH:att_receiver(Req, chttpd:body_length(Req)),
  -                len = case chttpd:header_value(Req,"Content-Length") of
  +                data = fabric:att_receiver(Req, chttpd:body_length(Req)),
  +                att_len = case chttpd:header_value(Req,"Content-Length") of
                       undefined ->
                           undefined;
                       Length ->
                           list_to_integer(Length)
  -                    end
  -                    }]
  +                    end,
  +                md5 = get_md5_header(Req),
  +                encoding = case string:to_lower(string:strip(
  +                    chttpd:header_value(Req,"Content-Encoding","identity")
  +                )) of
  +                "identity" ->
  +                   identity;
  +                "gzip" ->
  +                   gzip;
  +                _ ->
  +                   throw({
  +                       bad_ctype,
  +                       "Only gzip and identity content-encodings are supported"
  +                   })
  +                end
  +            }]
       end,
   
       Doc = case extract_header_rev(Req, chttpd:qs_value(Req, "rev")) of
  
positive.code:     case [A || A <- Atts, A#att.name == FileName] of
      [] ->
          throw({not_found, "Document is missing attachment"});
      [#att{type=Type, len=Len}=Att] ->
          Etag = chttpd:doc_etag(Doc),
          chttpd:etag_respond(Req, Etag, fun() ->
              {ok, Resp} = start_response_length(Req, 200, [
                  {"ETag", Etag},
                  {"Cache-Control", "must-revalidate"},
                  {"Content-Type", binary_to_list(Type)}
                  ], integer_to_list(Len)),
              couch_doc:att_foldl(Att, fun(BinSegment, _) ->
                  send(Resp, BinSegment)
              end, {ok, Resp})
          end)
      end;
  
  
  
negative.code:     end;
  parse_doc_format(_BadFormatStr) ->
      throw({bad_request, <<"Invalid doc format">>}).
  
  get_md5_header(Req) ->
      ContentMD5 = couch_httpd:header_value(Req, "Content-MD5"),
      Length = couch_httpd:body_length(Req),
      Trailer = couch_httpd:header_value(Req, "Trailer"),
      case {ContentMD5, Length, Trailer} of
          _ when is_list(ContentMD5) orelse is_binary(ContentMD5) ->
              base64:decode(ContentMD5);
          {_, chunked, undefined} ->
              <<>>;
          {_, chunked, _} ->
              case re:run(Trailer, "\\bContent-MD5\\b", [caseless]) of
                  {match, _} ->
                      md5_in_footer;
                  _ ->
                      <<>>
              end;
          _ ->
              <<>>
      end.
  
  parse_doc_query(Req) ->
      lists:foldl(fun({Key,Value}, Args) ->
  