http-protocol 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/http/protocol/headers.rb +1 -0
- data/lib/http/protocol/http1/connection.rb +45 -14
- data/lib/http/protocol/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 192ee24ff847367b1c8f59d6108c6e32a725eddf64284a62e087034a9d4c1a43
         | 
| 4 | 
            +
              data.tar.gz: bed20c2c1217b0279b9bec642df410a0a7e8ecab0cdbb2975a94a9f6e0dd33f3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a8d2032762049eeb8fc18ed69bcdcc7b7c7de1ff4108df5a0473b4ee2033e67138f981b866c66f9912a921684073cbec65a3075ce97f95ef7417b8b75927afc9
         | 
| 7 | 
            +
              data.tar.gz: 39cbcf536e6eb442533586457e87c4295c8d106a6e8fac09cf1b45e2e25bbae5c4fc17a6368ecd1a634cd735f2e2dd264d37c9923f799f014ab35c800c779fd2
         | 
| @@ -32,6 +32,7 @@ module HTTP | |
| 32 32 | 
             
            					@stream = stream
         | 
| 33 33 |  | 
| 34 34 | 
             
            					@persistent = persistent
         | 
| 35 | 
            +
            					@upgrade = nil
         | 
| 35 36 |  | 
| 36 37 | 
             
            					@count = 0
         | 
| 37 38 | 
             
            				end
         | 
| @@ -41,9 +42,18 @@ module HTTP | |
| 41 42 | 
             
            				# Whether the connection is persistent.
         | 
| 42 43 | 
             
            				attr :persistent
         | 
| 43 44 |  | 
| 45 | 
            +
            				# Whether the connection has been upgraded, and to what.
         | 
| 46 | 
            +
            				attr :upgrade
         | 
| 47 | 
            +
            				
         | 
| 44 48 | 
             
            				# The number of requests processed.
         | 
| 45 49 | 
             
            				attr :count
         | 
| 46 50 |  | 
| 51 | 
            +
            				def upgrade?(headers)
         | 
| 52 | 
            +
            					if upgrade = headers[UPGRADE]
         | 
| 53 | 
            +
            						return upgrade.first
         | 
| 54 | 
            +
            					end
         | 
| 55 | 
            +
            				end
         | 
| 56 | 
            +
            				
         | 
| 47 57 | 
             
            				def persistent?(version, headers)
         | 
| 48 58 | 
             
            					if version == HTTP10
         | 
| 49 59 | 
             
            						if connection = headers[CONNECTION]
         | 
| @@ -60,18 +70,29 @@ module HTTP | |
| 60 70 | 
             
            					end
         | 
| 61 71 | 
             
            				end
         | 
| 62 72 |  | 
| 73 | 
            +
            				def upgrade!(protocol)
         | 
| 74 | 
            +
            					@upgrade = protocol
         | 
| 75 | 
            +
            					@persistent = false
         | 
| 76 | 
            +
            					
         | 
| 77 | 
            +
            					return @stream
         | 
| 78 | 
            +
            				end
         | 
| 79 | 
            +
            				
         | 
| 63 80 | 
             
            				# Write the appropriate header for connection persistence.
         | 
| 64 | 
            -
            				def  | 
| 65 | 
            -
            					if  | 
