repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/spec/lib/secure_headers/headers/x_frame_options_spec.rb | spec/lib/secure_headers/headers/x_frame_options_spec.rb | # frozen_string_literal: true
require "spec_helper"
module SecureHeaders
describe XFrameOptions do
describe "#value" do
specify { expect(XFrameOptions.make_header).to eq([XFrameOptions::HEADER_NAME, XFrameOptions::DEFAULT_VALUE]) }
specify { expect(XFrameOptions.make_header("DENY")).to eq([XFrameOpti... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/spec/lib/secure_headers/headers/strict_transport_security_spec.rb | spec/lib/secure_headers/headers/strict_transport_security_spec.rb | # frozen_string_literal: true
require "spec_helper"
module SecureHeaders
describe StrictTransportSecurity do
describe "#value" do
specify { expect(StrictTransportSecurity.make_header).to eq([StrictTransportSecurity::HEADER_NAME, StrictTransportSecurity::DEFAULT_VALUE]) }
specify { expect(StrictTransp... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/spec/lib/secure_headers/headers/cookie_spec.rb | spec/lib/secure_headers/headers/cookie_spec.rb | # frozen_string_literal: true
require "spec_helper"
module SecureHeaders
describe Cookie do
let(:raw_cookie) { "_session=thisisatest" }
it "does not tamper with cookies when using OPT_OUT is used" do
cookie = Cookie.new(raw_cookie, OPT_OUT)
expect(cookie.to_s).to eq(raw_cookie)
end
it "... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/spec/lib/secure_headers/headers/policy_management_spec.rb | spec/lib/secure_headers/headers/policy_management_spec.rb | # frozen_string_literal: true
require "spec_helper"
module SecureHeaders
describe PolicyManagement do
before(:each) do
reset_config
Configuration.default
end
let(:default_opts) do
{
default_src: %w(https:),
img_src: %w(https: data:),
script_src: %w('unsafe-inlin... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/spec/lib/secure_headers/headers/content_security_policy_spec.rb | spec/lib/secure_headers/headers/content_security_policy_spec.rb | # frozen_string_literal: true
require "spec_helper"
module SecureHeaders
describe ContentSecurityPolicy do
let(:default_opts) do
{
default_src: %w(https:),
img_src: %w(https: data:),
script_src: %w('unsafe-inline' 'unsafe-eval' https: data:),
style_src: %w('unsafe-inline' ht... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb | spec/lib/secure_headers/headers/expect_certificate_transparency_spec.rb | # frozen_string_literal: true
require "spec_helper"
module SecureHeaders
describe ExpectCertificateTransparency do
specify { expect(ExpectCertificateTransparency.new(max_age: 1234, enforce: true).value).to eq("enforce, max-age=1234") }
specify { expect(ExpectCertificateTransparency.new(max_age: 1234, enforce... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers.rb | lib/secure_headers.rb | # frozen_string_literal: true
require "secure_headers/hash_helper"
require "secure_headers/headers/cookie"
require "secure_headers/headers/content_security_policy"
require "secure_headers/headers/x_frame_options"
require "secure_headers/headers/strict_transport_security"
require "secure_headers/headers/x_xss_protection... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/view_helper.rb | lib/secure_headers/view_helper.rb | # frozen_string_literal: true
module SecureHeaders
module ViewHelpers
include SecureHeaders::HashHelper
SECURE_HEADERS_RAKE_TASK = "rake secure_headers:generate_hashes"
class UnexpectedHashedScriptException < StandardError; end
# Public: create a style tag using the content security policy nonce.
... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/version.rb | lib/secure_headers/version.rb | # frozen_string_literal: true
module SecureHeaders
VERSION = "7.1.0"
end
| ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/middleware.rb | lib/secure_headers/middleware.rb | # frozen_string_literal: true
module SecureHeaders
class Middleware
def initialize(app)
@app = app
end
# merges the hash of headers into the current header set.
def call(env)
req = Rack::Request.new(env)
status, headers, response = @app.call(env)
config = SecureHeaders.config... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/railtie.rb | lib/secure_headers/railtie.rb | # frozen_string_literal: true
# rails 3.1+
if defined?(Rails::Railtie)
module SecureHeaders
class Railtie < Rails::Railtie
isolate_namespace SecureHeaders if defined? isolate_namespace # rails 3.0
conflicting_headers = ["x-frame-options", "x-xss-protection",
"x-permitted-c... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/configuration.rb | lib/secure_headers/configuration.rb | # frozen_string_literal: true
require "yaml"
module SecureHeaders
class Configuration
DEFAULT_CONFIG = :default
NOOP_OVERRIDE = "secure_headers_noop_override"
class AlreadyConfiguredError < StandardError; end
class NotYetConfiguredError < StandardError; end
class IllegalPolicyModificationError < ... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/hash_helper.rb | lib/secure_headers/hash_helper.rb | # frozen_string_literal: true
require "base64"
module SecureHeaders
module HashHelper
def hash_source(inline_script, digest = :SHA256)
base64_hashed_content = Base64.encode64(Digest.const_get(digest).digest(inline_script)).chomp
"'#{digest.to_s.downcase}-#{base64_hashed_content}'"
end
end
end
| ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/utils/cookies_config.rb | lib/secure_headers/utils/cookies_config.rb | # frozen_string_literal: true
module SecureHeaders
class CookiesConfig
attr_reader :config
def initialize(config)
@config = config
end
def validate!
return if config.nil? || config == SecureHeaders::OPT_OUT
validate_config!
validate_secure_config! unless config[:secure].nil... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/content_security_policy.rb | lib/secure_headers/headers/content_security_policy.rb | # frozen_string_literal: true
require_relative "policy_management"
require_relative "content_security_policy_config"
module SecureHeaders
class ContentSecurityPolicy
include PolicyManagement
def initialize(config = nil)
@config =
if config.is_a?(Hash)
if config[:report_only]
... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/x_download_options.rb | lib/secure_headers/headers/x_download_options.rb | # frozen_string_literal: true
module SecureHeaders
class XDOConfigError < StandardError; end
class XDownloadOptions
HEADER_NAME = "x-download-options".freeze
DEFAULT_VALUE = "noopen"
# Public: generate an x-download-options header.
#
# Returns a default header if no configuration is provided, o... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/expect_certificate_transparency.rb | lib/secure_headers/headers/expect_certificate_transparency.rb | # frozen_string_literal: true
module SecureHeaders
class ExpectCertificateTransparencyConfigError < StandardError; end
class ExpectCertificateTransparency
HEADER_NAME = "expect-ct".freeze
INVALID_CONFIGURATION_ERROR = "config must be a hash.".freeze
INVALID_ENFORCE_VALUE_ERROR = "enforce must be a bool... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/x_frame_options.rb | lib/secure_headers/headers/x_frame_options.rb | # frozen_string_literal: true
module SecureHeaders
class XFOConfigError < StandardError; end
class XFrameOptions
HEADER_NAME = "x-frame-options".freeze
SAMEORIGIN = "sameorigin"
DENY = "deny"
ALLOW_FROM = "allow-from"
ALLOW_ALL = "allowall"
DEFAULT_VALUE = SAMEORIGIN
VALID_XFO_HEADER = /... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/strict_transport_security.rb | lib/secure_headers/headers/strict_transport_security.rb | # frozen_string_literal: true
module SecureHeaders
class STSConfigError < StandardError; end
class StrictTransportSecurity
HEADER_NAME = "strict-transport-security".freeze
HSTS_MAX_AGE = "631138519"
DEFAULT_VALUE = "max-age=" + HSTS_MAX_AGE
VALID_STS_HEADER = /\Amax-age=\d+(; includeSubdomains)?(; ... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/clear_site_data.rb | lib/secure_headers/headers/clear_site_data.rb | # frozen_string_literal: true
module SecureHeaders
class ClearSiteDataConfigError < StandardError; end
class ClearSiteData
HEADER_NAME = "clear-site-data".freeze
# Valid `types`
CACHE = "cache".freeze
COOKIES = "cookies".freeze
STORAGE = "storage".freeze
EXECUTION_CONTEXTS = "executionConte... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/x_content_type_options.rb | lib/secure_headers/headers/x_content_type_options.rb | # frozen_string_literal: true
module SecureHeaders
class XContentTypeOptionsConfigError < StandardError; end
class XContentTypeOptions
HEADER_NAME = "x-content-type-options".freeze
DEFAULT_VALUE = "nosniff"
# Public: generate an X-Content-Type-Options header.
#
# Returns a default header if no... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/x_permitted_cross_domain_policies.rb | lib/secure_headers/headers/x_permitted_cross_domain_policies.rb | # frozen_string_literal: true
module SecureHeaders
class XPCDPConfigError < StandardError; end
class XPermittedCrossDomainPolicies
HEADER_NAME = "x-permitted-cross-domain-policies".freeze
DEFAULT_VALUE = "none"
VALID_POLICIES = %w(all none master-only by-content-type by-ftp-filename)
# Public: gene... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/x_xss_protection.rb | lib/secure_headers/headers/x_xss_protection.rb | # frozen_string_literal: true
module SecureHeaders
class XXssProtectionConfigError < StandardError; end
class XXssProtection
HEADER_NAME = "x-xss-protection".freeze
DEFAULT_VALUE = "0".freeze
VALID_X_XSS_HEADER = /\A[01](; mode=block)?(; report=.*)?\z/
# Public: generate an X-Xss-Protection header.... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/content_security_policy_config.rb | lib/secure_headers/headers/content_security_policy_config.rb | # frozen_string_literal: true
module SecureHeaders
module DynamicConfig
def initialize(hash)
@config = {}
from_hash(hash)
end
def initialize_copy(hash)
@config = hash.to_h
end
def update_directive(directive, value)
@config[directive] = value
end
def directive_va... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/cookie.rb | lib/secure_headers/headers/cookie.rb | # frozen_string_literal: true
require "cgi"
require "secure_headers/utils/cookies_config"
module SecureHeaders
class CookiesConfigError < StandardError; end
class Cookie
def self.validate_config!(config)
CookiesConfig.new(config).validate!
end
attr_reader :raw_cookie, :config
COOKIE_DEFAU... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/policy_management.rb | lib/secure_headers/headers/policy_management.rb | # frozen_string_literal: true
require "set"
module SecureHeaders
module PolicyManagement
def self.included(base)
base.extend(ClassMethods)
end
DEFAULT_CONFIG = {
default_src: %w(https:),
img_src: %w(https: data: 'self'),
object_src: %w('none'),
script_src: %w(https:),
... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
github/secure_headers | https://github.com/github/secure_headers/blob/d2c41cef9493407684d67a6b8e83e3769f7085d6/lib/secure_headers/headers/referrer_policy.rb | lib/secure_headers/headers/referrer_policy.rb | # frozen_string_literal: true
module SecureHeaders
class ReferrerPolicyConfigError < StandardError; end
class ReferrerPolicy
HEADER_NAME = "referrer-policy".freeze
DEFAULT_VALUE = "origin-when-cross-origin"
VALID_POLICIES = %w(
no-referrer
no-referrer-when-downgrade
same-origin
s... | ruby | MIT | d2c41cef9493407684d67a6b8e83e3769f7085d6 | 2026-01-04T15:51:11.711416Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/regression_specs.rb | spec/regression_specs.rb | # frozen_string_literal: true
require "spec_helper"
RSpec.describe "Regression testing" do
describe "#248" do
it "does not fail with github" do
github_uri = "http://github.com/"
expect { HTTP.get(github_uri).to_s }.not_to raise_error
end
it "does not fail with googleapis" do
google_ur... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/spec_helper.rb | spec/spec_helper.rb | # frozen_string_literal: true
require_relative "./support/simplecov"
require_relative "./support/fuubar" unless ENV["CI"]
require "http"
require "rspec/its"
require "rspec/memory"
require "support/capture_warning"
require "support/fakeio"
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.confi... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/ssl_helper.rb | spec/support/ssl_helper.rb | # frozen_string_literal: true
require "pathname"
require "certificate_authority"
module SSLHelper
CERTS_PATH = Pathname.new File.expand_path("../../tmp/certs", __dir__)
class RootCertificate < ::CertificateAuthority::Certificate
EXTENSIONS = {"keyUsage" => {"usage" => %w[critical keyCertSign]}}.freeze
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/proxy_server.rb | spec/support/proxy_server.rb | # frozen_string_literal: true
require "webrick/httpproxy"
require "support/black_hole"
require "support/servers/config"
require "support/servers/runner"
class ProxyServer < WEBrick::HTTPProxyServer
include ServerConfig
CONFIG = {
BindAddress: "127.0.0.1",
Port: 0,
AccessLog: Bla... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/capture_warning.rb | spec/support/capture_warning.rb | # frozen_string_literal: true
def capture_warning
old_stderr = $stderr
$stderr = StringIO.new
yield
$stderr.string
ensure
$stderr = old_stderr
end
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/simplecov.rb | spec/support/simplecov.rb | # frozen_string_literal: true
require "simplecov"
if ENV["CI"]
require "simplecov-lcov"
SimpleCov::Formatter::LcovFormatter.config do |config|
config.report_with_single_file = true
config.lcov_file_name = "lcov.info"
end
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
end
SimpleC... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/fuubar.rb | spec/support/fuubar.rb | # frozen_string_literal: true
require "fuubar"
RSpec.configure do |config|
# Use Fuubar instafail-alike formatter, unless a formatter has already been
# configured (e.g. via a command-line flag).
config.default_formatter = "Fuubar"
# Disable auto-refresh of the fuubar progress bar to avoid surprises during
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/http_handling_shared.rb | spec/support/http_handling_shared.rb | # frozen_string_literal: true
RSpec.shared_context "HTTP handling" do
context "without timeouts" do
let(:options) { {timeout_class: HTTP::Timeout::Null, timeout_options: {}} }
it "works" do
expect(client.get(server.endpoint).body.to_s).to eq("<!doctype html>")
end
end
context "with a per oper... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/dummy_server.rb | spec/support/dummy_server.rb | # frozen_string_literal: true
require "webrick"
require "webrick/ssl"
require "support/black_hole"
require "support/dummy_server/servlet"
require "support/servers/config"
require "support/servers/runner"
require "support/ssl_helper"
class DummyServer < WEBrick::HTTPServer
include ServerConfig
CONFIG = {
Bin... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/black_hole.rb | spec/support/black_hole.rb | # frozen_string_literal: true
module BlackHole
class << self
def method_missing(*)
self
end
def respond_to_missing?(*)
true
end
end
end
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/fakeio.rb | spec/support/fakeio.rb | # frozen_string_literal: true
require "stringio"
class FakeIO
def initialize(content)
@io = StringIO.new(content)
end
def string
@io.string
end
def read(*args)
@io.read(*args)
end
def size
@io.size
end
end
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/dummy_server/servlet.rb | spec/support/dummy_server/servlet.rb | # encoding: UTF-8
# frozen_string_literal: true
require "cgi"
class DummyServer < WEBrick::HTTPServer
class Servlet < WEBrick::HTTPServlet::AbstractServlet # rubocop:disable Metrics/ClassLength
def self.sockets
@sockets ||= []
end
def not_found(req, res)
res.status = 404
res.body = ... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/servers/runner.rb | spec/support/servers/runner.rb | # frozen_string_literal: true
module ServerRunner
def run_server(name)
let! name do
server = yield
Thread.new { server.start }
server
end
after do
send(name).shutdown
end
end
end
RSpec.configure { |c| c.extend ServerRunner }
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/support/servers/config.rb | spec/support/servers/config.rb | # frozen_string_literal: true
module ServerConfig
def addr
config[:BindAddress]
end
def port
config[:Port]
end
end
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http_spec.rb | spec/lib/http_spec.rb | # encoding: utf-8
# frozen_string_literal: true
require "json"
require "support/dummy_server"
require "support/proxy_server"
RSpec.describe HTTP do
run_server(:dummy) { DummyServer.new }
run_server(:dummy_ssl) { DummyServer.new(ssl: true) }
let(:ssl_client) do
HTTP::Client.new ssl_context: SSLHelper.clien... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/response_spec.rb | spec/lib/http/response_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Response do
subject(:response) do
HTTP::Response.new(
status: 200,
version: "1.1",
headers: headers,
body: body,
request: request
)
end
let(:body) { "Hello world!" }
let(:uri) { "http://example.com/... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/request_spec.rb | spec/lib/http/request_spec.rb | # coding: utf-8
# frozen_string_literal: true
RSpec.describe HTTP::Request do
subject :request do
HTTP::Request.new(
verb: :get,
uri: request_uri,
headers: headers,
proxy: proxy
)
end
let(:proxy) { {} }
let(:headers) { {accept: "text/html"} }
let(:request_u... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/client_spec.rb | spec/lib/http/client_spec.rb | # coding: utf-8
# frozen_string_literal: true
require "cgi"
require "logger"
require "support/http_handling_shared"
require "support/dummy_server"
require "support/ssl_helper"
RSpec.describe HTTP::Client do
run_server(:dummy) { DummyServer.new }
before do
stubbed_client = Class.new(HTTP::Client) do
de... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/connection_spec.rb | spec/lib/http/connection_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Connection do
let(:req) do
HTTP::Request.new(
verb: :get,
uri: "http://example.com/",
headers: {}
)
end
let(:socket) { double(connect: nil, close: nil) }
let(:timeout_class) { double(new: socket) }
let(:opts) { HTTP::Options.... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/headers_spec.rb | spec/lib/http/headers_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Headers do
subject(:headers) { described_class.new }
it "is Enumerable" do
expect(headers).to be_an Enumerable
end
describe "#set" do
it "sets header value" do
headers.set "Accept", "application/json"
expect(headers["Accept"]).to eq "appl... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/redirector_spec.rb | spec/lib/http/redirector_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Redirector do
def simple_response(status, body = "", headers = {})
HTTP::Response.new(
status: status,
version: "1.1",
headers: headers,
body: body,
request: HTTP::Request.new(verb: :get, uri: "http://example.com")
)
end
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/uri_spec.rb | spec/lib/http/uri_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::URI do
subject(:ipv6_uri) { described_class.parse(example_ipv6_uri_string) }
let(:example_ipv6_address) { "2606:2800:220:1:248:1893:25c8:1946" }
let(:example_http_uri_string) { "http://example.com" }
let(:example_https_uri_string) { "https://example.com" }
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/content_type_spec.rb | spec/lib/http/content_type_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::ContentType do
describe ".parse" do
context "with text/plain" do
subject { described_class.parse "text/plain" }
its(:mime_type) { is_expected.to eq "text/plain" }
its(:charset) { is_expected.to be_nil }
end
context "with tEXT/plaIN"... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options_spec.rb | spec/lib/http/options_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options do
subject { described_class.new(response: :body) }
it "has reader methods for attributes" do
expect(subject.response).to eq(:body)
end
it "coerces to a Hash" do
expect(subject.to_hash).to be_a(Hash)
end
end
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/uri/normalizer_spec.rb | spec/lib/http/uri/normalizer_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::URI::NORMALIZER do
describe "scheme" do
it "lower-cases scheme" do
expect(HTTP::URI::NORMALIZER.call("HttP://example.com").scheme).to eq "http"
end
end
describe "hostname" do
it "lower-cases hostname" do
expect(HTTP::URI::NORMALIZER.call... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options/form_spec.rb | spec/lib/http/options/form_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options, "form" do
let(:opts) { HTTP::Options.new }
it "defaults to nil" do
expect(opts.form).to be_nil
end
it "may be specified with with_form_data" do
opts2 = opts.with_form(foo: 42)
expect(opts.form).to be_nil
expect(opts2.form).to eq(foo:... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options/new_spec.rb | spec/lib/http/options/new_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options, "new" do
it "supports a Options instance" do
opts = HTTP::Options.new
expect(HTTP::Options.new(opts)).to eq(opts)
end
context "with a Hash" do
it "coerces :response correctly" do
opts = HTTP::Options.new(response: :object)
expec... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options/proxy_spec.rb | spec/lib/http/options/proxy_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options, "proxy" do
let(:opts) { HTTP::Options.new }
it "defaults to {}" do
expect(opts.proxy).to eq({})
end
it "may be specified with with_proxy" do
opts2 = opts.with_proxy(proxy_address: "127.0.0.1", proxy_port: 8080)
expect(opts.proxy).to eq({... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options/features_spec.rb | spec/lib/http/options/features_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options, "features" do
let(:opts) { HTTP::Options.new }
it "defaults to be empty" do
expect(opts.features).to be_empty
end
it "accepts plain symbols in array" do
opts2 = opts.with_features([:auto_inflate])
expect(opts.features).to be_empty
ex... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options/headers_spec.rb | spec/lib/http/options/headers_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options, "headers" do
let(:opts) { HTTP::Options.new }
it "defaults to be empty" do
expect(opts.headers).to be_empty
end
it "may be specified with with_headers" do
opts2 = opts.with_headers(accept: "json")
expect(opts.headers).to be_empty
exp... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options/body_spec.rb | spec/lib/http/options/body_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options, "body" do
let(:opts) { HTTP::Options.new }
it "defaults to nil" do
expect(opts.body).to be_nil
end
it "may be specified with with_body" do
opts2 = opts.with_body("foo")
expect(opts.body).to be_nil
expect(opts2.body).to eq("foo")
en... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options/json_spec.rb | spec/lib/http/options/json_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options, "json" do
let(:opts) { HTTP::Options.new }
it "defaults to nil" do
expect(opts.json).to be_nil
end
it "may be specified with with_json data" do
opts2 = opts.with_json(foo: 42)
expect(opts.json).to be_nil
expect(opts2.json).to eq(foo:... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/options/merge_spec.rb | spec/lib/http/options/merge_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Options, "merge" do
let(:opts) { HTTP::Options.new }
it "supports a Hash" do
old_response = opts.response
expect(opts.merge(response: :body).response).to eq(:body)
expect(opts.response).to eq(old_response)
end
it "supports another Options" do
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/retriable/performer_spec.rb | spec/lib/http/retriable/performer_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Retriable::Performer do
let(:client) do
HTTP::Client.new
end
let(:response) do
HTTP::Response.new(
status: 200,
version: "1.1",
headers: {},
body: "Hello world!",
request: request
)
end
let(:request) do
HTT... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/retriable/delay_calculator_spec.rb | spec/lib/http/retriable/delay_calculator_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Retriable::DelayCalculator do
let(:response) do
HTTP::Response.new(
status: 200,
version: "1.1",
headers: {},
body: "Hello world!",
request: HTTP::Request.new(verb: :get, uri: "http://example.com")
)
end
def call_delay(... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/features/auto_deflate_spec.rb | spec/lib/http/features/auto_deflate_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Features::AutoDeflate do
subject { HTTP::Features::AutoDeflate.new }
it "raises error for wrong type" do
expect { HTTP::Features::AutoDeflate.new(method: :wrong) }.
to raise_error(HTTP::Error) { |error|
expect(error.message).to eq("Only gzip and... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/features/auto_inflate_spec.rb | spec/lib/http/features/auto_inflate_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Features::AutoInflate do
subject(:feature) { HTTP::Features::AutoInflate.new }
let(:connection) { double }
let(:headers) { {} }
let(:response) do
HTTP::Response.new(
version: "1.1",
status: 200,
headers: headers,
conn... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/features/instrumentation_spec.rb | spec/lib/http/features/instrumentation_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Features::Instrumentation do
subject(:feature) { HTTP::Features::Instrumentation.new(instrumenter: instrumenter) }
let(:instrumenter) { TestInstrumenter.new }
before do
test_instrumenter = Class.new(HTTP::Features::Instrumentation::NullInstrumenter) do
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/features/logging_spec.rb | spec/lib/http/features/logging_spec.rb | # frozen_string_literal: true
require "logger"
RSpec.describe HTTP::Features::Logging do
subject(:feature) do
logger = Logger.new(logdev)
logger.formatter = ->(severity, _, _, message) { format("** %s **\n%s\n", severity, message) }
described_class.new(logger: logger)
end
let(:logdev) { ... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/features/raise_error_spec.rb | spec/lib/http/features/raise_error_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Features::RaiseError do
subject(:feature) { described_class.new(ignore: ignore) }
let(:connection) { double }
let(:status) { 200 }
let(:ignore) { [] }
describe "#wrap_response" do
subject(:result) { feature.wrap_response(response) }
let(:response)... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/headers/normalizer_spec.rb | spec/lib/http/headers/normalizer_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Headers::Normalizer do
subject(:normalizer) { described_class.new }
include_context RSpec::Memory
describe "#call" do
it "normalizes the header" do
expect(normalizer.call("content_type")).to eq "Content-Type"
end
it "returns a non-frozen str... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/headers/mixin_spec.rb | spec/lib/http/headers/mixin_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Headers::Mixin do
let :dummy_class do
Class.new do
include HTTP::Headers::Mixin
def initialize(headers)
@headers = headers
end
end
end
let(:headers) { HTTP::Headers.new }
let(:dummy) { dummy_class.new headers }
describe... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/response/status_spec.rb | spec/lib/http/response/status_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Response::Status do
describe ".new" do
it "fails if given value does not respond to #to_i" do
expect { described_class.new double }.to raise_error TypeError
end
it "accepts any object that responds to #to_i" do
expect { described_class.new d... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/response/body_spec.rb | spec/lib/http/response/body_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Response::Body do
subject(:body) { described_class.new(connection, encoding: Encoding::UTF_8) }
let(:connection) { double(sequence_id: 0) }
let(:chunks) { ["Hello, ", "World!"] }
before do
allow(connection).to receive(:readpartial) { chunks.shift }
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/response/parser_spec.rb | spec/lib/http/response/parser_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Response::Parser do
subject(:parser) { described_class.new }
let(:raw_response) do
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: application/json\r\nMyHeader: val\r\nEmptyHeader: \r\n\r\n{}"
end
let(:expected_headers) do
{
"Content-Leng... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/request/writer_spec.rb | spec/lib/http/request/writer_spec.rb | # coding: utf-8
# frozen_string_literal: true
RSpec.describe HTTP::Request::Writer do
subject(:writer) { described_class.new(io, body, headers, headerstart) }
let(:io) { StringIO.new }
let(:body) { HTTP::Request::Body.new("") }
let(:headers) { HTTP::Headers.new }
let(:headerstart) { "GE... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/spec/lib/http/request/body_spec.rb | spec/lib/http/request/body_spec.rb | # frozen_string_literal: true
RSpec.describe HTTP::Request::Body do
subject { HTTP::Request::Body.new(body) }
let(:body) { "" }
describe "#initialize" do
context "when body is nil" do
let(:body) { nil }
it "does not raise an error" do
expect { subject }.not_to raise_error
end
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http.rb | lib/http.rb | # frozen_string_literal: true
require "http/errors"
require "http/timeout/null"
require "http/timeout/per_operation"
require "http/timeout/global"
require "http/chainable"
require "http/client"
require "http/retriable/client"
require "http/connection"
require "http/options"
require "http/feature"
require "http/request... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/version.rb | lib/http/version.rb | # frozen_string_literal: true
module HTTP
VERSION = "5.2.0"
end
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/content_type.rb | lib/http/content_type.rb | # frozen_string_literal: true
module HTTP
class ContentType
MIME_TYPE_RE = %r{^([^/]+/[^;]+)(?:$|;)}
CHARSET_RE = /;\s*charset=([^;]+)/i
attr_accessor :mime_type, :charset
class << self
# Parse string and return ContentType struct
def parse(str)
new mime_type(str), charset(str... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/errors.rb | lib/http/errors.rb | # frozen_string_literal: true
module HTTP
# Generic error
class Error < StandardError; end
# Generic Connection error
class ConnectionError < Error; end
# Types of Connection errors
class ResponseHeaderError < ConnectionError; end
class SocketReadError < ConnectionError; end
class SocketWriteError < ... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/options.rb | lib/http/options.rb | # frozen_string_literal: true
require "http/headers"
require "openssl"
require "socket"
require "http/uri"
module HTTP
class Options # rubocop:disable Metrics/ClassLength
@default_socket_class = TCPSocket
@default_ssl_socket_class = OpenSSL::SSL::SSLSocket
@default_timeout_class = HTTP::Timeout::... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/response.rb | lib/http/response.rb | # frozen_string_literal: true
require "forwardable"
require "http/errors"
require "http/headers"
require "http/content_type"
require "http/mime_type"
require "http/response/status"
require "http/response/inflater"
require "http/cookie_jar"
require "time"
module HTTP
class Response
extend Forwardable
inclu... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/feature.rb | lib/http/feature.rb | # frozen_string_literal: true
module HTTP
class Feature
def wrap_request(request)
request
end
def wrap_response(response)
response
end
def on_error(_request, _error); end
end
end
require "http/features/auto_inflate"
require "http/features/auto_deflate"
require "http/features/inst... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/base64.rb | lib/http/base64.rb | # frozen_string_literal: true
module HTTP
module Base64
module_function
# Equivalent to Base64.strict_encode64
def encode64(input)
[input].pack("m0")
end
end
end
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/uri.rb | lib/http/uri.rb | # frozen_string_literal: true
require "addressable/uri"
module HTTP
class URI
extend Forwardable
def_delegators :@uri, :scheme, :normalized_scheme, :scheme=
def_delegators :@uri, :user, :normalized_user, :user=
def_delegators :@uri, :password, :normalized_password, :password=
def_delegators :@u... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/connection.rb | lib/http/connection.rb | # frozen_string_literal: true
require "forwardable"
require "http/headers"
module HTTP
# A connection to the HTTP server
class Connection
extend Forwardable
# Allowed values for CONNECTION header
KEEP_ALIVE = "Keep-Alive"
CLOSE = "close"
# Attempt to read this much data
BUFFER_SIZE... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/client.rb | lib/http/client.rb | # frozen_string_literal: true
require "forwardable"
require "http/form_data"
require "http/options"
require "http/feature"
require "http/headers"
require "http/connection"
require "http/redirector"
require "http/uri"
module HTTP
# Clients make requests and receive responses
class Client
extend Forwardable
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/chainable.rb | lib/http/chainable.rb | # frozen_string_literal: true
require "http/base64"
require "http/headers"
module HTTP
module Chainable
include HTTP::Base64
# Request a get sans response body
# @param uri
# @option options [Hash]
def head(uri, options = {})
request :head, uri, options
end
# Get a resource
#... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/request.rb | lib/http/request.rb | # frozen_string_literal: true
require "forwardable"
require "time"
require "http/base64"
require "http/errors"
require "http/headers"
require "http/request/body"
require "http/request/writer"
require "http/version"
require "http/uri"
module HTTP
class Request
extend Forwardable
include HTTP::Base64
in... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/redirector.rb | lib/http/redirector.rb | # frozen_string_literal: true
require "set"
require "http/headers"
module HTTP
class Redirector
# Notifies that we reached max allowed redirect hops
class TooManyRedirectsError < ResponseError; end
# Notifies that following redirects got into an endless loop
class EndlessRedirectError < TooManyRed... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/headers.rb | lib/http/headers.rb | # frozen_string_literal: true
require "forwardable"
require "http/errors"
require "http/headers/mixin"
require "http/headers/normalizer"
require "http/headers/known"
module HTTP
# HTTP Headers container.
class Headers
extend Forwardable
include Enumerable
class << self
# Coerces given `object`... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/mime_type.rb | lib/http/mime_type.rb | # frozen_string_literal: true
require "http/errors"
module HTTP
# MIME type encode/decode adapters
module MimeType
class << self
# Associate MIME type with adapter
#
# @example
#
# module JsonAdapter
# class << self
# def encode(obj)
# # enco... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/retriable/errors.rb | lib/http/retriable/errors.rb | # frozen_string_literal: true
module HTTP
# Retriable performance ran out of attempts
class OutOfRetriesError < Error
attr_accessor :response
attr_writer :cause
def cause
@cause || super
end
end
end
| ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/retriable/delay_calculator.rb | lib/http/retriable/delay_calculator.rb | # frozen_string_literal: true
module HTTP
module Retriable
# @api private
class DelayCalculator
def initialize(opts)
@max_delay = opts.fetch(:max_delay, Float::MAX).to_f
if (delay = opts[:delay]).respond_to?(:call)
@delay_proc = opts.fetch(:delay)
else
@delay... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/retriable/performer.rb | lib/http/retriable/performer.rb | # frozen_string_literal: true
require "date"
require "http/retriable/errors"
require "http/retriable/delay_calculator"
require "openssl"
module HTTP
module Retriable
# Request performing watchdog.
# @api private
class Performer
# Exceptions we should retry
RETRIABLE_ERRORS = [
HTTP::... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/retriable/client.rb | lib/http/retriable/client.rb | # frozen_string_literal: true
require "http/retriable/performer"
module HTTP
module Retriable
# Retriable version of HTTP::Client.
#
# @see http://www.rubydoc.info/gems/http/HTTP/Client
class Client < HTTP::Client
# @param [Performer] performer
# @param [HTTP::Options, Hash] options
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/features/raise_error.rb | lib/http/features/raise_error.rb | # frozen_string_literal: true
module HTTP
module Features
class RaiseError < Feature
def initialize(ignore: [])
super()
@ignore = ignore
end
def wrap_response(response)
return response if response.code < 400
return response if @ignore.include?(response.code)
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/features/logging.rb | lib/http/features/logging.rb | # frozen_string_literal: true
module HTTP
module Features
# Log requests and responses. Request verb and uri, and Response status are
# logged at `info`, and the headers and bodies of both are logged at
# `debug`. Be sure to specify the logger when enabling the feature:
#
# HTTP.use(logging: {... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/features/normalize_uri.rb | lib/http/features/normalize_uri.rb | # frozen_string_literal: true
require "http/uri"
module HTTP
module Features
class NormalizeUri < Feature
attr_reader :normalizer
def initialize(normalizer: HTTP::URI::NORMALIZER)
super()
@normalizer = normalizer
end
HTTP::Options.register_feature(:normalize_uri, self)
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/features/auto_inflate.rb | lib/http/features/auto_inflate.rb | # frozen_string_literal: true
require "set"
module HTTP
module Features
class AutoInflate < Feature
SUPPORTED_ENCODING = Set.new(%w[deflate gzip x-gzip]).freeze
private_constant :SUPPORTED_ENCODING
def wrap_response(response)
return response unless supported_encoding?(response)
... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/features/instrumentation.rb | lib/http/features/instrumentation.rb | # frozen_string_literal: true
module HTTP
module Features
# Instrument requests and responses. Expects an
# ActiveSupport::Notifications-compatible instrumenter. Defaults to use a
# namespace of 'http' which may be overridden with a `:namespace` param.
# Emits a single event like `"request.{namespace... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
httprb/http | https://github.com/httprb/http/blob/7a32573d61477ab45af321f40e05039c6301c2f6/lib/http/features/auto_deflate.rb | lib/http/features/auto_deflate.rb | # frozen_string_literal: true
require "set"
require "tempfile"
require "zlib"
require "http/request/body"
module HTTP
module Features
class AutoDeflate < Feature
VALID_METHODS = Set.new(%w[gzip deflate]).freeze
attr_reader :method
def initialize(method: "gzip")
super()
@met... | ruby | MIT | 7a32573d61477ab45af321f40e05039c6301c2f6 | 2026-01-04T15:51:40.084926Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.