@@ -15,17 +15,17 @@ This guide explains how to work with HTTP headers using `protocol-http`.
1515The {Protocol::HTTP::Headers} class provides a comprehensive interface for creating and manipulating HTTP headers:
1616
1717``` ruby
18- require ' protocol/http'
18+ require " protocol/http"
1919
2020headers = Protocol ::HTTP ::Headers .new
21- headers.add(' content-type' , ' text/html' )
22- headers.add(' set-cookie' , ' session=abc123' )
21+ headers.add(" content-type" , " text/html" )
22+ headers.add(" set-cookie" , " session=abc123" )
2323
2424# Access headers
25- content_type = headers[' content-type' ] # => "text/html"
25+ content_type = headers[" content-type" ] # => "text/html"
2626
2727# Check if header exists
28- headers.include?(' content-type' ) # => true
28+ headers.include?(" content-type" ) # => true
2929```
3030
3131### Header Policies
@@ -34,11 +34,11 @@ Different header types have different behaviors for merging, validation, and tra
3434
3535``` ruby
3636# Some headers can be specified multiple times
37- headers.add(' set-cookie' , ' first=value1' )
38- headers.add(' set-cookie' , ' second=value2' )
37+ headers.add(" set-cookie" , " first=value1" )
38+ headers.add(" set-cookie" , " second=value2" )
3939
4040# Others are singletons and will raise errors if duplicated
41- headers.add(' content-length' , ' 100' )
41+ headers.add(" content-length" , " 100" )
4242# headers.add('content-length', '200') # Would raise DuplicateHeaderError
4343```
4444
@@ -48,11 +48,11 @@ Some headers have specialized classes for parsing and formatting:
4848
4949``` ruby
5050# Accept header with media ranges
51- accept = Protocol ::HTTP ::Header ::Accept .new (' text/html,application/json;q=0.9' )
51+ accept = Protocol ::HTTP ::Header ::Accept .new (" text/html,application/json;q=0.9" )
5252media_ranges = accept.media_ranges
5353
5454# Authorization header
55- auth = Protocol ::HTTP ::Header ::Authorization .basic(' username' , ' password' )
55+ auth = Protocol ::HTTP ::Header ::Authorization .basic(" username" , " password" )
5656# => "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
5757```
5858
@@ -63,20 +63,20 @@ HTTP trailers are headers that appear after the message body. For security reaso
6363``` ruby
6464# Working with trailers
6565headers = Protocol ::HTTP ::Headers .new ([
66- [ ' content-type' , ' text/html' ],
67- [ ' content-length' , ' 1000' ]
66+ [ " content-type" , " text/html" ],
67+ [ " content-length" , " 1000" ]
6868])
6969
7070# Start trailer section
7171headers.trailer!
7272
7373# These will be allowed (safe metadata)
74- headers.add(' etag' , ' "12345"' )
75- headers.add(' date' , Time .now.httpdate)
74+ headers.add(" etag" , ' "12345"' )
75+ headers.add(" date" , Time .now.httpdate)
7676
7777# These will be silently ignored for security
78- headers.add(' authorization' , ' Bearer token' ) # Ignored - credential leakage risk
79- headers.add(' connection' , ' close' ) # Ignored - hop-by-hop header
78+ headers.add(" authorization" , " Bearer token" ) # Ignored - credential leakage risk
79+ headers.add(" connection" , " close" ) # Ignored - hop-by-hop header
8080```
8181
8282The trailer security system prevents HTTP request smuggling by restricting which headers can appear in trailers:
0 commit comments