{"id":18779400,"url":"https://github.com/zostay/raku-http-headers","last_synced_at":"2025-07-31T12:06:18.209Z","repository":{"id":32750535,"uuid":"36341436","full_name":"zostay/raku-HTTP-Headers","owner":"zostay","description":"Tools for working with HTTP message headers","archived":false,"fork":false,"pushed_at":"2020-02-08T16:33:57.000Z","size":88,"stargazers_count":2,"open_issues_count":3,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-01T20:57:19.403Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zostay.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-27T03:54:10.000Z","updated_at":"2021-05-14T15:57:48.000Z","dependencies_parsed_at":"2022-09-23T16:02:31.175Z","dependency_job_id":null,"html_url":"https://github.com/zostay/raku-HTTP-Headers","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/zostay/raku-HTTP-Headers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-HTTP-Headers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-HTTP-Headers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-HTTP-Headers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-HTTP-Headers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zostay","download_url":"https://codeload.github.com/zostay/raku-HTTP-Headers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zostay%2Fraku-HTTP-Headers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268035798,"owners_count":24185099,"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":"2025-07-31T02:00:08.723Z","response_time":66,"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":[],"created_at":"2024-11-07T20:19:56.468Z","updated_at":"2025-07-31T12:06:17.689Z","avatar_url":"https://github.com/zostay.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"TITLE\n=====\n\nHTTP::Headers\n\nSUBTITLE\n========\n\nTools for working with HTTP message headers\n\nSYNOPSIS\n========\n\n    use HTTP::Headers :standard-names;\n    my $headers = HTTP::Headers.new;\n    $headers.Content-Type = 'text/html';\n    $headers.Content-Type.charset = \"UTF-8\";\n    $headers.Content-Length = $content.encode.bytes;\n\n    my $CRLF = \"\\x0d\\x0a\";\n    print \"200 OK$CRLF;\n    print $headers.as-string(:eol($CRLF));\n    print $CRLF;\n    print $content;\n\nDESCRIPTION\n===========\n\nThis module provides convenient tools for working with HTTP headers. An emphasis has been placed on making it easy to use in a way that helps catch errors early. It has also been built for extensibility.\n\nMethods\n=======\n\nmethod new\n----------\n\n    method new(HTTP::Headers:U: @headers, Bool:D :$quiet = False --\u003e HTTP::Headers:D)\n    method new(HTTP::Headers:U: %headers, Bool:D :$quiet = False --\u003e HTTP::Headers:D)\n    method new(HTTP::Headers:U: Bool:D :$quiet = False, *@headers, *%headers --\u003e HTTP::Headers:D)\n\nConstructs a new object for working with headers. The `:$quiet` option can be used to suppress all warnings normally generated by this object.\n\nThe various `%headers` and `@headers` methods can be used to initialize the object from a list of pairs:\n\n    my $headers = HTTP::Headers.new:\n        ::(Content-Type)   =\u003e 'text/html',\n        ::(Content-Length) =\u003e 42,\n        'X-Requested-With' =\u003e 'XMLHTTPRequest',\n        ;\n\nmethod headers\n--------------\n\n    multi method headers(HTTP::Headers:D: Pair:D @headers)\n    multi method headers(HTTP::Headers:D: %headers)\n    multi method headers(HTTP::Headers:D: *@headers, *%headers)\n\nSets all the headers given as pairs or named parameters.\n\nmethod header\n-------------\n\n    multi method header(HTTP::Headers:D: HTTP::Header::Standard::Name $name --\u003e HTTP::Header) is rw\n    multi method header(HTTP::Headers:D: Str $name --\u003e HTTP::Header) is rw\n\nThis method is writable and allows the use of either the values in the `HTTP::Header::Standard::Name` enumeration or string values. In general, you should not use strings when you can use the enumeration in your code. By using the enumeration, you can discover typos at compile time.\n\n    use HTTP::Headers :standard-names;\n    $headers.header(Content-MIME-Type); # I forgot it's just Content-Type\n    # Undeclared name:\n    #     Content-MIME-Type used at line 1\n\nThe library will remind you of this best practice if you use a string when you could use an enumeration:\n\n    $headers.header(\"Content-Type\");\n    # Calling .header(Content-Type) is preferred to .header(\"Content-Type\") for standard HTTP headers.\n\nIf you don't want to see these, you can ask the object or the method to be quiet:\n\n    $headers.header(\"Content-Type\", :quiet);\n    # OR during construction\n    my $headers = HTTP::Headers.new(:$quiet);\n\nWhen setting values on a header, you may set either a single or multiples.\n\n    $headers.header(Content-Length) = 42;\n    $headers.header(Accept) = \"text/html\", \"text/*\", \"*/*\";\n    say $headers.as-string;\n    # Accept: text/html\n    # Accept: text/*\n    # Accept: */*\n    # Content-Length: 42\n\nBy setting with a comma, you will generate multiple headers.\n\nYou may also set headers with [DateTime](DateTime), [Instant](Instant), and [Duration](Duration) objects and it should do the right thing. For example,\n\n    $headers.header(Date)        = DateTime.now;\n    $headers.header(Retry-After) = Duration.new(120);\n    say $headers.as-string;\n    # Date: Thu, 14 May 2015 09:48:00 GMT\n    # Retry-After: 120\n\nWhen you read a header, the value returns is a [HTTP::Header](HTTP::Header) object.\n\n    my HTTP::Header $ct = $headers.header(Content-Type);\n    my HTTP::Header $xf = $headers.header(\"X-Foo-Custom\");\n\nThis object stringifies to the value of the header (with multiple values being joined together using a comma, safe according to RFC). It also provides a bunch of additional tools for working with and manipulating the header. For example:\n\n    $headers.header(Accept).push: \"text/css\", \"text/js\";\n    $headers.header(Content-Type).charset = \"UTF-8\";\n\nSee [HTTP::Header](HTTP::Header) for details.\n\nmethod remove-header\n--------------------\n\n    multi method remove-header(HTTP::Header:D: $name --\u003e HTTP::Header)\n    multi method remove-header(HTTP::Header:D: *@names --\u003e List)\n\nThese method will remove headers from the list. The removed [HTTP::Header](HTTP::Header) object is returned.\n\nmethod remove-content-headers\n-----------------------------\n\n    method remove-content-headers(HTTP::Headers:D: --\u003e List)\n\nThis method removes all the entity headers:\n\n    Allow Content-Encoding Content-Language Content-Length\n    Content-Location Content-MD5 Content-Range Content-Type\n    Expires Last-Modified\n\nas well as any that start with \"Content-\".\n\nmethod clear\n------------\n\n    method clear(HTTP::Headers:D:)\n\nThis removes all headers.\n\nmethod clone\n------------\n\n    method clone(HTTP::Headers:D: --\u003e HTTP::Headers:D)\n\nThis performs a deep clone of the object.\n\nmethod sorted-headers\n---------------------\n\n    method sorted-headers(HTTP::Headers:D: --\u003e Seq)\n\nReturns all [HTTP::Header](HTTP::Header) objcts in a sequence sorted by header name.\n\nmethod list\n-----------\n\n    method list(HTTP::Headers:D: --\u003e List)\n\nThis returns all the headers stored in this object, sorted according to the RFC recommendation (general headers first, then request/response headers, then entity/content headers, and finally custom headers).\n\nmethod map\n----------\n\n    method map(HTTP::Headers:D: \u0026code --\u003e Seq)\n\nProvides a way to iterate over all the headers in the object.\n\nmethod as-string\n----------------\n\n    method as-string(HTTP::Headers:D: Str:D :$eol = \"\\n\" --\u003e Str)\n\nReturns the headers for output using the given line separator. If no line separator is given, \"\\n\" is used.\n\nmethod Str\n----------\n\n    multi method Str(:$eol = \"\\n\") returns Str\n\nThis calls [/method as-string](/method as-string) with the given arguments.\n\nmethod for-WAPI\n---------------\n\n    method for-WAPI(HTTP::Headers:D: --\u003e List:D)\n\nThis returns the headers formatted for output from a RakuWAPI application, as an array of Pairs.\n\nHash-like Operations\n====================\n\nYou can also treat [HTTP::Headers](HTTP::Headers) like a hash in some ways. These are **experimental** and might be removed or changed in the future.\n\nmethod postcircumfix:\u003c{ }\u003e\n--------------------------\n\n    multi method postcircumfix:\u003c{ }\u003e(HTTP::Headers:D: Str:D $key --\u003e HTTP::Header)\n    multi method postcircumfix:\u003c{ }\u003e(HTTP::Headers:D: HTTP::Header::Standard::Name:D $key --\u003e HTTP::Header)\n\nThis may be used to return or assign a head value.\n\nadverb :delete\n--------------\n\nThis may be used to delete headers.\n\nadverb :exists\n--------------\n\nThis may be used to check to see if a head is set.\n\nConvenience Methods\n===================\n\nThe following methods are provided as a shortcut for [/method header](/method header) and can be used as an accessor or mutator.\n\n    # General Headers\n    method Cache-Control is rw\n    method Connection is rw\n    method Date is rw\n    method Pragma is rw\n    method Trailer is rw\n    method Transfer-Encoding is rw\n    method Upgrade is rw\n    method Via is rw\n    method Warning is rw\n\n    # Request Headers\n    method Accept is rw\n    method Accept-Charset is rw\n    method Accept-Encoding is rw\n    method Accept-Language is rw\n    method Authorization is rw\n    method Expect is rw\n    method From is rw\n    method Host is rw\n    method If-Match is rw\n    method If-Modified-Since is rw\n    method If-None-Match is rw\n    method If-Range is rw\n    method If-Unmodified-Since is rw\n    method Max-Forwards is rw\n    method Proxy-Authorization is rw\n    method Range is rw\n    method Referer is rw\n    method TE is rw\n    method User-Agent is rw\n\n    # Response Headers\n    method Accept-Ranges is rw\n    method Age is rw\n    method ETag is rw\n    method Location is rw\n    method Proxy-Authenticate is rw\n    method Retry-After is rw\n    method Server is rw\n    method Vary is rw\n    method WWW-Authenticate is rw\n\n    # Entity Headers\n    method Allow is rw\n    method Content-Encoding is rw\n    method Content-Language is rw\n    method Content-Length is rw\n    method Content-Location is rw\n    method Content-MD5 is rw\n    method Content-Range is rw\n    method Content-Type is rw\n    method Expires is rw\n    method Last-Modified is rw\n\nExtending HTTP::Headers\n=======================\n\nIt is possible to create a sub-class of [HTTP::Headers](HTTP::Headers) more suited to your application. As a simplistic example, here's a customization that provides two new custom headers named \"X-Foo\" and \"X-Bar\" which have a default column setting of 42 when used.\n\n    class MyApp::CustomHeaders is HTTP::Headers {\n        enum MyAppHeader \u003c X-Foo X-Bar \u003e;\n\n        method build-header($name, *@values) {\n            if $name ~~ MyAppHeader {\n                HTTP::Header::Custom.new(:name($name.Str), :42values);\n            }\n            else {\n                nextsame;\n            }\n        }\n\n        multi method header(MyAppHeader $name) is rw {\n            self.header-proxy($name);\n        }\n\n        method X-Foo is rw { self.header(MyAppHeader::X-Foo) }\n        method X-Bar is rw { self.header(MyAppHeader::X-Bar) }\n    }\n\nHere is a description of the methods you'll need to consider in doing this.\n\nmethod build-header\n-------------------\n\n    multi method build-header(HTTP::Headers:D: Str:D $name, *@values --\u003e HTTP::Header:D)\n    multi method build-header(HTTP::Headers:D: HTTP::Header::Standard::Name:D $name, *@values --\u003e HTTP::Header:D)\n\nThis is a factory method used to decide how to build the headers being stored. Here is the place where you'll want to add custom roles to your headers, instantiate any custom implementations of [HTTP::Header](HTTP::Header), etc.\n\nIt is recommended that you define it to build what you need and then use `nextsame` to handle all the remaining cases.\n\nmethod header-proxy\n-------------------\n\n    multi method header-proxy(HTTP::Headers:D: Str:D $name --\u003e HTTP::Header) is rw\n    multi method header-proxy(HTTP::Headers:D: HTTP::Header::Standard::Name:D $name --\u003e HTTP::Header) is rw\n\nThis is a handy helper that allows you to easily build your own custom version of [/method header](/method header). It returns a [Proxy](Proxy) useful for building `is rw` methods similar to those in [HTTP::Headers](HTTP::Headers).\n\nCAVEATS\n=======\n\nThis module provides a mutator style that is not considered ideal, possibly even un-Perlish. It pretty much completely overuses [Proxy](Proxy) objects and such to make mutators that perform complex operations during seemingly straightforward assignment operations. This is probably not wise, but it seemed like a good idea at the time of first writing.\n\nFor a detailed write-up of why this is not preferable, see this blog post by Jonathan Worthington: [https://6guts.wordpress.com/2016/11/25/perl-6-is-biased-towards-mutators-being-really-simple-thats-a-good-thing/](Perl 6 is biased towards mutators being really simple. That’s a good thing.)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzostay%2Fraku-http-headers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzostay%2Fraku-http-headers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzostay%2Fraku-http-headers/lists"}