-
Notifications
You must be signed in to change notification settings - Fork 20
Use 'Content-Type' to access content type header #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,7 +85,7 @@ class Client | |
| # if you want to use something other than the default `TCPSocket`; it must implement | ||
| # `open(uri, timeout)` to return a connected `Socket` | ||
| # @yieldparam [Client] client the new client instance, before opening the connection | ||
| # | ||
| # | ||
| def initialize(uri, | ||
| headers: {}, | ||
| connect_timeout: DEFAULT_CONNECT_TIMEOUT, | ||
|
|
@@ -107,7 +107,7 @@ def initialize(uri, | |
| if socket_factory | ||
| http_client_options["socket_class"] = socket_factory | ||
| end | ||
|
|
||
| if proxy | ||
| @proxy = proxy | ||
| else | ||
|
|
@@ -202,12 +202,12 @@ def closed? | |
| end | ||
|
|
||
| private | ||
|
|
||
| def reset_http | ||
| @http_client.close if !@http_client.nil? | ||
| close_connection | ||
| end | ||
|
|
||
| def close_connection | ||
| @lock.synchronize do | ||
| @cxn.connection.close if [email protected]? | ||
|
|
@@ -258,7 +258,7 @@ def connect | |
| interval = @first_attempt ? 0 : @backoff.next_interval | ||
| @first_attempt = false | ||
| if interval > 0 | ||
| @logger.info { "Will retry connection after #{'%.3f' % interval} seconds" } | ||
| @logger.info { "Will retry connection after #{'%.3f' % interval} seconds" } | ||
| sleep(interval) | ||
| end | ||
| cxn = nil | ||
|
|
@@ -268,14 +268,14 @@ def connect | |
| headers: build_headers | ||
| }) | ||
| if cxn.status.code == 200 | ||
| content_type = cxn.headers["content-type"] | ||
| content_type = cxn.content_type.mime_type | ||
| if content_type && content_type.start_with?("text/event-stream") | ||
| return cxn # we're good to proceed | ||
| else | ||
| reset_http | ||
| err = Errors::HTTPContentTypeError.new(cxn.headers["content-type"]) | ||
| err = Errors::HTTPContentTypeError.new(content_type) | ||
| @on[:error].call(err) | ||
| @logger.warn { "Event source returned unexpected content type '#{cxn.headers["content-type"]}'" } | ||
| @logger.warn { "Event source returned unexpected content type '#{content_type}'" } | ||
| end | ||
| else | ||
| body = cxn.to_s # grab the whole response body in case it has error details | ||
|
|
@@ -309,7 +309,7 @@ def read_stream(cxn) | |
| # readpartial gives us a string, which may not be a valid UTF-8 string because a | ||
| # multi-byte character might not yet have been fully read, but BufferedLineReader | ||
| # will handle that. | ||
| rescue HTTP::TimeoutError | ||
| rescue HTTP::TimeoutError | ||
| # For historical reasons, we rethrow this as our own type | ||
| raise Errors::ReadTimeoutError.new(@read_timeout) | ||
| end | ||
|
|
@@ -344,7 +344,7 @@ def log_and_dispatch_error(e, message) | |
| @logger.warn { "#{message}: #{e.inspect}"} | ||
| @logger.debug { "Exception trace: #{e.backtrace}" } | ||
| begin | ||
| @on[:error].call(e) | ||
| @on[:error].call(e) | ||
| rescue StandardError => ee | ||
| @logger.warn { "Error handler threw an exception: #{ee.inspect}"} | ||
| @logger.debug { "Exception trace: #{ee.backtrace}" } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cxn.content_typereturns a struct,mime_typegets us the appropriate string which matches the header.