@@ -33,23 +33,24 @@ def set(v)
3333 end
3434 end
3535
36- class ApacheJPReqHeaderName < BinData ::Primitive
37- COMMON_HEADERS = %w{ accept accept-charset accept-encoding accept-language authorization connection content-type content-length cookie cookie2 host pragma referer user-agent }
36+ class ApacheJPHeaderName < BinData ::Primitive
37+ COMMON_HEADERS = [ ]
38+
3839 endian :big
3940
4041 uint16 :len_or_code
4142 stringz :data , onlyif : -> { len_or_code < 0xa000 }
4243
4344 def get
4445 if len_or_code >= 0xa000
45- COMMON_HEADERS [ ( len_or_code . to_i & 0xff ) - 1 ]
46+ self . class :: COMMON_HEADERS [ ( len_or_code . to_i & 0xff ) - 1 ]
4647 else
4748 self . data
4849 end
4950 end
5051
5152 def set ( v )
52- if ( idx = COMMON_HEADERS . index ( v ) )
53+ if ( idx = self . class :: COMMON_HEADERS . index ( v ) )
5354 self . len_or_code = 0xa000 | ( idx + 1 )
5455 else
5556 raise RuntimeError if v . length >= 0xa000
@@ -60,13 +61,28 @@ def set(v)
6061 end
6162 end
6263
64+ class ApacheJPReqHeaderName < ApacheJPHeaderName
65+ COMMON_HEADERS = %w{ accept accept-charset accept-encoding accept-language authorization connection content-type content-length cookie cookie2 host pragma referer user-agent }
66+ end
67+
68+ class ApacheJPResHeaderName < ApacheJPHeaderName
69+ COMMON_HEADERS = %w{ Content-Type Content-Language Content-Length Date Last-Modified Location Set-Cookie Set-Cookie2 Servlet-Engine Status WWW-Authentication }
70+ end
71+
6372 class ApacheJPRequestHeader < BinData ::Record
6473 endian :big
6574
6675 apache_jp_req_header_name :header_name
6776 apache_jp_string :header_value
6877 end
6978
79+ class ApacheJPResponseHeader < BinData ::Record
80+ endian :big
81+
82+ apache_jp_res_header_name :header_name
83+ apache_jp_string :header_value
84+ end
85+
7086 class ApacheJPRequestAttribute < BinData ::Record
7187 CODE_CONTEXT = 1
7288 CODE_SERVLET_PATH = 2
@@ -83,6 +99,7 @@ class ApacheJPRequestAttribute < BinData::Record
8399 endian :big
84100
85101 uint8 :code
102+ apache_jp_string :attribute_name , onlyif : -> { code == CODE_REQ_ATTRIBUTE }
86103 apache_jp_string :attribute_value , onlyif : -> { code != CODE_TERMINATOR }
87104 end
88105
@@ -108,10 +125,11 @@ class ApacheJPForwardRequest < BinData::Record
108125 HTTP_METHOD_CHECKOUT = 19
109126 HTTP_METHOD_UNCHECKOUT = 20
110127 HTTP_METHOD_SEARCH = 21
128+ PREFIX_CODE = 2
111129
112130 endian :big
113131
114- uint8 :prefix_code , value : 2
132+ uint8 :prefix_code , value : PREFIX_CODE
115133 uint8 :http_method
116134 apache_jp_string :protocol , initial_value : 'HTTP/1.1'
117135 apache_jp_string :req_uri
@@ -124,4 +142,44 @@ class ApacheJPForwardRequest < BinData::Record
124142 array :headers , type : :apache_jp_request_header , initial_length : :num_headers
125143 array :attributes , type : :apache_jp_request_attribute , read_until : -> { element . code == ApacheJPRequestAttribute ::TERMINATOR }
126144 end
145+
146+ class ApacheJPSendBodyChunk < BinData ::Record
147+ PREFIX_CODE = 3
148+
149+ endian :big
150+
151+ uint8 :prefix_code , value : PREFIX_CODE
152+ uint16 :body_chunk_length , initial_value : -> { body_chunk . length }
153+ string :body_chunk , read_length : :body_chunk_length
154+ end
155+
156+ class ApacheJPSendHeaders < BinData ::Record
157+ PREFIX_CODE = 4
158+
159+ endian :big
160+
161+ uint8 :prefix_code , value : PREFIX_CODE
162+ uint16 :http_status_code
163+ apache_jp_string :http_status_msg
164+ uint16 :num_headers , initial_value : -> { header . length }
165+ array :headers , type : :apache_jp_response_header , initial_length : :num_headers
166+ end
167+
168+ class ApacheJPEndResponse < BinData ::Record
169+ PREFIX_CODE = 5
170+
171+ endian :big
172+
173+ uint8 :prefix_code , value : PREFIX_CODE
174+ apache_jp_boolean :reuse
175+ end
176+
177+ class ApacheJPGetBodyChunk < BinData ::Record
178+ PREFIX_CODE = 6
179+
180+ endian :big
181+
182+ uint8 :prefix_code , value : PREFIX_CODE
183+ uint16 :requested_length
184+ end
127185end
0 commit comments