Skip to content

Commit

Permalink
Simplified - use directly integer_to_list in place of ibrowse_lib:dec…
Browse files Browse the repository at this point in the history
…2hex everywhere.
  • Loading branch information
fdmanana committed Nov 10, 2010
1 parent 5715632 commit 41fe7ac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/ibrowse_http_client.erl
Expand Up @@ -544,7 +544,7 @@ do_send_body1(Source, Resp, State, TE) ->
maybe_chunked_encode(Data, false) ->
Data;
maybe_chunked_encode(Data, true) ->
[ibrowse_lib:dec2hex(byte_size(to_binary(Data))), "\r\n", Data, "\r\n"].
[integer_to_list(byte_size(to_binary(Data)), 16), "\r\n", Data, "\r\n"].

do_close(#state{socket = undefined}) -> ok;
do_close(#state{socket = Sock,
Expand Down Expand Up @@ -927,23 +927,23 @@ chunk_request_body(Body, _ChunkSize, Acc) when Body == <<>>; Body == [] ->
chunk_request_body(Body, ChunkSize, Acc) when is_binary(Body),
size(Body) >= ChunkSize ->
<<ChunkBody:ChunkSize/binary, Rest/binary>> = Body,
Chunk = [ibrowse_lib:dec2hex(ChunkSize),"\r\n",
Chunk = [integer_to_list(ChunkSize, 16),"\r\n",
ChunkBody, "\r\n"],
chunk_request_body(Rest, ChunkSize, [Chunk | Acc]);
chunk_request_body(Body, _ChunkSize, Acc) when is_binary(Body) ->
BodySize = size(Body),
Chunk = [ibrowse_lib:dec2hex(BodySize),"\r\n",
Chunk = [integer_to_list(BodySize, 16),"\r\n",
Body, "\r\n"],
LastChunk = "0\r\n",
lists:reverse(["\r\n", LastChunk, Chunk | Acc]);
chunk_request_body(Body, ChunkSize, Acc) when length(Body) >= ChunkSize ->
{ChunkBody, Rest} = split_list_at(Body, ChunkSize),
Chunk = [ibrowse_lib:dec2hex(ChunkSize),"\r\n",
Chunk = [integer_to_list(ChunkSize, 16),"\r\n",
ChunkBody, "\r\n"],
chunk_request_body(Rest, ChunkSize, [Chunk | Acc]);
chunk_request_body(Body, _ChunkSize, Acc) when is_list(Body) ->
BodySize = length(Body),
Chunk = [ibrowse_lib:dec2hex(BodySize),"\r\n",
Chunk = [integer_to_list(BodySize, 16),"\r\n",
Body, "\r\n"],
LastChunk = "0\r\n",
lists:reverse(["\r\n", LastChunk, Chunk | Acc]).
Expand Down
6 changes: 0 additions & 6 deletions src/ibrowse_lib.erl
Expand Up @@ -19,7 +19,6 @@
url_encode/1,
decode_rfc822_date/1,
status_code/1,
dec2hex/1,
drv_ue/1,
drv_ue/2,
encode_base64/1,
Expand Down Expand Up @@ -163,11 +162,6 @@ status_code(507) -> insufficient_storage;
status_code(X) when is_list(X) -> status_code(list_to_integer(X));
status_code(_) -> unknown_status_code.

%% @doc Returns a string with the hexadecimal representation of a given decimal.
%% N = integer() -- the number to represent as hex
%% @spec dec2hex(N::integer()) -> string()
dec2hex(N) -> integer_to_list(N, 16).

%% @doc Implements the base64 encoding algorithm. The output data type matches in the input data type.
%% @spec encode_base64(In) -> Out
%% In = string() | binary()
Expand Down

0 comments on commit 41fe7ac

Please sign in to comment.