Skip to content

Commit

Permalink
返回值格式修改
Browse files Browse the repository at this point in the history
  • Loading branch information
maike committed Sep 24, 2020
1 parent b167926 commit fabe943
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/agHttpCli/agHttpCli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ castAgency(PoolNameOrSocket, Method, Path, Headers, Body, Pid, IsSystem, Timeout
end
end.

-spec receiveRequestRet(requestId(), reference()) -> term() | {error, term()}.
-spec receiveRequestRet(requestId(), reference()) -> {StatusCode :: non_neg_integer(), Body :: binary(), Headers :: binary()} | {error, term()}.
receiveRequestRet(RequestId, MonitorRef) ->
receive
#miRequestRet{requestId = RequestId, reply = Reply} ->
erlang:demonitor(MonitorRef),
case Reply of
{ok, <<>>, _StatusCode, _Headers} ->
erlang:setelement(2, Reply, #{});
{ok, Body, _StatusCode, _Headers} ->
erlang:setelement(2, Reply, jiffy:decode(Body, [return_maps, copy_strings]));
{_StatusCode, Body, _Headers} ->
case Body of
<<>> ->
erlang:setelement(2, Reply, #{});
_ ->
erlang:setelement(2, Reply, jiffy:decode(Body, [return_maps, copy_strings]))
end;
_ ->
Reply
end;
Expand Down
4 changes: 2 additions & 2 deletions src/agHttpCli/agSslAgencyIns.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ handleMsg({ssl, Socket, Data},
#cliState{isHeadMethod = IsHeadMethod, backlogNum = BacklogNum, curInfo = CurInfo, requestsIns = RequestsIns, requestsOuts = RequestsOuts, recvState = RecvState} = CliState) ->
try agHttpProtocol:response(RecvState, Rn, RnRn, Data, IsHeadMethod) of
{done, #recvState{statusCode = StatusCode, headers = Headers, body = Body}} ->
agAgencyUtils:agencyReply(CurInfo, {ok, Body, StatusCode, Headers}),
agAgencyUtils:agencyReply(CurInfo, {StatusCode, Body, Headers}),
case RequestsOuts of
[] ->
case RequestsIns of
Expand Down Expand Up @@ -230,7 +230,7 @@ overReceiveSslData(#srvState{poolName = PoolName, serverName = ServerName, rn =
{ssl, Socket, Data} ->
try agHttpProtocol:response(RecvState, Rn, RnRn, Data, IsHeadMethod) of
{done, #recvState{statusCode = StatusCode, headers = Headers, body = Body}} ->
agAgencyUtils:agencyReply(CurInfo, {ok, Body, StatusCode, Headers}),
agAgencyUtils:agencyReply(CurInfo, {StatusCode, Body, Headers}),
case RequestsOuts of
[] ->
case RequestsIns of
Expand Down
4 changes: 2 additions & 2 deletions src/agHttpCli/agTcpAgencyIns.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ handleMsg({tcp, Socket, Data},
#cliState{isHeadMethod = IsHeadMethod, backlogNum = BacklogNum, curInfo = CurInfo, requestsIns = RequestsIns, requestsOuts = RequestsOuts, recvState = RecvState} = CliState) ->
try agHttpProtocol:response(RecvState, Rn, RnRn, Data, IsHeadMethod) of
{done, #recvState{statusCode = StatusCode, headers = Headers, body = Body}} ->
agAgencyUtils:agencyReply(CurInfo, {ok, Body, StatusCode, Headers}),
agAgencyUtils:agencyReply(CurInfo, {StatusCode, Body, Headers}),
case RequestsOuts of
[] ->
case RequestsIns of
Expand Down Expand Up @@ -229,7 +229,7 @@ overReceiveTcpData(#srvState{poolName = PoolName, serverName = ServerName, rn =
{tcp, Socket, Data} ->
try agHttpProtocol:response(RecvState, Rn, RnRn, Data, IsHeadMethod) of
{done, #recvState{statusCode = StatusCode, headers = Headers, body = Body}} ->
agAgencyUtils:agencyReply(CurInfo, {ok, Body, StatusCode, Headers}),
agAgencyUtils:agencyReply(CurInfo, {StatusCode, Body, Headers}),
case RequestsOuts of
[] ->
case RequestsIns of
Expand Down

0 comments on commit fabe943

Please sign in to comment.