| 66 | 
            -
            						@stream.write("connection:  | 
| 81 | 
            +
            				def write_connection_header(version)
         | 
| 82 | 
            +
            					if @upgrade
         | 
| 83 | 
            +
            						@stream.write("connection: upgrade\r\nupgrade: #{@upgrade}\r\n")
         | 
| 67 84 | 
             
            					else
         | 
| 68 | 
            -
            						 | 
| 85 | 
            +
            						if version == HTTP10
         | 
| 86 | 
            +
            							@stream.write("connection: keep-alive\r\n") if @persistent
         | 
| 87 | 
            +
            						else
         | 
| 88 | 
            +
            							@stream.write("connection: close\r\n") unless @persistent
         | 
| 89 | 
            +
            						end
         | 
| 69 90 | 
             
            					end
         | 
| 70 91 | 
             
            				end
         | 
| 71 92 |  | 
| 72 93 | 
             
            				# Effectively close the connection and return the underlying IO.
         | 
| 73 94 | 
             
            				# @return [IO] the underlying non-blocking IO.
         | 
| 74 | 
            -
            				def hijack
         | 
| 95 | 
            +
            				def hijack!
         | 
| 75 96 | 
             
            					@persistent = false
         | 
| 76 97 |  | 
| 77 98 | 
             
            					@stream.flush
         | 
| @@ -89,14 +110,14 @@ module HTTP | |
| 89 110 | 
             
            					@stream.write("host: #{authority}\r\n")
         | 
| 90 111 |  | 
| 91 112 | 
             
            					write_headers(headers)
         | 
| 92 | 
            -
            					 | 
| 113 | 
            +
            					write_connection_header(version)
         | 
| 93 114 | 
             
            				end
         | 
| 94 115 |  | 
| 95 116 | 
             
            				def write_response(version, status, headers, body = nil, head = false)
         | 
| 96 117 | 
             
            					@stream.write("#{version} #{status}\r\n")
         | 
| 97 118 |  | 
| 98 119 | 
             
            					write_headers(headers)
         | 
| 99 | 
            -
            					 | 
| 120 | 
            +
            					write_connection_header(version)
         | 
| 100 121 | 
             
            					write_body(body, version == HTTP11, head)
         | 
| 101 122 | 
             
            				end
         | 
| 102 123 |  | 
| @@ -113,13 +134,7 @@ module HTTP | |
| 113 134 | 
             
            				end
         | 
| 114 135 |  | 
| 115 136 | 
             
            				def read_line
         | 
| 116 | 
            -
            					 | 
| 117 | 
            -
            					# @stream.gets(CRLF, chomp: true) or raise EOFError
         | 
| 118 | 
            -
            					if line = @stream.gets(CRLF)
         | 
| 119 | 
            -
            						return line.chomp!(CRLF)
         | 
| 120 | 
            -
            					else
         | 
| 121 | 
            -
            						raise EOFError
         | 
| 122 | 
            -
            					end
         | 
| 137 | 
            +
            					@stream.gets(CRLF, chomp: true) or raise EOFError
         | 
| 123 138 | 
             
            				end
         | 
| 124 139 |  | 
| 125 140 | 
             
            				def read_request
         | 
| @@ -127,6 +142,7 @@ module HTTP | |
| 127 142 | 
             
            					headers = read_headers
         | 
| 128 143 |  | 
| 129 144 | 
             
            					@persistent = persistent?(version, headers)
         | 
| 145 | 
            +
            					@upgrade = upgrade?(headers)
         | 
| 130 146 |  | 
| 131 147 | 
             
            					body = read_request_body(headers)
         | 
| 132 148 |  | 
| @@ -183,6 +199,19 @@ module HTTP | |
| 183 199 | 
             
            					return chunk
         | 
| 184 200 | 
             
            				end
         | 
| 185 201 |  | 
| 202 | 
            +
            				def write_upgrade_body
         | 
| 203 | 
            +
            					@stream.write("\r\n")
         | 
| 204 | 
            +
            					@stream.flush
         | 
| 205 | 
            +
            					
         | 
| 206 | 
            +
            					return @stream unless block_given?
         | 
| 207 | 
            +
            					
         | 
| 208 | 
            +
            					begin
         | 
| 209 | 
            +
            						yield @stream
         | 
| 210 | 
            +
            					rescue
         | 
| 211 | 
            +
            						@stream.close_write
         | 
| 212 | 
            +
            					end
         | 
| 213 | 
            +
            				end
         | 
| 214 | 
            +
            				
         | 
| 186 215 | 
             
            				def write_empty_body(body)
         | 
| 187 216 | 
             
            					@stream.write("content-length: 0\r\n\r\n")
         | 
| 188 217 | 
             
            					@stream.flush
         | 
| @@ -264,6 +293,8 @@ module HTTP | |
| 264 293 | 
             
            				def write_body(body, chunked = true, head = false)
         | 
| 265 294 | 
             
            					if body.nil? or body.empty?
         | 
| 266 295 | 
             
            						write_empty_body(body)
         | 
| 296 | 
            +
            					# elsif body.respond_to?(:call)
         | 
| 297 | 
            +
            					# 	write_upgrade_body(&body)
         | 
| 267 298 | 
             
            					elsif length = body.length
         | 
| 268 299 | 
             
            						write_fixed_length_body(body, length, head)
         | 
| 269 300 | 
             
            					elsif @persistent and chunked
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: http-protocol
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.17.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Samuel Williams
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019- | 
| 11 | 
            +
            date: 2019-05-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: http-hpack
         | 
| @@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 143 143 | 
             
                - !ruby/object:Gem::Version
         | 
| 144 144 | 
             
                  version: '0'
         | 
| 145 145 | 
             
            requirements: []
         | 
| 146 | 
            -
            rubygems_version: 3.0. | 
| 146 | 
            +
            rubygems_version: 3.0.2
         | 
| 147 147 | 
             
            signing_key: 
         | 
| 148 148 | 
             
            specification_version: 4
         | 
| 149 149 | 
             
            summary: Provides abstractions to handle HTTP1 and HTTP2 protocols.
         |