Changeset 598
- Timestamp:
- 12/03/07 15:48:44 (1 year ago)
- Files:
-
- version_0/lib/protocols/httpcli2.rb (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
version_0/lib/protocols/httpcli2.rb
r597 r598 64 64 end 65 65 66 67 #-- 68 # 69 def receive_line ln 70 if @chunk_trailer 71 receive_chunk_trailer(ln) 72 elsif @chunking 73 receive_chunk_header(ln) 74 else 75 receive_header_line(ln) 76 end 77 end 78 79 #-- 80 # 81 def receive_chunk_trailer ln 82 if ln.length == 0 83 @conn.pop_request 84 succeed 85 else 86 p "Received chunk trailer line" 87 end 88 end 89 66 90 #-- 67 91 # Allow up to ten blank lines before we get a real response line. 68 92 # Allow no more than 100 lines in the header. 69 93 # 70 def receive_ line ln94 def receive_header_line ln 71 95 if ln.length == 0 72 96 if @header_lines.length > 0 … … 87 111 end 88 112 89 90 113 #-- 114 # Cf RFC 2616 pgh 3.6.1 for the format of HTTP chunks. 115 # 116 def receive_chunk_header ln 117 if ln.length > 0 118 chunksize = ln.to_i(16) 119 if chunksize > 0 120 @conn.set_text_mode(ln.to_i(16)) 121 else 122 @content = @content.join 123 @chunk_trailer = true 124 end 125 else 126 # We correctly come here after each chunk gets read. 127 p "Got A BLANK chunk line" 128 end 129 130 end 131 132 133 #-- 134 # We get a single chunk. Append it to the incoming content and switch back to line mode. 135 # 136 def receive_chunked_text text 137 p "RECEIVED #{text.length} CHUNK" 138 (@content ||= []) << text 139 end 140 141 142 #-- 143 # TODO, inefficient how we're handling this. Part of it is done so as to 144 # make sure we don't have problems in detecting chunked-encoding, content-length, 145 # etc. 91 146 # 92 147 # 93 148 HttpResponseRE = /\AHTTP\/(1.[01]) ([\d]{3})/i 94 149 ClenRE = /\AContent-length:\s*(\d+)/i 150 ChunkedRE = /\ATransfer-encoding:\s*chunked/i 95 151 ColonRE = /\:\s*/ 96 152 … … 104 160 105 161 clen = nil 162 chunks = nil 106 163 @header_lines.each_with_index do |e,ix| 107 164 if ix > 0 … … 109 166 (@headers[hdr.downcase] ||= []) << val 110 167 end 168 111 169 if clen == nil and e =~ ClenRE 112 170 clen = $1.dup.to_i 113 171 end 172 if e =~ ChunkedRE 173 chunks = true 174 end 114 175 end 115 176 116 177 if clen 117 178 @conn.set_text_mode clen 179 elsif chunks 180 @chunking = true 118 181 else 119 182 # Chunked transfer, multipart, or end-of-connection. … … 121 184 # method and suppress its desire to fail us. 122 185 p "NO CLEN" 186 p @args[:uri] 187 p @header_lines 123 188 @internal_error = :unsupported_clen 124 189 @conn.close_connection … … 126 191 end 127 192 private :process_header 193 194 195 def receive_text text 196 @chunking ? receive_chunked_text(text) : receive_sized_text(text) 197 end 128 198 129 199 #-- … … 131 201 # specified by the content-length header. 132 202 # 133 def receive_ text text203 def receive_sized_text text 134 204 @content = text 135 205 @conn.pop_request … … 233 303 234 304 def receive_line ln 235 @requests.last.receive_line ln 305 if req = @requests.last 306 req.receive_line ln 307 else 308 p "??????????" 309 p ln 310 end 311 236 312 end 237 313 def receive_binary_data text