Changeset 4852

Show
Ignore:
Timestamp:
05/03/07 15:01:42 (1 year ago)
Author:
hdm
Message:

Improvements to the SSL socket support in Rex, fixes #102, and a HTTP client response parsing bug

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework3/tags/framework-3.0/lib/rex/proto/http/client.rb

    r4745 r4852  
    5454                        'uri_fake_end'           => false,   # bool 
    5555                        'uri_fake_params_start'  => false,   # bool 
    56                         'header_folding'         => false    # bool  
     56                        'header_folding'         => false,   # bool  
     57                        'chunked_size'           => 0        # integer 
    5758                } 
    5859                 
     
    8283                        'uri_fake_end'           => 'bool', 
    8384                        'uri_fake_params_start'  => 'bool', 
    84                         'header_folding'         => 'bool' 
     85                        'header_folding'         => 'bool', 
     86                        'chunked_size'           => 'integer' 
    8587                } 
    8688        end 
     
    169171                c_path = opts['path_info'] 
    170172                c_auth = opts['basic_auth'] || config['basic_auth'] || '' 
    171                                  
     173 
    172174                uri    = set_cgi(c_cgi) 
    173175                qstr   = c_qs 
     
    231233                req += set_connection_header(c_conn)             
    232234                req += set_extra_headers(c_head) 
    233                  
    234                 # TODO: 
    235                 # * Implement chunked transfer 
    236                  
     235                         
    237236                req += set_content_type_header(c_type) 
    238237                req += set_content_len_header(pstr.length) 
     238                req += set_chunked_header() 
    239239                req += set_raw_headers(c_rawh) 
    240240                req += set_body(pstr) 
     
    300300                ret = conn.put(req_string) 
    301301 
    302                 # Tell the remote side if we aren't pipelining 
    303                 conn.shutdown(::Socket::SHUT_WR) if (!pipelining?) 
    304                  
    305302                ret 
    306303        end 
     
    364361                                                        raise RuntimeError, resp.error, caller 
    365362                                                end 
     363                                                select(nil, nil, nil, 0.10) 
    366364                                        end 
    367365                                end 
     
    535533        # 
    536534        def set_body(data) 
    537                 "\r\n" + data 
     535                return "\r\n" + data if self.config['chunked_size'] == 0 
     536                str = data.dup 
     537                chunked = '' 
     538                while str.size > 0 
     539                        chunk = str.slice!(0,rand(self.config['chunked_size']) + 1) 
     540                        chunked += sprintf("%x", chunk.size) + "\r\n" + chunk + "\r\n" 
     541                end 
     542                "\r\n" + chunked + "0\r\n\r\n" 
    538543        end 
    539544         
     
    655660        # 
    656661        # Return the content length header 
    657         # TODO: 
    658         #  * Ignore this if chunked encoding is set 
    659662        def set_content_len_header(clen) 
     663                return "" if self.config['chunked_size'] > 0 
    660664                set_formatted_header("Content-Length", clen) 
    661665        end 
     
    689693                buf 
    690694        end 
    691          
     695 
     696        def set_chunked_header() 
     697                return "" if self.config['chunked_size'] == 0 
     698                set_formatted_header('Transfer-Encoding', 'chunked') 
     699        end 
     700 
    692701        # 
    693702        # Return a string of raw header data