> For the complete documentation index, see [llms.txt](https://andrewmcodes.gitbook.io/vcr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://andrewmcodes.gitbook.io/vcr/configuration/allow_http_connections_when_no_cassette.md).

# Allow HTTP connections when no cassette

Usually, HTTP requests made when no cassette is inserted will [result in an error](https://github.com/andrewmcodes/vcr-docs/tree/7a05e6f0bf36d64e518b44d4e671c079c47fdf3b/cassettes/error-for-http-request-made-when-no-cassette-is-in-use/README.md). You can set the `allow_http_connections_when_no_cassette` configuration option to true to allow requests, if you do not want to use VCR for everything.

## Background ()

*Given* a file named "vcr\_setup.rb" with:

```
if ARGV.include?('--with-server')
  $server = start_sinatra_app do
    get('/') { "Hello" }
  end
end

require 'vcr'

VCR.configure do |c|
  c.allow_http_connections_when_no_cassette = true
  c.hook_into :webmock
  c.cassette_library_dir = 'cassettes'
  c.default_cassette_options = {
    :match_requests_on => [:method, :host, :path]
  }
end
```

*And* the directory "vcr/cassettes" does not exist.

## Allow HTTP connections when no cassette

*Given* a file named "no\_cassette.rb" with:

```
require 'vcr_setup.rb'

puts "Response: " + Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0).body
```

*When* I run `ruby no_cassette.rb --with-server`

*Then* the output should contain "Response: Hello".

## Cassettes record and replay as normal

*Given* a file named "record\_replay\_cassette.rb" with:

```
require 'vcr_setup.rb'

VCR.use_cassette('localhost') do
  puts "Response: " + Net::HTTP.get_response('localhost', '/', $server ? $server.port : 0).body
end
```

*When* I run `ruby record_replay_cassette.rb --with-server`

*Then* the output should contain "Response: Hello"

*And* the file "cassettes/localhost.yml" should contain "Hello"

*When* I run `ruby record_replay_cassette.rb`

*Then* the output should contain "Response: Hello".


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://andrewmcodes.gitbook.io/vcr/configuration/allow_http_connections_when_no_cassette.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
