summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_httpd_db.erl22
-rw-r--r--src/couchdb/couch_stream.erl3
2 files changed, 10 insertions, 15 deletions
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index ab14a7d1..b0fbe8de 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -883,7 +883,8 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
Headers = [
{"ETag", Etag},
{"Cache-Control", "must-revalidate"},
- {"Content-Type", binary_to_list(Type)}
+ {"Content-Type", binary_to_list(Type)},
+ {"Accept-Ranges", "bytes"}
] ++ case ReqAcceptsAttEnc of
true ->
[{"Content-Encoding", atom_to_list(Enc)}];
@@ -925,22 +926,13 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
AttFun(Att, fun(Seg, _) -> send_chunk(Resp, Seg) end, {ok, Resp}),
last_chunk(Resp);
_ ->
- #att{data={_,StreamInfo}} = Att, %% layering violation
- SupportsRange = case StreamInfo of
- [{_,_}|_] -> true;
- _ -> false
- end,
Ranges = MochiReq:get(range),
HasSingleRange = case Ranges of
[_] -> true;
_ -> false
end,
- Headers1 = case SupportsRange of
- false ->[{<<"Accept-Ranges">>, <<"none">>}] ++ Headers;
- true -> [{<<"Accept-Ranges">>, <<"bytes">>}] ++ Headers
- end,
if
- Enc == identity andalso SupportsRange == true andalso HasSingleRange == true ->
+ Enc == identity andalso HasSingleRange == true ->
[{From, To}] = Ranges,
{From1, To1} = case {From, To} of
{none, To} ->
@@ -956,13 +948,13 @@ db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
true ->
ok
end,
- Headers2 = [{<<"Content-Range">>,
+ Headers1 = [{<<"Content-Range">>,
?l2b(io_lib:format("bytes ~B-~B/~B", [From1, To1, Len]))}]
- ++ Headers1,
- {ok, Resp} = start_response_length(Req, 206, Headers2, To1 - From1 + 1),
+ ++ Headers,
+ {ok, Resp} = start_response_length(Req, 206, Headers1, To1 - From1 + 1),
couch_doc:range_att_foldl(Att, From1, To1 + 1, fun(Seg, _) -> send(Resp, Seg) end, {ok, Resp});
true ->
- {ok, Resp} = start_response_length(Req, 200, Headers1, Len),
+ {ok, Resp} = start_response_length(Req, 200, Headers, Len),
AttFun(Att, fun(Seg, _) -> send(Resp, Seg) end, {ok, Resp})
end
end
diff --git a/src/couchdb/couch_stream.erl b/src/couchdb/couch_stream.erl
index 9209cfec..60af1c2b 100644
--- a/src/couchdb/couch_stream.erl
+++ b/src/couchdb/couch_stream.erl
@@ -129,6 +129,9 @@ range_foldl(Fd, PosList, From, To, Fun, Acc) ->
range_foldl(_Fd, _PosList, _From, To, Off, _Fun, Acc) when Off >= To ->
Acc;
+range_foldl(Fd, [Pos|Rest], From, To, Off, Fun, Acc) when is_integer(Pos) -> % old-style attachment
+ {ok, Bin} = couch_file:pread_iolist(Fd, Pos),
+ range_foldl(Fd, [{Pos, iolist_size(Bin)}] ++ Rest, From, To, Off, Fun, Acc);
range_foldl(Fd, [{_Pos, Size}|Rest], From, To, Off, Fun, Acc) when From > Off + Size ->
range_foldl(Fd, Rest, From, To, Off + Size, Fun, Acc);
range_foldl(Fd, [{Pos, Size}|Rest], From, To, Off, Fun, Acc) ->