{"id":15056438,"url":"https://github.com/sirwumpus/erlang-httpb","last_synced_at":"2026-01-02T04:04:21.122Z","repository":{"id":56824366,"uuid":"445339502","full_name":"SirWumpus/erlang-httpb","owner":"SirWumpus","description":"An HTTP basic client.","archived":false,"fork":false,"pushed_at":"2023-01-03T17:03:26.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T10:23:38.490Z","etag":null,"topics":["erlang","http-client","low-level"],"latest_commit_sha":null,"homepage":"","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SirWumpus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-06T23:27:28.000Z","updated_at":"2022-05-30T20:54:10.000Z","dependencies_parsed_at":"2023-02-01T08:02:24.061Z","dependency_job_id":null,"html_url":"https://github.com/SirWumpus/erlang-httpb","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/SirWumpus/erlang-httpb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-httpb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-httpb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-httpb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-httpb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SirWumpus","download_url":"https://codeload.github.com/SirWumpus/erlang-httpb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SirWumpus%2Ferlang-httpb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28168764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2026-01-02T02:00:06.235Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["erlang","http-client","low-level"],"created_at":"2024-09-24T21:51:29.026Z","updated_at":"2026-01-02T04:04:21.091Z","avatar_url":"https://github.com/SirWumpus.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"httpb\n=====\n\nAn HTTP Basic client that provides finer granularity over the handling of HTTP requests and responses.\n\n\nData Types\n----------\n\n* Url               :: string() | binary().\n* Body              :: binary().\n* Data              :: binary().\n* Headers           :: #{atom() =\u003e binary()}.\n* Reason            :: term().\n* Method            :: delete | get | head | options | post | put | trace.\n* Result            :: #{status =\u003e integer(), headers =\u003e headers(), body =\u003e body()}.\n* Socket            :: gen_tcp:socket() | ssl:sslsocket().\n* Options           :: #{socket_opts =\u003e proplists:proplist(), timeout =\u003e timeout()}.\n* Connection        :: #{scheme =\u003e http | https, host =\u003e string(), port =\u003e non_neg_integer(), socket =\u003e socket()}.\n\n\nExports\n-------\n\n### httpb:close(Connection) -\u003e ok | {error, Reason}\n\nClose the `Connection`.\n\n- - -\n### httpb:content_length(Headers) -\u003e Length.\n\nReturn the content length.\n\n- - -\n### httpb:controlling_process(Connection, Pid) -\u003e ok | {error, Reason}\n\nSee `gen_tcp:controlling_process/2` or `ssl:controlling_process/2`.\n\n- - -\n### httpb:getopts(Connection, Options) -\u003e {ok, Options} | {error, Reason}\n\nSee `inet:getopts/2` or `ssl:getopts/2`.\n\n- - -\n### httpb:is_chunked(Headers) -\u003e true | false\n\nReturn true if `Transfer-Encoding` is present and equal to `chunked`.\n\n- - -\n### httpb:is_keep_alive(Headers) -\u003e true | false\n\nReturn false if `Connection` header is present and equal to `close`; otherwise true.\n\n- - -\n### httpb:one_request(Method, Url, Headers, Body) -\u003e {ok, Result} | {error, Reason}\n### httpb:one_request(Method, Url, Headers, Body, Options) -\u003e {ok, Result} | {error, Reason}\n\nA helper function for when the caller needs only make a single request and close the connection.\n\n- - -\n### httpb:recv(Connection, Length) -\u003e {ok, Data} | {error, Reason}\n### httpb:recv(Connection, Length, Timeout) -\u003e {ok, Data} | {error, Reason}\n\nReceives a packet from a `Connection` in passive mode (`{active, false}`).  A closed `Connection` is indicated by return value `{error, closed}`.\n\nArgument `Length` is meaningful only when the `Connection` is in mode raw and denotes the number of bytes to read.  If `Length = 0`, all available bytes are returned.  If `Length \u003e 0`, exactly `Length` bytes are returned, or an error; possibly discarding less than `Length` bytes of data when the `Connection` gets closed from the other side.\n\nOptional argument `Timeout` specifies a time-out in milliseconds; default value is 30000.\n\n- - -\n### httpb:recv_chunk(Connection) -\u003e {ok, Data} | {error, Reason}\n### httpb:recv_chunk(Connection, Timeout) -\u003e {ok, Data} | {error, Reason}\n\nRead the next chunk from the `Connection`.  A zero length `Data` chunk typically indicated end of the response body.\n\nOptional argument `Timeout` specifies a time-out in milliseconds; default value is 30000.\n\n- - -\n### httpb:request(Method, Url, Headers, Body) -\u003e {ok, Connection} | {error, Reason}\n### httpb:request(Method, Url, Headers, Body, Options) -\u003e {ok, Connection} | {error, Reason}\n\nStart an initial HTTP/1.1 request, returning the `Connection` on success.\n\nThe `Options` map can contain `socket_opts` and/or `timeout`.  `socket_opts` is a property list of socket options passed through to `gen_tcp:connect/4` or `ssl:connect/4`.  The connection `timeout` defaults to 30000 milliseconds.\n\n- - -\n### httpb:request(Connection, Method, Url, Headers, Body) -\u003e {ok, Connection} | {error, Reason}\n\nGiven an already open connection, send a request.\n\n`Headers` is a map keyed by header names as atoms, eg. `accept` or `content_type`, underscores will be converted to hyphens (-).  The values must be binary strings.  A `host` header will be generated from the `Connection` host and port, not the `Url`.\n\nBy design there is no help with the `content_length` header; its under the caller's control.  Its possible to specify a non-zero `content_length` and provide an initially empty body.  The caller should follow a successful request with `httpb:send(Connection, Body)`.\n\nThe `Body` argument is ignored for `head` and `trace` methods.  To support `OPTIONS * HTTP/1.1`, specify a `Url` without a path `http://localhost`, which only applies to the `options` method.\n\n- - -\n### httpb:response(Connection) -\u003e {ok, Result} | {error, Reason}\n### httpb:response(Connection, Timeout) -\u003e {ok, Result} | {error, Reason}\n\nRead the HTTP response line and headers.  If the response is chunked, then no `body` is returned, see `httpb:recv_chunk/1,2`; otherwise read as much of the body as possible.\n\nOptional argument `Timeout` specifies a time-out in milliseconds; default value is 30000.\n\n- - -\n### httpb:send(Connection, Data) -\u003e ok | {error, Reason}\n\nSend `Data` to the `Connection`.\n\n- - -\n### httpb:send_chunk(Connection, Data) -\u003e ok | {error, Reason}\n\nSend `Data` as an HTTP formatted chunk to the `Connection`.\n\n- - -\n### httpb:setopts(Connection, Options) -\u003e ok | {error, Reason}\n\nSee `inet:setopts/2` or `ssl:setopts/2`.\n\n\nExamples\n--------\n\n* Simple request-response-close:\n\n```erlang\n1\u003e {ok, Conn} = httpb:request(get, \"https://example.com/\", #{}, \u003c\u003c\u003e\u003e).\n{ok,#{host =\u003e \u003c\u003c\"example.com\"\u003e\u003e,port =\u003e 443,scheme =\u003e https,\n      socket =\u003e\n          {sslsocket,{gen_tcp,#Port\u003c0.5\u003e,tls_connection,undefined},\n                     [\u003c0.113.0\u003e,\u003c0.112.0\u003e]}}}\n2\u003e {ok, Result} = httpb:response(Conn).\n{ok,#{body =\u003e\n          \u003c\u003c\"\u003c!doctype html\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n    \u003ctitle\u003eExample Domain\u003c/title\u003e\\n\\n ... \u003c/html\u003e\\n\"\u003e\u003e,\n      headers =\u003e\n          #{age =\u003e \u003c\u003c\"408052\"\u003e\u003e,cache_control =\u003e \u003c\u003c\"max-age=604800\"\u003e\u003e,\n            content_length =\u003e \u003c\u003c\"1256\"\u003e\u003e,\n            content_type =\u003e \u003c\u003c\"text/html; charset=UTF-8\"\u003e\u003e,\n            date =\u003e \u003c\u003c\"Thu, 06 Jan 2022 17:48:22 GMT\"\u003e\u003e,\n            etag =\u003e \u003c\u003c\"\\\"3147526947+gzip+ident\\\"\"\u003e\u003e,\n            expires =\u003e \u003c\u003c\"Thu, 13 Jan 2022 17:48:22 GMT\"\u003e\u003e,\n            last_modified =\u003e \u003c\u003c\"Thu, 17 Oct 2019 07:18:26 GMT\"\u003e\u003e,\n            server =\u003e \u003c\u003c\"ECS (chb/0286)\"\u003e\u003e,\n            vary =\u003e \u003c\u003c\"Accept-Encoding\"\u003e\u003e,x_cache =\u003e \u003c\u003c\"HIT\"\u003e\u003e},\n      status =\u003e 200}}\n3\u003e httpb:close(Conn).\nok\n```\n\n* If the connection is not going to be reused for more requests, the above can be done using the helper function `one_request/4,5`:\n\n```erlang\n1\u003e httpb:one_request(get, \"https://example.com/\", #{}, \u003c\u003c\u003e\u003e).\n{ok,#{body =\u003e\n          \u003c\u003c\"\u003c!doctype html\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n    \u003ctitle\u003eExample Domain\u003c/title\u003e\\n\\n    \u003cmeta charset=\\\"utf-8\\\" /\u003e\\n    \u003cmeta \"...\u003e\u003e,\n      headers =\u003e\n          #{age =\u003e \u003c\u003c\"554779\"\u003e\u003e,cache_control =\u003e \u003c\u003c\"max-age=604800\"\u003e\u003e,\n            content_length =\u003e \u003c\u003c\"1256\"\u003e\u003e,\n            content_type =\u003e \u003c\u003c\"text/html; charset=UTF-8\"\u003e\u003e,\n            date =\u003e \u003c\u003c\"Sat, 21 May 2022 13:01:06 GMT\"\u003e\u003e,\n            etag =\u003e \u003c\u003c\"\\\"3147526947+ident\\\"\"\u003e\u003e,\n            expires =\u003e \u003c\u003c\"Sat, 28 May 2022 13:01:06 GMT\"\u003e\u003e,\n            last_modified =\u003e \u003c\u003c\"Thu, 17 Oct 2019 07:18:26 GMT\"\u003e\u003e,\n            server =\u003e \u003c\u003c\"ECS (chb/0286)\"\u003e\u003e,\n            vary =\u003e \u003c\u003c\"Accept-Encoding\"\u003e\u003e,x_cache =\u003e \u003c\u003c\"HIT\"\u003e\u003e},\n      status =\u003e 200}}\n2\u003e\n```\n\n* It is possible to send multiple requests over the same connection:\n\n```erlang\n1\u003e {ok, Conn} = httpb:request(get, \"http://snert.com/about.html\", #{}, \u003c\u003c\u003e\u003e).\n{ok,#{host =\u003e \u003c\u003c\"snert.com\"\u003e\u003e,method =\u003e get,port =\u003e 80,\n      scheme =\u003e http,socket =\u003e #Port\u003c0.7\u003e}}\n2\u003e {ok, About} = httpb:response(Conn).\n{ok,#{body =\u003e\n          \u003c\u003c\"\u003c!DOCTYPE html PUBLIC \\\"-//W3C//DTD XHTML 1.0 Strict//EN\\\"\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n\u003cmeta http-equiv=\\\"Content-Type\\\" \"...\u003e\u003e,\n      headers =\u003e\n          #{accept_ranges =\u003e \u003c\u003c\"bytes\"\u003e\u003e,connection =\u003e \u003c\u003c\"keep-alive\"\u003e\u003e,\n            content_length =\u003e \u003c\u003c\"5090\"\u003e\u003e,\n            content_type =\u003e \u003c\u003c\"text/html\"\u003e\u003e,\n            date =\u003e \u003c\u003c\"Sat, 21 May 2022 14:49:49 GMT\"\u003e\u003e,\n            etag =\u003e \u003c\u003c\"\\\"56fbba85-13e2\\\"\"\u003e\u003e,\n            last_modified =\u003e \u003c\u003c\"Wed, 30 Mar 2016 11:37:41 GMT\"\u003e\u003e,\n            server =\u003e \u003c\u003c\"nginx/1.13.0\"\u003e\u003e},\n      status =\u003e 200}}\n3\u003e {ok, Conn} = httpb:request(Conn, get, \"http://snert.com/snert.html\", #{}, \u003c\u003c\u003e\u003e).\n{ok,#{host =\u003e \u003c\u003c\"snert.com\"\u003e\u003e,method =\u003e get,port =\u003e 80,\n      scheme =\u003e http,socket =\u003e #Port\u003c0.7\u003e}}\n4\u003e {ok, Snert} = httpb:response(Conn).\n{ok,#{body =\u003e\n          \u003c\u003c\"\u003c!DOCTYPE html PUBLIC \\\"-//W3C//DTD XHTML 1.0 Strict//EN\\\"\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n\u003cmeta http-equiv=\\\"Content-Type\\\" \"...\u003e\u003e,\n      headers =\u003e\n          #{accept_ranges =\u003e \u003c\u003c\"bytes\"\u003e\u003e,connection =\u003e \u003c\u003c\"keep-alive\"\u003e\u003e,\n            content_length =\u003e \u003c\u003c\"4436\"\u003e\u003e,\n            content_type =\u003e \u003c\u003c\"text/html\"\u003e\u003e,\n            date =\u003e \u003c\u003c\"Sat, 21 May 2022 14:49:49 GMT\"\u003e\u003e,\n            etag =\u003e \u003c\u003c\"\\\"5324973c-1154\\\"\"\u003e\u003e,\n            last_modified =\u003e \u003c\u003c\"Sat, 15 Mar 2014 18:09:00 GMT\"\u003e\u003e,\n            server =\u003e \u003c\u003c\"nginx/1.13.0\"\u003e\u003e},\n      status =\u003e 200}}\n5\u003e httpb:close(Conn).\nok\n```\n\n* Those multiple requests can be pipelined, though the responses must be read in the same order:\n\n```erlang\n1\u003e {ok, Conn} = httpb:request(get, \"http://snert.com/about.html\", #{}, \u003c\u003c\u003e\u003e).\n{ok,#{host =\u003e \u003c\u003c\"snert.com\"\u003e\u003e,method =\u003e get,port =\u003e 80,\n      scheme =\u003e http,socket =\u003e #Port\u003c0.7\u003e}}\n2\u003e {ok, Conn} = httpb:request(Conn, get, \"http://snert.com/snert.html\", #{}, \u003c\u003c\u003e\u003e).\n{ok,#{host =\u003e \u003c\u003c\"snert.com\"\u003e\u003e,method =\u003e get,port =\u003e 80,\n      scheme =\u003e http,socket =\u003e #Port\u003c0.7\u003e}}\n3\u003e {ok, About} = httpb:response(Conn).\n{ok,#{body =\u003e\n          \u003c\u003c\"\u003c!DOCTYPE html PUBLIC \\\"-//W3C//DTD XHTML 1.0 Strict//EN\\\"\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n\u003cmeta http-equiv=\\\"Content-Type\\\" \"...\u003e\u003e,\n      headers =\u003e\n          #{accept_ranges =\u003e \u003c\u003c\"bytes\"\u003e\u003e,connection =\u003e \u003c\u003c\"keep-alive\"\u003e\u003e,\n            content_length =\u003e \u003c\u003c\"5090\"\u003e\u003e,\n            content_type =\u003e \u003c\u003c\"text/html\"\u003e\u003e,\n            date =\u003e \u003c\u003c\"Wed, 01 Jun 2022 20:41:21 GMT\"\u003e\u003e,\n            etag =\u003e \u003c\u003c\"\\\"56fbba85-13e2\\\"\"\u003e\u003e,\n            last_modified =\u003e \u003c\u003c\"Wed, 30 Mar 2016 11:37:41 GMT\"\u003e\u003e,\n            server =\u003e \u003c\u003c\"nginx/1.13.0\"\u003e\u003e},\n      status =\u003e 200}}\n4\u003e {ok, Snert} = httpb:response(Conn).\n{ok,#{body =\u003e\n          \u003c\u003c\"\u003c!DOCTYPE html PUBLIC \\\"-//W3C//DTD XHTML 1.0 Strict//EN\\\"\u003e\\n\u003chtml\u003e\\n\u003chead\u003e\\n\u003cmeta http-equiv=\\\"Content-Type\\\" \"...\u003e\u003e,\n      headers =\u003e\n          #{accept_ranges =\u003e \u003c\u003c\"bytes\"\u003e\u003e,connection =\u003e \u003c\u003c\"keep-alive\"\u003e\u003e,\n            content_length =\u003e \u003c\u003c\"4436\"\u003e\u003e,\n            content_type =\u003e \u003c\u003c\"text/html\"\u003e\u003e,\n            date =\u003e \u003c\u003c\"Wed, 01 Jun 2022 20:41:22 GMT\"\u003e\u003e,\n            etag =\u003e \u003c\u003c\"\\\"5324973c-1154\\\"\"\u003e\u003e,\n            last_modified =\u003e \u003c\u003c\"Sat, 15 Mar 2014 18:09:00 GMT\"\u003e\u003e,\n            server =\u003e \u003c\u003c\"nginx/1.13.0\"\u003e\u003e},\n      status =\u003e 200}}\n5\u003e httpb:close(Conn).\nok\n```\n\n\nCopyright\n---------\n\nCopyright 2021, 2022 by Anthony Howe.  All rights reserved.\n\n\nMIT License\n-----------\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirwumpus%2Ferlang-httpb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsirwumpus%2Ferlang-httpb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirwumpus%2Ferlang-httpb/lists"}