passenger 5.0.4 → 5.0.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of passenger might be problematic. Click here for more details.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/.editorconfig +10 -0
- data/CHANGELOG +21 -0
- data/build/agents.rb +2 -2
- data/build/apache2.rb +6 -5
- data/build/common_library.rb +22 -7
- data/build/cxx_tests.rb +0 -3
- data/build/misc.rb +1 -1
- data/dev/parse_file_descriptor_log +119 -0
- data/doc/CloudLicensingConfiguration.html +387 -0
- data/doc/Design and Architecture.html +2430 -0
- data/doc/Packaging.html +488 -0
- data/doc/Security of user switching support.html +1833 -0
- data/doc/ServerOptimizationGuide.html +659 -0
- data/doc/ServerOptimizationGuide.txt.md +8 -0
- data/doc/Users guide Apache.html +9116 -0
- data/doc/Users guide Apache.idmap.txt +6 -2
- data/doc/Users guide Apache.txt +26 -7
- data/doc/Users guide Nginx.html +9025 -0
- data/doc/Users guide Nginx.idmap.txt +7 -3
- data/doc/Users guide Nginx.txt +29 -6
- data/doc/Users guide Standalone.html +3983 -0
- data/doc/Users guide.html +1748 -0
- data/doc/users_guide_snippets/installation.txt +4 -4
- data/ext/apache2/Configuration.cpp +16 -5
- data/ext/apache2/Configuration.hpp +4 -2
- data/ext/apache2/Hooks.cpp +44 -19
- data/ext/boost/libs/thread/src/pthread/once.cpp +2 -0
- data/ext/boost/libs/thread/src/pthread/once_atomic.cpp +6 -0
- data/ext/common/AgentsStarter.h +3 -2
- data/ext/common/ApplicationPool2/DirectSpawner.h +14 -4
- data/ext/common/ApplicationPool2/DummySpawner.h +12 -7
- data/ext/common/ApplicationPool2/Implementation.cpp +1 -1
- data/ext/common/ApplicationPool2/Process.h +2 -1
- data/ext/common/ApplicationPool2/Session.h +6 -6
- data/ext/common/ApplicationPool2/SmartSpawner.h +19 -4
- data/ext/common/ApplicationPool2/Socket.h +59 -27
- data/ext/common/ApplicationPool2/Spawner.h +2 -2
- data/ext/common/BackgroundEventLoop.cpp +6 -1
- data/ext/common/Constants.h +1 -1
- data/ext/common/EventedClient.h +1 -1
- data/ext/common/EventedServer.h +2 -2
- data/ext/common/FileDescriptor.h +25 -6
- data/ext/common/Logging.cpp +107 -52
- data/ext/common/Logging.h +146 -19
- data/ext/common/MessageClient.h +2 -2
- data/ext/common/MessageServer.h +3 -2
- data/ext/common/RandomGenerator.h +8 -7
- data/ext/common/SafeLibev.h +5 -1
- data/ext/common/ServerKit/AcceptLoadBalancer.h +9 -4
- data/ext/common/ServerKit/FdSinkChannel.h +5 -2
- data/ext/common/ServerKit/FdSourceChannel.h +5 -2
- data/ext/common/ServerKit/FileBufferedChannel.h +2 -0
- data/ext/common/ServerKit/FileBufferedFdSinkChannel.h +7 -2
- data/ext/common/ServerKit/HttpServer.h +6 -0
- data/ext/common/ServerKit/Server.h +40 -3
- data/ext/common/StaticString.h +20 -0
- data/ext/common/UnionStation/Connection.h +3 -1
- data/ext/common/UnionStation/Core.h +6 -4
- data/ext/common/Utils.cpp +4 -3
- data/ext/common/Utils/DateParsing.h +19 -5
- data/ext/common/Utils/FastStringStream.h +183 -0
- data/ext/common/Utils/IOUtils.cpp +47 -28
- data/ext/common/Utils/IOUtils.h +56 -12
- data/ext/common/Utils/MessagePassing.h +3 -3
- data/ext/common/Utils/ProcessMetricsCollector.h +2 -2
- data/ext/common/Utils/ScopeGuard.h +16 -5
- data/ext/common/Utils/SpeedMeter.h +2 -2
- data/ext/common/Utils/StrIntUtils.cpp +6 -6
- data/ext/common/Utils/StrIntUtils.h +2 -1
- data/ext/common/agents/Base.cpp +56 -4
- data/ext/common/agents/Base.h +2 -1
- data/ext/common/agents/HelperAgent/AdminServer.h +122 -11
- data/ext/common/agents/HelperAgent/Main.cpp +16 -5
- data/ext/common/agents/HelperAgent/OptionParser.h +7 -1
- data/ext/common/agents/HelperAgent/RequestHandler.h +1 -1
- data/ext/common/agents/HelperAgent/RequestHandler/Hooks.cpp +10 -1
- data/ext/common/agents/HelperAgent/RequestHandler/Request.h +8 -0
- data/ext/common/agents/HelperAgent/RequestHandler/TurboCaching.h +4 -3
- data/ext/common/agents/LoggingAgent/AdminServer.h +57 -11
- data/ext/common/agents/LoggingAgent/LoggingServer.h +3 -3
- data/ext/common/agents/LoggingAgent/Main.cpp +11 -3
- data/ext/common/agents/Watchdog/AdminServer.h +53 -11
- data/ext/common/agents/Watchdog/AgentWatcher.cpp +3 -3
- data/ext/common/agents/Watchdog/Main.cpp +13 -6
- data/ext/libeio/ecb.h +1 -1
- data/ext/libev/ev.c +13 -1
- data/ext/libev/ev.h +3 -0
- data/ext/nginx/Configuration.c +28 -6
- data/ext/nginx/Configuration.h +2 -1
- data/ext/nginx/ngx_http_passenger_module.c +5 -4
- data/ext/oxt/dynamic_thread_group.hpp +38 -5
- data/lib/phusion_passenger.rb +1 -1
- data/lib/phusion_passenger/common_library.rb +9 -5
- data/lib/phusion_passenger/config/reopen_logs_command.rb +2 -2
- data/lib/phusion_passenger/packaging.rb +23 -37
- data/passenger.gemspec +21 -21
- metadata +4 -453
- metadata.gz.asc +7 -7
- data/.gitignore +0 -68
- data/.travis.yml +0 -16
- data/Gemfile +0 -17
- data/Gemfile.lock +0 -39
- data/Vagrantfile +0 -54
- data/debian.template/README.Debian +0 -15
- data/debian.template/changelog +0 -316
- data/debian.template/compat +0 -1
- data/debian.template/control.erb +0 -91
- data/debian.template/copyright +0 -385
- data/debian.template/libapache2-mod-passenger.install +0 -3
- data/debian.template/libapache2-mod-passenger.postinst +0 -36
- data/debian.template/libapache2-mod-passenger.prerm +0 -15
- data/debian.template/locations.ini.erb +0 -14
- data/debian.template/passenger-dev.install.erb +0 -3
- data/debian.template/passenger-doc.install.erb +0 -2
- data/debian.template/passenger.conf +0 -6
- data/debian.template/passenger.docs +0 -4
- data/debian.template/passenger.install.erb +0 -14
- data/debian.template/passenger.load +0 -3
- data/debian.template/passenger.manpages +0 -3
- data/debian.template/patches/series +0 -0
- data/debian.template/rules.erb +0 -76
- data/debian.template/source/format +0 -1
- data/ext/common/EventedBufferedInput.h +0 -458
- data/packaging/rpm/LICENSE.txt +0 -19
- data/packaging/rpm/Makefile +0 -13
- data/packaging/rpm/README.md +0 -41
- data/packaging/rpm/Vagrantfile +0 -38
- data/packaging/rpm/Vagrantfile.centos +0 -30
- data/packaging/rpm/build +0 -170
- data/packaging/rpm/create_project +0 -41
- data/packaging/rpm/git_update +0 -88
- data/packaging/rpm/image/Dockerfile +0 -37
- data/packaging/rpm/image/Gemfile +0 -3
- data/packaging/rpm/image/Gemfile.lock +0 -12
- data/packaging/rpm/image/RPM-GPG-KEY-amazon-ga +0 -19
- data/packaging/rpm/image/amazon2014-i386.cfg +0 -96
- data/packaging/rpm/image/amazon2014-x86_64.cfg +0 -96
- data/packaging/rpm/image/site-defaults.cfg +0 -168
- data/packaging/rpm/internal/build_tasks.rb +0 -238
- data/packaging/rpm/internal/dummygpg +0 -11
- data/packaging/rpm/internal/exec_build +0 -42
- data/packaging/rpm/internal/get_distro_arch +0 -14
- data/packaging/rpm/internal/get_distro_id +0 -10
- data/packaging/rpm/internal/git_update +0 -27
- data/packaging/rpm/internal/inituidgid +0 -17
- data/packaging/rpm/internal/my_init +0 -344
- data/packaging/rpm/internal/python27 +0 -3
- data/packaging/rpm/internal/repo_update +0 -46
- data/packaging/rpm/internal/setuser +0 -26
- data/packaging/rpm/internal/tracking_helper +0 -40
- data/packaging/rpm/jenkins_release +0 -99
- data/packaging/rpm/lib/build_tasks_support.rb +0 -402
- data/packaging/rpm/lib/preprocessor.rb +0 -341
- data/packaging/rpm/nginx_spec/404.html +0 -119
- data/packaging/rpm/nginx_spec/50x.html +0 -119
- data/packaging/rpm/nginx_spec/index.html +0 -116
- data/packaging/rpm/nginx_spec/nginx-auto-cc-gcc.patch +0 -13
- data/packaging/rpm/nginx_spec/nginx-logo.png +0 -0
- data/packaging/rpm/nginx_spec/nginx-upgrade +0 -13
- data/packaging/rpm/nginx_spec/nginx-upgrade.8 +0 -151
- data/packaging/rpm/nginx_spec/nginx.conf +0 -131
- data/packaging/rpm/nginx_spec/nginx.init +0 -144
- data/packaging/rpm/nginx_spec/nginx.logrotate +0 -13
- data/packaging/rpm/nginx_spec/nginx.service +0 -15
- data/packaging/rpm/nginx_spec/nginx.spec.template +0 -560
- data/packaging/rpm/nginx_spec/nginx.sysconfig +0 -4
- data/packaging/rpm/nginx_spec/passenger.conf +0 -9
- data/packaging/rpm/nginx_spec/poweredby.png +0 -0
- data/packaging/rpm/passenger_spec/apache-passenger.conf.in +0 -26
- data/packaging/rpm/passenger_spec/config.json +0 -30
- data/packaging/rpm/passenger_spec/passenger.logrotate +0 -7
- data/packaging/rpm/passenger_spec/passenger.spec.template +0 -478
- data/packaging/rpm/passenger_spec/passenger_dynamic_thread_group.patch +0 -16
- data/packaging/rpm/passenger_spec/passenger_tests_default_config_example.patch +0 -44
- data/packaging/rpm/passenger_spec/rubygem-passenger-4.0.18-GLIBC_HAVE_LONG_LONG.patch +0 -21
- data/packaging/rpm/repo_update +0 -114
- data/packaging/rpm/setup-system +0 -61
- data/packaging/rpm/shell +0 -10
- data/test/.rspec +0 -4
- data/test/config.json.example +0 -42
- data/test/config.json.rpm-automation +0 -15
- data/test/config.json.travis +0 -15
- data/test/config.json.vagrant +0 -30
- data/test/cxx/ApplicationPool2/DirectSpawnerTest.cpp +0 -124
- data/test/cxx/ApplicationPool2/OptionsTest.cpp +0 -30
- data/test/cxx/ApplicationPool2/PoolTest.cpp +0 -2062
- data/test/cxx/ApplicationPool2/ProcessTest.cpp +0 -130
- data/test/cxx/ApplicationPool2/SmartSpawnerTest.cpp +0 -243
- data/test/cxx/ApplicationPool2/SpawnerTestCases.cpp +0 -823
- data/test/cxx/BufferedIOTest.cpp +0 -364
- data/test/cxx/CachedFileStatTest.cpp +0 -402
- data/test/cxx/CxxTestMain.cpp +0 -181
- data/test/cxx/DataStructures/LStringTest.cpp +0 -275
- data/test/cxx/DataStructures/StringKeyTableTest.cpp +0 -199
- data/test/cxx/DateParsingTest.cpp +0 -75
- data/test/cxx/DechunkerTest.cpp +0 -250
- data/test/cxx/EventedBufferedInputTest.cpp +0 -758
- data/test/cxx/EventedClientTest.cpp +0 -523
- data/test/cxx/FileChangeCheckerTest.cpp +0 -331
- data/test/cxx/FileDescriptorTest.cpp +0 -69
- data/test/cxx/FilterSupportTest.cpp +0 -433
- data/test/cxx/IOUtilsTest.cpp +0 -861
- data/test/cxx/MemoryKit/MbufTest.cpp +0 -213
- data/test/cxx/MessageIOTest.cpp +0 -360
- data/test/cxx/MessagePassingTest.cpp +0 -81
- data/test/cxx/MessageReadersWritersTest.cpp +0 -576
- data/test/cxx/MessageServerTest.cpp +0 -393
- data/test/cxx/ProcessMetricsCollectorTest.cpp +0 -123
- data/test/cxx/RequestHandlerTest.cpp +0 -1463
- data/test/cxx/ResponseCacheTest.cpp +0 -322
- data/test/cxx/ServerKit/ChannelTest.cpp +0 -1467
- data/test/cxx/ServerKit/CookieUtilsTest.cpp +0 -274
- data/test/cxx/ServerKit/FileBufferedChannelTest.cpp +0 -992
- data/test/cxx/ServerKit/HeaderTableTest.cpp +0 -177
- data/test/cxx/ServerKit/HttpServerTest.cpp +0 -1580
- data/test/cxx/ServerKit/ServerTest.cpp +0 -408
- data/test/cxx/StaticStringTest.cpp +0 -220
- data/test/cxx/StringMapTest.cpp +0 -131
- data/test/cxx/SystemTimeTest.cpp +0 -37
- data/test/cxx/TemplateTest.cpp +0 -118
- data/test/cxx/TestSupport.cpp +0 -207
- data/test/cxx/TestSupport.h +0 -333
- data/test/cxx/UnionStationTest.cpp +0 -741
- data/test/cxx/Utils/StrIntUtilsTest.cpp +0 -39
- data/test/cxx/UtilsTest.cpp +0 -672
- data/test/cxx/VariantMapTest.cpp +0 -191
- data/test/gdbinit.example +0 -34
- data/test/integration_tests/apache2_tests.rb +0 -585
- data/test/integration_tests/downloaded_binaries_tests.rb +0 -185
- data/test/integration_tests/native_packaging_spec.rb +0 -368
- data/test/integration_tests/nginx_tests.rb +0 -402
- data/test/integration_tests/shared/example_webapp_tests.rb +0 -289
- data/test/integration_tests/source_packaging_test.rb +0 -201
- data/test/integration_tests/spec_helper.rb +0 -22
- data/test/integration_tests/standalone_tests.rb +0 -392
- data/test/node/line_reader_spec.js +0 -338
- data/test/node/spec_helper.js +0 -65
- data/test/oxt/backtrace_test.cpp +0 -88
- data/test/oxt/counter.hpp +0 -55
- data/test/oxt/dynamic_thread_group_test.cpp +0 -131
- data/test/oxt/oxt_test_main.cpp +0 -27
- data/test/oxt/spin_lock_test.cpp +0 -59
- data/test/oxt/syscall_interruption_test.cpp +0 -39
- data/test/ruby/debug_logging_spec.rb +0 -145
- data/test/ruby/message_channel_spec.rb +0 -196
- data/test/ruby/rack/loader_spec.rb +0 -42
- data/test/ruby/rack/preloader_spec.rb +0 -48
- data/test/ruby/rails3.0/loader_spec.rb +0 -26
- data/test/ruby/rails3.0/preloader_spec.rb +0 -32
- data/test/ruby/rails3.1/loader_spec.rb +0 -26
- data/test/ruby/rails3.1/preloader_spec.rb +0 -32
- data/test/ruby/rails3.2/loader_spec.rb +0 -26
- data/test/ruby/rails3.2/preloader_spec.rb +0 -32
- data/test/ruby/rails4.0/loader_spec.rb +0 -28
- data/test/ruby/rails4.0/preloader_spec.rb +0 -34
- data/test/ruby/rails4.1/loader_spec.rb +0 -28
- data/test/ruby/rails4.1/preloader_spec.rb +0 -34
- data/test/ruby/request_handler_spec.rb +0 -747
- data/test/ruby/shared/loader_sharedspec.rb +0 -247
- data/test/ruby/shared/rails/union_station_extensions_sharedspec.rb +0 -357
- data/test/ruby/shared/ruby_loader_sharedspec.rb +0 -55
- data/test/ruby/spec_helper.rb +0 -114
- data/test/ruby/standalone/runtime_installer_spec.rb +0 -402
- data/test/ruby/union_station_spec.rb +0 -288
- data/test/ruby/utils/file_system_watcher_spec.rb +0 -229
- data/test/ruby/utils/hosts_file_parser.rb +0 -258
- data/test/ruby/utils/tee_input_spec.rb +0 -235
- data/test/ruby/utils/unseekable_socket_spec.rb +0 -66
- data/test/ruby/utils_spec.rb +0 -41
- data/test/stub/apache2/httpd.conf.erb +0 -122
- data/test/stub/apache2/mime.types +0 -748
- data/test/stub/garbage1.dat +0 -0
- data/test/stub/garbage2.dat +0 -0
- data/test/stub/garbage3.dat +0 -0
- data/test/stub/http_request.yml +0 -23
- data/test/stub/index.html +0 -1
- data/test/stub/nginx/koi-utf +0 -109
- data/test/stub/nginx/koi-win +0 -103
- data/test/stub/nginx/mime.types +0 -70
- data/test/stub/nginx/nginx.conf.erb +0 -70
- data/test/stub/nginx/win-utf +0 -126
- data/test/stub/node/app.js +0 -133
- data/test/stub/node/public/.gitignore +0 -0
- data/test/stub/node/tmp/.gitignore +0 -0
- data/test/stub/rack/config.ru +0 -95
- data/test/stub/rack/library.rb +0 -16
- data/test/stub/rack/public/.gitignore +0 -0
- data/test/stub/rack/start.rb +0 -52
- data/test/stub/rack/tmp/.gitignore +0 -0
- data/test/stub/rails3.0/.gitignore +0 -4
- data/test/stub/rails3.0/Gemfile +0 -22
- data/test/stub/rails3.0/Gemfile.lock +0 -80
- data/test/stub/rails3.0/Rakefile +0 -10
- data/test/stub/rails3.0/app/controllers/application_controller.rb +0 -4
- data/test/stub/rails3.0/app/helpers/application_helper.rb +0 -2
- data/test/stub/rails3.0/app/views/layouts/application.html.erb +0 -14
- data/test/stub/rails3.0/config.ru +0 -4
- data/test/stub/rails3.0/config/application.rb +0 -48
- data/test/stub/rails3.0/config/boot.rb +0 -13
- data/test/stub/rails3.0/config/database.yml +0 -22
- data/test/stub/rails3.0/config/environment.rb +0 -5
- data/test/stub/rails3.0/config/environments/development.rb +0 -19
- data/test/stub/rails3.0/config/environments/production.rb +0 -48
- data/test/stub/rails3.0/config/environments/test.rb +0 -32
- data/test/stub/rails3.0/config/initializers/backtrace_silencers.rb +0 -7
- data/test/stub/rails3.0/config/initializers/inflections.rb +0 -10
- data/test/stub/rails3.0/config/initializers/mime_types.rb +0 -5
- data/test/stub/rails3.0/config/initializers/passenger.rb +0 -2
- data/test/stub/rails3.0/config/initializers/secret_token.rb +0 -7
- data/test/stub/rails3.0/config/initializers/session_store.rb +0 -8
- data/test/stub/rails3.0/config/locales/en.yml +0 -5
- data/test/stub/rails3.0/config/routes.rb +0 -58
- data/test/stub/rails3.0/db/seeds.rb +0 -7
- data/test/stub/rails3.0/doc/README_FOR_APP +0 -2
- data/test/stub/rails3.0/lib/tasks/.gitkeep +0 -0
- data/test/stub/rails3.0/log/.gitignore +0 -0
- data/test/stub/rails3.0/public/404.html +0 -26
- data/test/stub/rails3.0/public/422.html +0 -26
- data/test/stub/rails3.0/public/500.html +0 -26
- data/test/stub/rails3.0/public/favicon.ico +0 -0
- data/test/stub/rails3.0/public/index.html +0 -279
- data/test/stub/rails3.0/public/robots.txt +0 -5
- data/test/stub/rails3.0/public/stylesheets/.gitkeep +0 -0
- data/test/stub/rails3.0/script/rails +0 -9
- data/test/stub/rails3.0/test/performance/browsing_test.rb +0 -9
- data/test/stub/rails3.0/test/test_helper.rb +0 -13
- data/test/stub/rails3.0/vendor/plugins/.gitkeep +0 -0
- data/test/stub/rails3.1/.gitignore +0 -15
- data/test/stub/rails3.1/Gemfile +0 -37
- data/test/stub/rails3.1/Gemfile.lock +0 -115
- data/test/stub/rails3.1/README +0 -261
- data/test/stub/rails3.1/Rakefile +0 -7
- data/test/stub/rails3.1/app/assets/images/rails.png +0 -0
- data/test/stub/rails3.1/app/assets/stylesheets/application.css +0 -7
- data/test/stub/rails3.1/app/controllers/application_controller.rb +0 -3
- data/test/stub/rails3.1/app/helpers/application_helper.rb +0 -2
- data/test/stub/rails3.1/app/mailers/.gitkeep +0 -0
- data/test/stub/rails3.1/app/models/.gitkeep +0 -0
- data/test/stub/rails3.1/app/views/layouts/application.html.erb +0 -14
- data/test/stub/rails3.1/config.ru +0 -4
- data/test/stub/rails3.1/config/application.rb +0 -48
- data/test/stub/rails3.1/config/boot.rb +0 -6
- data/test/stub/rails3.1/config/database.yml +0 -25
- data/test/stub/rails3.1/config/environment.rb +0 -5
- data/test/stub/rails3.1/config/environments/development.rb +0 -30
- data/test/stub/rails3.1/config/environments/production.rb +0 -60
- data/test/stub/rails3.1/config/environments/test.rb +0 -39
- data/test/stub/rails3.1/config/initializers/backtrace_silencers.rb +0 -7
- data/test/stub/rails3.1/config/initializers/inflections.rb +0 -10
- data/test/stub/rails3.1/config/initializers/mime_types.rb +0 -5
- data/test/stub/rails3.1/config/initializers/passenger.rb +0 -2
- data/test/stub/rails3.1/config/initializers/secret_token.rb +0 -7
- data/test/stub/rails3.1/config/initializers/session_store.rb +0 -8
- data/test/stub/rails3.1/config/initializers/wrap_parameters.rb +0 -14
- data/test/stub/rails3.1/config/locales/en.yml +0 -5
- data/test/stub/rails3.1/config/routes.rb +0 -58
- data/test/stub/rails3.1/db/seeds.rb +0 -7
- data/test/stub/rails3.1/doc/README_FOR_APP +0 -2
- data/test/stub/rails3.1/lib/assets/.gitkeep +0 -0
- data/test/stub/rails3.1/lib/tasks/.gitkeep +0 -0
- data/test/stub/rails3.1/log/.gitkeep +0 -0
- data/test/stub/rails3.1/public/404.html +0 -26
- data/test/stub/rails3.1/public/422.html +0 -26
- data/test/stub/rails3.1/public/500.html +0 -26
- data/test/stub/rails3.1/public/favicon.ico +0 -0
- data/test/stub/rails3.1/public/index.html +0 -241
- data/test/stub/rails3.1/public/robots.txt +0 -5
- data/test/stub/rails3.1/script/rails +0 -6
- data/test/stub/rails3.1/test/fixtures/.gitkeep +0 -0
- data/test/stub/rails3.1/test/functional/.gitkeep +0 -0
- data/test/stub/rails3.1/test/integration/.gitkeep +0 -0
- data/test/stub/rails3.1/test/performance/browsing_test.rb +0 -12
- data/test/stub/rails3.1/test/test_helper.rb +0 -13
- data/test/stub/rails3.1/test/unit/.gitkeep +0 -0
- data/test/stub/rails3.1/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test/stub/rails3.1/vendor/plugins/.gitkeep +0 -0
- data/test/stub/rails3.2/.gitignore +0 -15
- data/test/stub/rails3.2/Gemfile +0 -39
- data/test/stub/rails3.2/Gemfile.lock +0 -113
- data/test/stub/rails3.2/Rakefile +0 -7
- data/test/stub/rails3.2/app/assets/images/rails.png +0 -0
- data/test/stub/rails3.2/app/assets/stylesheets/application.css +0 -13
- data/test/stub/rails3.2/app/controllers/application_controller.rb +0 -3
- data/test/stub/rails3.2/app/helpers/application_helper.rb +0 -2
- data/test/stub/rails3.2/app/mailers/.gitkeep +0 -0
- data/test/stub/rails3.2/app/models/.gitkeep +0 -0
- data/test/stub/rails3.2/app/views/layouts/application.html.erb +0 -14
- data/test/stub/rails3.2/config.ru +0 -4
- data/test/stub/rails3.2/config/application.rb +0 -62
- data/test/stub/rails3.2/config/boot.rb +0 -6
- data/test/stub/rails3.2/config/database.yml +0 -25
- data/test/stub/rails3.2/config/environment.rb +0 -5
- data/test/stub/rails3.2/config/environments/development.rb +0 -37
- data/test/stub/rails3.2/config/environments/production.rb +0 -67
- data/test/stub/rails3.2/config/environments/test.rb +0 -37
- data/test/stub/rails3.2/config/initializers/backtrace_silencers.rb +0 -7
- data/test/stub/rails3.2/config/initializers/inflections.rb +0 -15
- data/test/stub/rails3.2/config/initializers/mime_types.rb +0 -5
- data/test/stub/rails3.2/config/initializers/passenger.rb +0 -2
- data/test/stub/rails3.2/config/initializers/secret_token.rb +0 -7
- data/test/stub/rails3.2/config/initializers/session_store.rb +0 -8
- data/test/stub/rails3.2/config/initializers/wrap_parameters.rb +0 -14
- data/test/stub/rails3.2/config/locales/en.yml +0 -5
- data/test/stub/rails3.2/config/routes.rb +0 -58
- data/test/stub/rails3.2/db/seeds.rb +0 -7
- data/test/stub/rails3.2/doc/README_FOR_APP +0 -2
- data/test/stub/rails3.2/lib/assets/.gitkeep +0 -0
- data/test/stub/rails3.2/lib/tasks/.gitkeep +0 -0
- data/test/stub/rails3.2/log/.gitkeep +0 -0
- data/test/stub/rails3.2/public/404.html +0 -26
- data/test/stub/rails3.2/public/422.html +0 -26
- data/test/stub/rails3.2/public/500.html +0 -25
- data/test/stub/rails3.2/public/favicon.ico +0 -0
- data/test/stub/rails3.2/public/index.html +0 -241
- data/test/stub/rails3.2/public/robots.txt +0 -5
- data/test/stub/rails3.2/script/rails +0 -6
- data/test/stub/rails3.2/test/fixtures/.gitkeep +0 -0
- data/test/stub/rails3.2/test/functional/.gitkeep +0 -0
- data/test/stub/rails3.2/test/integration/.gitkeep +0 -0
- data/test/stub/rails3.2/test/performance/browsing_test.rb +0 -12
- data/test/stub/rails3.2/test/test_helper.rb +0 -13
- data/test/stub/rails3.2/test/unit/.gitkeep +0 -0
- data/test/stub/rails3.2/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test/stub/rails3.2/vendor/plugins/.gitkeep +0 -0
- data/test/stub/rails4.0/.gitignore +0 -16
- data/test/stub/rails4.0/Gemfile +0 -45
- data/test/stub/rails4.0/Gemfile.lock +0 -126
- data/test/stub/rails4.0/README.rdoc +0 -28
- data/test/stub/rails4.0/Rakefile +0 -6
- data/test/stub/rails4.0/app/assets/images/.keep +0 -0
- data/test/stub/rails4.0/app/assets/javascripts/application.js +0 -16
- data/test/stub/rails4.0/app/assets/stylesheets/application.css +0 -13
- data/test/stub/rails4.0/app/controllers/application_controller.rb +0 -5
- data/test/stub/rails4.0/app/controllers/concerns/.keep +0 -0
- data/test/stub/rails4.0/app/helpers/application_helper.rb +0 -2
- data/test/stub/rails4.0/app/mailers/.keep +0 -0
- data/test/stub/rails4.0/app/models/.keep +0 -0
- data/test/stub/rails4.0/app/models/concerns/.keep +0 -0
- data/test/stub/rails4.0/app/views/layouts/application.html.erb +0 -14
- data/test/stub/rails4.0/bin/bundle +0 -3
- data/test/stub/rails4.0/bin/rails +0 -4
- data/test/stub/rails4.0/bin/rake +0 -4
- data/test/stub/rails4.0/config.ru +0 -4
- data/test/stub/rails4.0/config/application.rb +0 -23
- data/test/stub/rails4.0/config/boot.rb +0 -4
- data/test/stub/rails4.0/config/database.yml +0 -25
- data/test/stub/rails4.0/config/environment.rb +0 -5
- data/test/stub/rails4.0/config/environments/development.rb +0 -29
- data/test/stub/rails4.0/config/environments/production.rb +0 -80
- data/test/stub/rails4.0/config/environments/test.rb +0 -36
- data/test/stub/rails4.0/config/initializers/backtrace_silencers.rb +0 -7
- data/test/stub/rails4.0/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/stub/rails4.0/config/initializers/inflections.rb +0 -16
- data/test/stub/rails4.0/config/initializers/mime_types.rb +0 -5
- data/test/stub/rails4.0/config/initializers/passenger.rb +0 -2
- data/test/stub/rails4.0/config/initializers/secret_token.rb +0 -12
- data/test/stub/rails4.0/config/initializers/session_store.rb +0 -3
- data/test/stub/rails4.0/config/initializers/wrap_parameters.rb +0 -14
- data/test/stub/rails4.0/config/locales/en.yml +0 -23
- data/test/stub/rails4.0/config/routes.rb +0 -57
- data/test/stub/rails4.0/db/seeds.rb +0 -7
- data/test/stub/rails4.0/lib/assets/.keep +0 -0
- data/test/stub/rails4.0/lib/tasks/.keep +0 -0
- data/test/stub/rails4.0/log/.keep +0 -0
- data/test/stub/rails4.0/public/404.html +0 -58
- data/test/stub/rails4.0/public/422.html +0 -58
- data/test/stub/rails4.0/public/500.html +0 -57
- data/test/stub/rails4.0/public/favicon.ico +0 -0
- data/test/stub/rails4.0/public/robots.txt +0 -5
- data/test/stub/rails4.0/test/controllers/.keep +0 -0
- data/test/stub/rails4.0/test/fixtures/.keep +0 -0
- data/test/stub/rails4.0/test/helpers/.keep +0 -0
- data/test/stub/rails4.0/test/integration/.keep +0 -0
- data/test/stub/rails4.0/test/mailers/.keep +0 -0
- data/test/stub/rails4.0/test/models/.keep +0 -0
- data/test/stub/rails4.0/test/test_helper.rb +0 -15
- data/test/stub/rails4.0/vendor/assets/javascripts/.keep +0 -0
- data/test/stub/rails4.0/vendor/assets/stylesheets/.keep +0 -0
- data/test/stub/rails4.1/.gitignore +0 -16
- data/test/stub/rails4.1/Gemfile +0 -45
- data/test/stub/rails4.1/Gemfile.lock +0 -129
- data/test/stub/rails4.1/README.rdoc +0 -28
- data/test/stub/rails4.1/Rakefile +0 -6
- data/test/stub/rails4.1/app/assets/images/.keep +0 -0
- data/test/stub/rails4.1/app/assets/javascripts/application.js +0 -16
- data/test/stub/rails4.1/app/assets/stylesheets/application.css +0 -13
- data/test/stub/rails4.1/app/controllers/application_controller.rb +0 -5
- data/test/stub/rails4.1/app/controllers/concerns/.keep +0 -0
- data/test/stub/rails4.1/app/helpers/application_helper.rb +0 -2
- data/test/stub/rails4.1/app/mailers/.keep +0 -0
- data/test/stub/rails4.1/app/models/.keep +0 -0
- data/test/stub/rails4.1/app/models/concerns/.keep +0 -0
- data/test/stub/rails4.1/app/views/layouts/application.html.erb +0 -14
- data/test/stub/rails4.1/bin/bundle +0 -3
- data/test/stub/rails4.1/bin/rails +0 -4
- data/test/stub/rails4.1/bin/rake +0 -4
- data/test/stub/rails4.1/config.ru +0 -4
- data/test/stub/rails4.1/config/application.rb +0 -23
- data/test/stub/rails4.1/config/boot.rb +0 -4
- data/test/stub/rails4.1/config/database.yml +0 -25
- data/test/stub/rails4.1/config/environment.rb +0 -5
- data/test/stub/rails4.1/config/environments/development.rb +0 -29
- data/test/stub/rails4.1/config/environments/production.rb +0 -80
- data/test/stub/rails4.1/config/environments/test.rb +0 -36
- data/test/stub/rails4.1/config/initializers/backtrace_silencers.rb +0 -7
- data/test/stub/rails4.1/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/stub/rails4.1/config/initializers/inflections.rb +0 -16
- data/test/stub/rails4.1/config/initializers/mime_types.rb +0 -5
- data/test/stub/rails4.1/config/initializers/passenger.rb +0 -5
- data/test/stub/rails4.1/config/initializers/secret_token.rb +0 -12
- data/test/stub/rails4.1/config/initializers/session_store.rb +0 -3
- data/test/stub/rails4.1/config/initializers/wrap_parameters.rb +0 -14
- data/test/stub/rails4.1/config/locales/en.yml +0 -23
- data/test/stub/rails4.1/config/routes.rb +0 -57
- data/test/stub/rails4.1/db/seeds.rb +0 -7
- data/test/stub/rails4.1/lib/assets/.keep +0 -0
- data/test/stub/rails4.1/lib/tasks/.keep +0 -0
- data/test/stub/rails4.1/log/.keep +0 -0
- data/test/stub/rails4.1/public/404.html +0 -58
- data/test/stub/rails4.1/public/422.html +0 -58
- data/test/stub/rails4.1/public/500.html +0 -57
- data/test/stub/rails4.1/public/favicon.ico +0 -0
- data/test/stub/rails4.1/public/robots.txt +0 -5
- data/test/stub/rails4.1/test/controllers/.keep +0 -0
- data/test/stub/rails4.1/test/fixtures/.keep +0 -0
- data/test/stub/rails4.1/test/helpers/.keep +0 -0
- data/test/stub/rails4.1/test/integration/.keep +0 -0
- data/test/stub/rails4.1/test/mailers/.keep +0 -0
- data/test/stub/rails4.1/test/models/.keep +0 -0
- data/test/stub/rails4.1/test/test_helper.rb +0 -15
- data/test/stub/rails4.1/vendor/assets/javascripts/.keep +0 -0
- data/test/stub/rails4.1/vendor/assets/stylesheets/.keep +0 -0
- data/test/stub/start_error.pl +0 -24
- data/test/stub/upload_data.txt +0 -494
- data/test/stub/wsgi/passenger_wsgi.py +0 -212
- data/test/stub/wsgi/public/.gitignore +0 -0
- data/test/stub/wsgi/tmp/.gitignore +0 -0
- data/test/support/allocate_memory.c +0 -14
- data/test/support/apache2_controller.rb +0 -258
- data/test/support/multipart.rb +0 -62
- data/test/support/nginx_controller.rb +0 -97
- data/test/support/placebo-preloader.rb +0 -88
- data/test/support/test_helper.rb +0 -455
- data/test/support/valgrind.h +0 -2539
- data/test/tut/tut.h +0 -1310
- data/test/tut/tut_reporter.h +0 -256
- data/test/valgrind-osx.supp +0 -7
@@ -1,177 +0,0 @@
|
|
1
|
-
#include <TestSupport.h>
|
2
|
-
#include <ServerKit/HeaderTable.h>
|
3
|
-
|
4
|
-
using namespace Passenger;
|
5
|
-
using namespace Passenger::ServerKit;
|
6
|
-
using namespace std;
|
7
|
-
|
8
|
-
namespace tut {
|
9
|
-
struct ServerKit_HeaderTableTest {
|
10
|
-
psg_pool_t *pool;
|
11
|
-
HeaderTable table;
|
12
|
-
|
13
|
-
ServerKit_HeaderTableTest() {
|
14
|
-
pool = psg_create_pool(PSG_DEFAULT_POOL_SIZE);
|
15
|
-
}
|
16
|
-
|
17
|
-
~ServerKit_HeaderTableTest() {
|
18
|
-
psg_destroy_pool(pool);
|
19
|
-
}
|
20
|
-
|
21
|
-
Header *createHeader(const HashedStaticString &key, const StaticString &val) {
|
22
|
-
Header *header = (Header *) psg_palloc(pool, sizeof(Header));
|
23
|
-
psg_lstr_init(&header->key);
|
24
|
-
psg_lstr_init(&header->val);
|
25
|
-
psg_lstr_append(&header->key, pool, key.data(), key.size());
|
26
|
-
psg_lstr_append(&header->val, pool, val.data(), val.size());
|
27
|
-
header->hash = key.hash();
|
28
|
-
return header;
|
29
|
-
}
|
30
|
-
};
|
31
|
-
|
32
|
-
DEFINE_TEST_GROUP(ServerKit_HeaderTableTest);
|
33
|
-
|
34
|
-
TEST_METHOD(1) {
|
35
|
-
set_test_name("Initial state");
|
36
|
-
ensure_equals(table.size(), 0u);
|
37
|
-
ensure_equals(table.arraySize(), (unsigned int) HeaderTable::DEFAULT_SIZE);
|
38
|
-
}
|
39
|
-
|
40
|
-
TEST_METHOD(2) {
|
41
|
-
set_test_name("On an empty HeaderTable, iterators reach the end immediately");
|
42
|
-
HeaderTable::Iterator it(table);
|
43
|
-
ensure_equals<void *>(*it, NULL);
|
44
|
-
}
|
45
|
-
|
46
|
-
TEST_METHOD(3) {
|
47
|
-
set_test_name("On an empty HeaderTable, lookups return NULL");
|
48
|
-
ensure_equals<void *>(table.lookup("hello"), NULL);
|
49
|
-
ensure_equals<void *>(table.lookup("?"), NULL);
|
50
|
-
}
|
51
|
-
|
52
|
-
TEST_METHOD(4) {
|
53
|
-
set_test_name("Insertions work");
|
54
|
-
Header *header = createHeader("Content-Length", "5");
|
55
|
-
Header *header2 = createHeader("Host", "foo.com");
|
56
|
-
|
57
|
-
table.insert(header, pool);
|
58
|
-
ensure_equals(table.size(), 1u);
|
59
|
-
ensure_equals<void *>("(1)", table.lookup("hello"), NULL);
|
60
|
-
ensure_equals<void *>("(2)", table.lookup("Host"), NULL);
|
61
|
-
ensure("(3)", table.lookup("Content-Length") != NULL);
|
62
|
-
ensure("(4)", psg_lstr_cmp(table.lookup("Content-Length"), "5"));
|
63
|
-
|
64
|
-
table.insert(header2, pool);
|
65
|
-
ensure_equals(table.size(), 2u);
|
66
|
-
ensure_equals<void *>("(5)", table.lookup("hello"), NULL);
|
67
|
-
ensure("(6)", table.lookup("Host") != NULL);
|
68
|
-
ensure("(7)", table.lookup("Content-Length") != NULL);
|
69
|
-
ensure("(8)", psg_lstr_cmp(table.lookup("Host"), "foo.com"));
|
70
|
-
ensure("(9)", psg_lstr_cmp(table.lookup("Content-Length"), "5"));
|
71
|
-
}
|
72
|
-
|
73
|
-
TEST_METHOD(5) {
|
74
|
-
set_test_name("Large amounts of insertions");
|
75
|
-
|
76
|
-
table.insert(createHeader("Host", "foo.com"), pool);
|
77
|
-
table.insert(createHeader("Content-Length", "5"), pool);
|
78
|
-
table.insert(createHeader("Accept", "text/html"), pool);
|
79
|
-
table.insert(createHeader("Accept-Encoding", "gzip"), pool);
|
80
|
-
table.insert(createHeader("Accept-Language", "nl"), pool);
|
81
|
-
table.insert(createHeader("User-Agent", "Mozilla"), pool);
|
82
|
-
table.insert(createHeader("Set-Cookie", "foo=bar"), pool);
|
83
|
-
table.insert(createHeader("Connection", "keep-alive"), pool);
|
84
|
-
table.insert(createHeader("Cache-Control", "no-cache"), pool);
|
85
|
-
table.insert(createHeader("Pragma", "no-cache"), pool);
|
86
|
-
|
87
|
-
ensure_equals<void *>(table.lookup("MyHeader"), NULL);
|
88
|
-
ensure(psg_lstr_cmp(table.lookup("Host"), "foo.com"));
|
89
|
-
ensure(psg_lstr_cmp(table.lookup("Content-Length"), "5"));
|
90
|
-
ensure(psg_lstr_cmp(table.lookup("Accept"), "text/html"));
|
91
|
-
ensure(psg_lstr_cmp(table.lookup("Accept-Encoding"), "gzip"));
|
92
|
-
ensure(psg_lstr_cmp(table.lookup("Accept-Language"), "nl"));
|
93
|
-
ensure(psg_lstr_cmp(table.lookup("User-Agent"), "Mozilla"));
|
94
|
-
ensure(psg_lstr_cmp(table.lookup("Set-Cookie"), "foo=bar"));
|
95
|
-
ensure(psg_lstr_cmp(table.lookup("Connection"), "keep-alive"));
|
96
|
-
ensure(psg_lstr_cmp(table.lookup("Cache-Control"), "no-cache"));
|
97
|
-
ensure(psg_lstr_cmp(table.lookup("Pragma"), "no-cache"));
|
98
|
-
}
|
99
|
-
|
100
|
-
TEST_METHOD(6) {
|
101
|
-
set_test_name("Iterators work");
|
102
|
-
Header *header = createHeader("Content-Length", "5");
|
103
|
-
Header *header2 = createHeader("Host", "foo.com");
|
104
|
-
table.insert(header, pool);
|
105
|
-
table.insert(header2, pool);
|
106
|
-
|
107
|
-
HeaderTable::Iterator it(table);
|
108
|
-
ensure(*it != NULL);
|
109
|
-
if (psg_lstr_cmp(&it->header->key, "Content-Length")) {
|
110
|
-
it.next();
|
111
|
-
ensure(psg_lstr_cmp(&it->header->key, "Host"));
|
112
|
-
} else {
|
113
|
-
ensure(psg_lstr_cmp(&it->header->key, "Host"));
|
114
|
-
it.next();
|
115
|
-
ensure(psg_lstr_cmp(&it->header->key, "Content-Length"));
|
116
|
-
}
|
117
|
-
|
118
|
-
it.next();
|
119
|
-
ensure_equals<void *>(*it, NULL);
|
120
|
-
}
|
121
|
-
|
122
|
-
TEST_METHOD(7) {
|
123
|
-
set_test_name("Dynamically growing the bucket on insert");
|
124
|
-
table = HeaderTable(4);
|
125
|
-
ensure_equals(table.size(), 0u);
|
126
|
-
ensure_equals(table.arraySize(), 4u);
|
127
|
-
|
128
|
-
table.insert(createHeader("Host", "foo.com"), pool);
|
129
|
-
table.insert(createHeader("Content-Length", "5"), pool);
|
130
|
-
ensure_equals(table.size(), 2u);
|
131
|
-
ensure_equals(table.arraySize(), 4u);
|
132
|
-
|
133
|
-
table.insert(createHeader("Accept", "text/html"), pool);
|
134
|
-
ensure_equals(table.size(), 3u);
|
135
|
-
ensure_equals(table.arraySize(), 8u);
|
136
|
-
|
137
|
-
ensure_equals<void *>(table.lookup("MyHeader"), NULL);
|
138
|
-
ensure(psg_lstr_cmp(table.lookup("Host"), "foo.com"));
|
139
|
-
ensure(psg_lstr_cmp(table.lookup("Content-Length"), "5"));
|
140
|
-
ensure(psg_lstr_cmp(table.lookup("Accept"), "text/html"));
|
141
|
-
}
|
142
|
-
|
143
|
-
TEST_METHOD(8) {
|
144
|
-
set_test_name("Clearing");
|
145
|
-
|
146
|
-
table.insert(createHeader("Host", "foo.com"), pool);
|
147
|
-
table.insert(createHeader("Content-Length", "5"), pool);
|
148
|
-
table.insert(createHeader("Accept", "text/html"), pool);
|
149
|
-
|
150
|
-
table.clear();
|
151
|
-
ensure_equals(table.size(), 0u);
|
152
|
-
ensure_equals(table.arraySize(), (unsigned int) HeaderTable::DEFAULT_SIZE);
|
153
|
-
|
154
|
-
ensure_equals<void *>(table.lookup("Host"), NULL);
|
155
|
-
ensure_equals<void *>(table.lookup("Content-Length"), NULL);
|
156
|
-
ensure_equals<void *>(table.lookup("Accept"), NULL);
|
157
|
-
}
|
158
|
-
|
159
|
-
TEST_METHOD(9) {
|
160
|
-
set_test_name("Duplicate header merging");
|
161
|
-
|
162
|
-
table.insert(createHeader("X-Forwarded-For", "foo.com"), pool);
|
163
|
-
table.insert(createHeader("X-Forwarded-For", "bar.com"), pool);
|
164
|
-
table.insert(createHeader("Cache-Control", "must-invalidate"), pool);
|
165
|
-
table.insert(createHeader("Cache-Control", "private"), pool);
|
166
|
-
table.insert(createHeader("cookie", "a"), pool);
|
167
|
-
table.insert(createHeader("cookie", "b"), pool);
|
168
|
-
table.insert(createHeader("set-cookie", "c=123"), pool);
|
169
|
-
table.insert(createHeader("set-cookie", "d=456"), pool);
|
170
|
-
|
171
|
-
ensure_equals(table.size(), 4u);
|
172
|
-
ensure("(1)", psg_lstr_cmp(table.lookup("X-Forwarded-For"), "foo.com,bar.com"));
|
173
|
-
ensure("(2)", psg_lstr_cmp(table.lookup("Cache-Control"), "must-invalidate,private"));
|
174
|
-
ensure("(3)", psg_lstr_cmp(table.lookup("cookie"), "a;b"));
|
175
|
-
ensure("(4)", psg_lstr_cmp(table.lookup("set-cookie"), "c=123\nd=456"));
|
176
|
-
}
|
177
|
-
}
|
@@ -1,1580 +0,0 @@
|
|
1
|
-
#include <TestSupport.h>
|
2
|
-
#include <boost/foreach.hpp>
|
3
|
-
#include <boost/bind.hpp>
|
4
|
-
#include <boost/shared_ptr.hpp>
|
5
|
-
#include <boost/make_shared.hpp>
|
6
|
-
#include <boost/thread.hpp>
|
7
|
-
#include <oxt/system_calls.hpp>
|
8
|
-
#include <BackgroundEventLoop.h>
|
9
|
-
#include <ServerKit/HttpServer.h>
|
10
|
-
#include <Logging.h>
|
11
|
-
#include <FileDescriptor.h>
|
12
|
-
#include <Utils.h>
|
13
|
-
#include <Utils/IOUtils.h>
|
14
|
-
#include <Utils/BufferedIO.h>
|
15
|
-
|
16
|
-
using namespace Passenger;
|
17
|
-
using namespace Passenger::ServerKit;
|
18
|
-
using namespace Passenger::MemoryKit;
|
19
|
-
using namespace std;
|
20
|
-
using namespace oxt;
|
21
|
-
|
22
|
-
namespace tut {
|
23
|
-
class MyRequest: public BaseHttpRequest {
|
24
|
-
public:
|
25
|
-
string body;
|
26
|
-
|
27
|
-
DEFINE_SERVER_KIT_BASE_HTTP_REQUEST_FOOTER(MyRequest);
|
28
|
-
};
|
29
|
-
|
30
|
-
class MyClient: public BaseHttpClient<MyRequest> {
|
31
|
-
public:
|
32
|
-
MyClient(void *server)
|
33
|
-
: BaseHttpClient<MyRequest>(server)
|
34
|
-
{
|
35
|
-
SERVER_KIT_BASE_HTTP_CLIENT_INIT();
|
36
|
-
}
|
37
|
-
|
38
|
-
DEFINE_SERVER_KIT_BASE_HTTP_CLIENT_FOOTER(MyClient, MyRequest);
|
39
|
-
};
|
40
|
-
|
41
|
-
class MyServer: public HttpServer<MyServer, MyClient> {
|
42
|
-
private:
|
43
|
-
typedef HttpServer<MyServer, MyClient> ParentClass;
|
44
|
-
|
45
|
-
void testRequest(MyClient *client, MyRequest *req) {
|
46
|
-
HeaderTable headers;
|
47
|
-
const unsigned int BUFSIZE = 128;
|
48
|
-
char *response = (char *) psg_pnalloc(req->pool, BUFSIZE);
|
49
|
-
char *pos = response;
|
50
|
-
const char *end = response + BUFSIZE;
|
51
|
-
const LString *value;
|
52
|
-
const LString::Part *part;
|
53
|
-
|
54
|
-
headers.insert(req->pool, "date", "Thu, 11 Sep 2014 12:54:09 GMT");
|
55
|
-
headers.insert(req->pool, "content-type", "text/plain");
|
56
|
-
|
57
|
-
pos = appendData(pos, end, "hello ");
|
58
|
-
part = req->path.start;
|
59
|
-
while (part != NULL) {
|
60
|
-
pos = appendData(pos, end, part->data, part->size);
|
61
|
-
part = part->next;
|
62
|
-
}
|
63
|
-
|
64
|
-
value = req->headers.lookup("foo");
|
65
|
-
if (value != NULL) {
|
66
|
-
pos = appendData(pos, end, "\nFoo: ");
|
67
|
-
part = value->start;
|
68
|
-
while (part != NULL) {
|
69
|
-
pos = appendData(pos, end, part->data, part->size);
|
70
|
-
part = part->next;
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
value = req->secureHeaders.lookup("!~Secure");
|
75
|
-
if (value != NULL) {
|
76
|
-
pos = appendData(pos, end, "\nSecure: ");
|
77
|
-
part = value->start;
|
78
|
-
while (part != NULL) {
|
79
|
-
pos = appendData(pos, end, part->data, part->size);
|
80
|
-
part = part->next;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
writeSimpleResponse(client, 200, &headers,
|
85
|
-
StaticString(response, pos - response));
|
86
|
-
endRequest(&client, &req);
|
87
|
-
}
|
88
|
-
|
89
|
-
void testBody(MyClient *client, MyRequest *req) {
|
90
|
-
if (!req->hasBody() && !req->upgraded()) {
|
91
|
-
writeSimpleResponse(client, 422, NULL, "Body required");
|
92
|
-
if (!req->ended()) {
|
93
|
-
endRequest(&client, &req);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
void testBodyStop(MyClient *client, MyRequest *req) {
|
99
|
-
if (!req->hasBody() && !req->upgraded()) {
|
100
|
-
writeSimpleResponse(client, 422, NULL, "Body required");
|
101
|
-
if (!req->ended()) {
|
102
|
-
endRequest(&client, &req);
|
103
|
-
}
|
104
|
-
} else {
|
105
|
-
refRequest(req, __FILE__, __LINE__);
|
106
|
-
req->bodyChannel.stop();
|
107
|
-
requestsWaitingToStartAcceptingBody.push_back(req);
|
108
|
-
// Continues in startAcceptingBody()
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
void startAcceptingBody(MyClient *client, MyRequest *req) {
|
113
|
-
req->bodyChannel.start();
|
114
|
-
// Continues on onRequestBody()
|
115
|
-
}
|
116
|
-
|
117
|
-
void testLargeResponse(MyClient *client, MyRequest *req) {
|
118
|
-
const LString *value = req->headers.lookup("size");
|
119
|
-
value = psg_lstr_make_contiguous(value, req->pool);
|
120
|
-
unsigned int size = stringToUint(StaticString(value->start->data, value->size));
|
121
|
-
char *body = (char *) psg_pnalloc(req->pool, size);
|
122
|
-
memset(body, 'x', size);
|
123
|
-
writeSimpleResponse(client, 200, NULL, StaticString(body, size));
|
124
|
-
if (!req->ended()) {
|
125
|
-
endRequest(&client, &req);
|
126
|
-
}
|
127
|
-
}
|
128
|
-
|
129
|
-
void testPath(MyClient *client, MyRequest *req) {
|
130
|
-
if (req->path.start->next == NULL) {
|
131
|
-
writeSimpleResponse(client, 200, NULL, "Contiguous: 1");
|
132
|
-
} else {
|
133
|
-
writeSimpleResponse(client, 500, NULL, "Contiguous: 0");
|
134
|
-
}
|
135
|
-
if (!req->ended()) {
|
136
|
-
endRequest(&client, &req);
|
137
|
-
}
|
138
|
-
}
|
139
|
-
|
140
|
-
protected:
|
141
|
-
virtual void onRequestBegin(MyClient *client, MyRequest *req) {
|
142
|
-
ParentClass::onRequestBegin(client, req);
|
143
|
-
|
144
|
-
if (psg_lstr_cmp(&req->path, "/body_test")) {
|
145
|
-
testBody(client, req);
|
146
|
-
} else if (psg_lstr_cmp(&req->path, "/body_stop_test")) {
|
147
|
-
testBodyStop(client, req);
|
148
|
-
} else if (psg_lstr_cmp(&req->path, "/large_response")) {
|
149
|
-
testLargeResponse(client, req);
|
150
|
-
} else if (psg_lstr_cmp(&req->path, "/path_test")) {
|
151
|
-
testPath(client, req);
|
152
|
-
} else {
|
153
|
-
testRequest(client, req);
|
154
|
-
}
|
155
|
-
}
|
156
|
-
|
157
|
-
virtual Channel::Result onRequestBody(MyClient *client, MyRequest *req,
|
158
|
-
const MemoryKit::mbuf &buffer, int errcode)
|
159
|
-
{
|
160
|
-
if (buffer.size() > 0) {
|
161
|
-
// Data
|
162
|
-
bodyBytesRead += buffer.size();
|
163
|
-
req->body.append(buffer.start, buffer.size());
|
164
|
-
} else if (errcode == 0) {
|
165
|
-
// EOF
|
166
|
-
req->body.insert(0, toString(req->body.size()) + " bytes: ");
|
167
|
-
writeSimpleResponse(client, 200, NULL, req->body);
|
168
|
-
endRequest(&client, &req);
|
169
|
-
} else {
|
170
|
-
// Error
|
171
|
-
req->body.insert(0, string("Request body error: ") +
|
172
|
-
getErrorDesc(errcode) + "\n" +
|
173
|
-
toString(req->body.size()) + " bytes: ");
|
174
|
-
writeSimpleResponse(client, 422, NULL, req->body);
|
175
|
-
if (!req->ended()) {
|
176
|
-
endRequest(&client, &req);
|
177
|
-
}
|
178
|
-
}
|
179
|
-
return Channel::Result(buffer.size(), false);
|
180
|
-
}
|
181
|
-
|
182
|
-
virtual void reinitializeRequest(MyClient *client, MyRequest *req) {
|
183
|
-
ParentClass::reinitializeRequest(client, req);
|
184
|
-
req->body.clear();
|
185
|
-
}
|
186
|
-
|
187
|
-
virtual void deinitializeRequest(MyClient *client, MyRequest *req) {
|
188
|
-
unsigned int i;
|
189
|
-
|
190
|
-
for (i = 0; i < requestsWaitingToStartAcceptingBody.size(); i++) {
|
191
|
-
if (requestsWaitingToStartAcceptingBody[i] == req) {
|
192
|
-
requestsWaitingToStartAcceptingBody.erase(
|
193
|
-
requestsWaitingToStartAcceptingBody.begin() + i);
|
194
|
-
unrefRequest(req, __FILE__, __LINE__);
|
195
|
-
break;
|
196
|
-
}
|
197
|
-
}
|
198
|
-
ParentClass::deinitializeRequest(client, req);
|
199
|
-
}
|
200
|
-
|
201
|
-
virtual bool supportsUpgrade(MyClient *client, MyRequest *req) {
|
202
|
-
return allowUpgrades;
|
203
|
-
}
|
204
|
-
|
205
|
-
public:
|
206
|
-
bool allowUpgrades;
|
207
|
-
|
208
|
-
vector<MyRequest *> requestsWaitingToStartAcceptingBody;
|
209
|
-
unsigned int bodyBytesRead;
|
210
|
-
|
211
|
-
MyServer(Context *context)
|
212
|
-
: ParentClass(context),
|
213
|
-
allowUpgrades(true),
|
214
|
-
bodyBytesRead(0)
|
215
|
-
{ }
|
216
|
-
|
217
|
-
void startAcceptingBody() {
|
218
|
-
MyRequest *req;
|
219
|
-
vector<MyRequest *> requestsWaitingToStartAcceptingBody;
|
220
|
-
|
221
|
-
requestsWaitingToStartAcceptingBody.swap(
|
222
|
-
this->requestsWaitingToStartAcceptingBody);
|
223
|
-
|
224
|
-
foreach (req, requestsWaitingToStartAcceptingBody) {
|
225
|
-
startAcceptingBody(static_cast<MyClient *>(req->client), req);
|
226
|
-
unrefRequest(req, __FILE__, __LINE__);
|
227
|
-
}
|
228
|
-
}
|
229
|
-
};
|
230
|
-
|
231
|
-
struct ServerKit_HttpServerTest {
|
232
|
-
typedef ClientRef<MyServer, MyClient> ClientRefType;
|
233
|
-
|
234
|
-
BackgroundEventLoop bg;
|
235
|
-
ServerKit::Context context;
|
236
|
-
boost::shared_ptr<MyServer> server;
|
237
|
-
int serverSocket;
|
238
|
-
FileDescriptor fd;
|
239
|
-
BufferedIO io;
|
240
|
-
|
241
|
-
ServerKit_HttpServerTest()
|
242
|
-
: bg(false, true),
|
243
|
-
context(bg.safe)
|
244
|
-
{
|
245
|
-
initializeLibeio();
|
246
|
-
setLogLevel(LVL_WARN);
|
247
|
-
serverSocket = createUnixServer("tmp.server");
|
248
|
-
server = boost::make_shared<MyServer>(&context);
|
249
|
-
server->listen(serverSocket);
|
250
|
-
}
|
251
|
-
|
252
|
-
~ServerKit_HttpServerTest() {
|
253
|
-
startLoop();
|
254
|
-
fd.close();
|
255
|
-
// Silence error disconnection messages during shutdown.
|
256
|
-
setLogLevel(LVL_CRIT);
|
257
|
-
bg.safe->runSync(boost::bind(&MyServer::shutdown, server.get(), true));
|
258
|
-
while (getServerState() != MyServer::FINISHED_SHUTDOWN) {
|
259
|
-
syscalls::usleep(10000);
|
260
|
-
}
|
261
|
-
safelyClose(serverSocket);
|
262
|
-
unlink("tmp.server");
|
263
|
-
setLogLevel(DEFAULT_LOG_LEVEL);
|
264
|
-
bg.stop();
|
265
|
-
shutdownLibeio();
|
266
|
-
}
|
267
|
-
|
268
|
-
void startLoop() {
|
269
|
-
if (!bg.isStarted()) {
|
270
|
-
bg.start();
|
271
|
-
}
|
272
|
-
}
|
273
|
-
|
274
|
-
FileDescriptor &connectToServer() {
|
275
|
-
startLoop();
|
276
|
-
fd = FileDescriptor(connectToUnixServer("tmp.server"));
|
277
|
-
io = BufferedIO(fd);
|
278
|
-
return fd;
|
279
|
-
}
|
280
|
-
|
281
|
-
void sendRequest(const StaticString &data) {
|
282
|
-
writeExact(fd, data);
|
283
|
-
}
|
284
|
-
|
285
|
-
void sendRequestAndWait(const StaticString &data) {
|
286
|
-
unsigned long long totalBytesConsumed = getTotalBytesConsumed();
|
287
|
-
sendRequest(data);
|
288
|
-
EVENTUALLY(5,
|
289
|
-
result = getTotalBytesConsumed() >= totalBytesConsumed + data.size();
|
290
|
-
);
|
291
|
-
ensure_equals(getTotalBytesConsumed(), totalBytesConsumed + data.size());
|
292
|
-
}
|
293
|
-
|
294
|
-
bool hasResponseData() {
|
295
|
-
unsigned long long timeout = 0;
|
296
|
-
return waitUntilReadable(fd, &timeout);
|
297
|
-
}
|
298
|
-
|
299
|
-
MyServer::State getServerState() {
|
300
|
-
MyServer::State result;
|
301
|
-
bg.safe->runSync(boost::bind(&ServerKit_HttpServerTest::_getServerState,
|
302
|
-
this, &result));
|
303
|
-
return result;
|
304
|
-
}
|
305
|
-
|
306
|
-
void _getServerState(MyServer::State *state) {
|
307
|
-
*state = server->serverState;
|
308
|
-
}
|
309
|
-
|
310
|
-
unsigned long long getTotalBytesConsumed() {
|
311
|
-
unsigned long long result;
|
312
|
-
bg.safe->runSync(boost::bind(&ServerKit_HttpServerTest::_getTotalBytesConsumed,
|
313
|
-
this, &result));
|
314
|
-
return result;
|
315
|
-
}
|
316
|
-
|
317
|
-
void _getTotalBytesConsumed(unsigned long long *result) {
|
318
|
-
*result = server->totalBytesConsumed;
|
319
|
-
}
|
320
|
-
|
321
|
-
unsigned long getTotalRequestsBegun() {
|
322
|
-
unsigned long result;
|
323
|
-
bg.safe->runSync(boost::bind(&ServerKit_HttpServerTest::_getTotalRequestsBegun,
|
324
|
-
this, &result));
|
325
|
-
return result;
|
326
|
-
}
|
327
|
-
|
328
|
-
void _getTotalRequestsBegun(unsigned long *result) {
|
329
|
-
*result = server->totalRequestsBegun;
|
330
|
-
}
|
331
|
-
|
332
|
-
unsigned int getBodyBytesRead() {
|
333
|
-
unsigned int result;
|
334
|
-
bg.safe->runSync(boost::bind(&ServerKit_HttpServerTest::_getBodyBytesRead,
|
335
|
-
this, &result));
|
336
|
-
return result;
|
337
|
-
}
|
338
|
-
|
339
|
-
void _getBodyBytesRead(unsigned int *result) {
|
340
|
-
*result = server->bodyBytesRead;
|
341
|
-
}
|
342
|
-
|
343
|
-
unsigned int getActiveClientCount() {
|
344
|
-
unsigned int result;
|
345
|
-
bg.safe->runSync(boost::bind(&ServerKit_HttpServerTest::_getActiveClientCount,
|
346
|
-
this, &result));
|
347
|
-
return result;
|
348
|
-
}
|
349
|
-
|
350
|
-
void _getActiveClientCount(unsigned int *result) {
|
351
|
-
*result = server->activeClientCount;
|
352
|
-
}
|
353
|
-
|
354
|
-
unsigned int getNumRequestsWaitingToStartAcceptingBody() {
|
355
|
-
unsigned int result;
|
356
|
-
bg.safe->runSync(boost::bind(
|
357
|
-
&ServerKit_HttpServerTest::_getNumRequestsWaitingToStartAcceptingBody,
|
358
|
-
this, &result));
|
359
|
-
return result;
|
360
|
-
}
|
361
|
-
|
362
|
-
void _getNumRequestsWaitingToStartAcceptingBody(unsigned int *result) {
|
363
|
-
*result = server->requestsWaitingToStartAcceptingBody.size();
|
364
|
-
}
|
365
|
-
|
366
|
-
void startAcceptingBody() {
|
367
|
-
bg.safe->runLater(boost::bind(&ServerKit_HttpServerTest::_startAcceptingBody,
|
368
|
-
this));
|
369
|
-
}
|
370
|
-
|
371
|
-
void _startAcceptingBody() {
|
372
|
-
server->startAcceptingBody();
|
373
|
-
}
|
374
|
-
|
375
|
-
void shutdownServer() {
|
376
|
-
bg.safe->runLater(boost::bind(&ServerKit_HttpServerTest::_shutdownServer,
|
377
|
-
this));
|
378
|
-
}
|
379
|
-
|
380
|
-
void _shutdownServer() {
|
381
|
-
server->shutdown();
|
382
|
-
}
|
383
|
-
|
384
|
-
string stripHeaders(const string &str) {
|
385
|
-
string::size_type pos = str.find("\r\n\r\n");
|
386
|
-
if (pos == string::npos) {
|
387
|
-
return str;
|
388
|
-
} else {
|
389
|
-
string result = str;
|
390
|
-
result.erase(0, pos + 4);
|
391
|
-
return result;
|
392
|
-
}
|
393
|
-
}
|
394
|
-
|
395
|
-
string readResponseHeader() {
|
396
|
-
string result;
|
397
|
-
string line;
|
398
|
-
do {
|
399
|
-
line = io.readLine();
|
400
|
-
if (line.empty()) {
|
401
|
-
break;
|
402
|
-
} else {
|
403
|
-
result.append(line);
|
404
|
-
if (line == "\r\n") {
|
405
|
-
break;
|
406
|
-
}
|
407
|
-
}
|
408
|
-
} while (true);
|
409
|
-
return result;
|
410
|
-
}
|
411
|
-
};
|
412
|
-
|
413
|
-
DEFINE_TEST_GROUP_WITH_LIMIT(ServerKit_HttpServerTest, 100);
|
414
|
-
|
415
|
-
|
416
|
-
/***** Valid HTTP header parsing *****/
|
417
|
-
|
418
|
-
TEST_METHOD(1) {
|
419
|
-
set_test_name("A complete header in one part");
|
420
|
-
|
421
|
-
connectToServer();
|
422
|
-
sendRequest(
|
423
|
-
"GET / HTTP/1.1\r\n"
|
424
|
-
"Connection: close\r\n"
|
425
|
-
"Host: foo\r\n\r\n");
|
426
|
-
string response = readAll(fd);
|
427
|
-
ensure_equals(response,
|
428
|
-
"HTTP/1.1 200 OK\r\n"
|
429
|
-
"Status: 200 OK\r\n"
|
430
|
-
"Content-Type: text/plain\r\n"
|
431
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
432
|
-
"Connection: close\r\n"
|
433
|
-
"Content-Length: 7\r\n\r\n"
|
434
|
-
"hello /");
|
435
|
-
}
|
436
|
-
|
437
|
-
TEST_METHOD(2) {
|
438
|
-
set_test_name("A complete header in multiple random-sized parts");
|
439
|
-
|
440
|
-
connectToServer();
|
441
|
-
sendRequestAndWait(
|
442
|
-
"GET / HTTP/1.1\r\n"
|
443
|
-
"Connect");
|
444
|
-
ensure(!hasResponseData());
|
445
|
-
|
446
|
-
sendRequestAndWait(
|
447
|
-
"ion: close\r\n"
|
448
|
-
"Host: fo");
|
449
|
-
ensure(!hasResponseData());
|
450
|
-
|
451
|
-
sendRequest(
|
452
|
-
"o\r\n\r\n");
|
453
|
-
|
454
|
-
string response = readAll(fd);
|
455
|
-
ensure_equals(response,
|
456
|
-
"HTTP/1.1 200 OK\r\n"
|
457
|
-
"Status: 200 OK\r\n"
|
458
|
-
"Content-Type: text/plain\r\n"
|
459
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
460
|
-
"Connection: close\r\n"
|
461
|
-
"Content-Length: 7\r\n\r\n"
|
462
|
-
"hello /");
|
463
|
-
}
|
464
|
-
|
465
|
-
TEST_METHOD(3) {
|
466
|
-
set_test_name("A complete header in multiple complete lines");
|
467
|
-
|
468
|
-
connectToServer();
|
469
|
-
|
470
|
-
sendRequestAndWait("GET / HTTP/1.1\r\n");
|
471
|
-
ensure(!hasResponseData());
|
472
|
-
|
473
|
-
sendRequestAndWait("Connection: close\r\n");
|
474
|
-
ensure(!hasResponseData());
|
475
|
-
|
476
|
-
sendRequestAndWait("Host: foo\r\n");
|
477
|
-
ensure(!hasResponseData());
|
478
|
-
|
479
|
-
sendRequest("\r\n");
|
480
|
-
|
481
|
-
string response = readAll(fd);
|
482
|
-
ensure_equals(response,
|
483
|
-
"HTTP/1.1 200 OK\r\n"
|
484
|
-
"Status: 200 OK\r\n"
|
485
|
-
"Content-Type: text/plain\r\n"
|
486
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
487
|
-
"Connection: close\r\n"
|
488
|
-
"Content-Length: 7\r\n\r\n"
|
489
|
-
"hello /");
|
490
|
-
}
|
491
|
-
|
492
|
-
TEST_METHOD(4) {
|
493
|
-
set_test_name("The request path is stored in req->path, "
|
494
|
-
"and headers are stored in req->headers");
|
495
|
-
|
496
|
-
connectToServer();
|
497
|
-
|
498
|
-
sendRequestAndWait("GET /");
|
499
|
-
ensure(!hasResponseData());
|
500
|
-
sendRequestAndWait("jo");
|
501
|
-
ensure(!hasResponseData());
|
502
|
-
sendRequestAndWait("o HTTP/1.1\r\n");
|
503
|
-
ensure(!hasResponseData());
|
504
|
-
|
505
|
-
sendRequestAndWait("Connection: close\r\n");
|
506
|
-
ensure(!hasResponseData());
|
507
|
-
|
508
|
-
sendRequestAndWait("Host: foo\r\n");
|
509
|
-
ensure(!hasResponseData());
|
510
|
-
|
511
|
-
sendRequestAndWait("F");
|
512
|
-
ensure(!hasResponseData());
|
513
|
-
sendRequestAndWait("oo: ");
|
514
|
-
ensure(!hasResponseData());
|
515
|
-
sendRequestAndWait("b");
|
516
|
-
ensure(!hasResponseData());
|
517
|
-
sendRequestAndWait("ar\r\n");
|
518
|
-
ensure(!hasResponseData());
|
519
|
-
|
520
|
-
sendRequest("\r\n");
|
521
|
-
|
522
|
-
string response = readAll(fd);
|
523
|
-
ensure_equals(response,
|
524
|
-
"HTTP/1.1 200 OK\r\n"
|
525
|
-
"Status: 200 OK\r\n"
|
526
|
-
"Content-Type: text/plain\r\n"
|
527
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
528
|
-
"Connection: close\r\n"
|
529
|
-
"Content-Length: 19\r\n\r\n"
|
530
|
-
"hello /joo\n"
|
531
|
-
"Foo: bar");
|
532
|
-
}
|
533
|
-
|
534
|
-
TEST_METHOD(5) {
|
535
|
-
set_test_name("It ensures that req->path is contiguous");
|
536
|
-
|
537
|
-
connectToServer();
|
538
|
-
sendRequestAndWait("GET /p");
|
539
|
-
sendRequestAndWait(
|
540
|
-
"ath_test HTTP/1.1\r\n"
|
541
|
-
"Connection: close\r\n\r\n");
|
542
|
-
|
543
|
-
string response = readAll(fd);
|
544
|
-
ensure(containsSubstring(response, "Contiguous: 1"));
|
545
|
-
}
|
546
|
-
|
547
|
-
|
548
|
-
/***** Invalid HTTP header parsing *****/
|
549
|
-
|
550
|
-
TEST_METHOD(7) {
|
551
|
-
set_test_name("Incomplete header, without closing connection");
|
552
|
-
|
553
|
-
connectToServer();
|
554
|
-
sendRequest("GET / HTT");
|
555
|
-
SHOULD_NEVER_HAPPEN(100,
|
556
|
-
result = hasResponseData();
|
557
|
-
);
|
558
|
-
}
|
559
|
-
|
560
|
-
TEST_METHOD(8) {
|
561
|
-
set_test_name("Incomplete header, half-closing connection");
|
562
|
-
|
563
|
-
connectToServer();
|
564
|
-
sendRequestAndWait("GET / HTT");
|
565
|
-
syscalls::shutdown(fd, SHUT_WR);
|
566
|
-
string response = readAll(fd);
|
567
|
-
ensure_equals(response, "");
|
568
|
-
}
|
569
|
-
|
570
|
-
TEST_METHOD(9) {
|
571
|
-
set_test_name("Invalid header data");
|
572
|
-
|
573
|
-
connectToServer();
|
574
|
-
sendRequest("whatever");
|
575
|
-
string response = readAll(fd);
|
576
|
-
ensure(containsSubstring(response,
|
577
|
-
"HTTP/1.0 400 Bad Request\r\n"
|
578
|
-
"Status: 400 Bad Request\r\n"
|
579
|
-
"Content-Type: text/html; charset=UTF-8\r\n"));
|
580
|
-
ensure(containsSubstring(response,
|
581
|
-
"Connection: close\r\n"
|
582
|
-
"Content-Length: 19\r\n"
|
583
|
-
"cache-control: no-cache, no-store, must-revalidate\r\n\r\n"
|
584
|
-
"invalid HTTP method"));
|
585
|
-
}
|
586
|
-
|
587
|
-
|
588
|
-
/***** Invalid request *****/
|
589
|
-
|
590
|
-
TEST_METHOD(14) {
|
591
|
-
set_test_name("HTTP > 1.1");
|
592
|
-
|
593
|
-
connectToServer();
|
594
|
-
sendRequest(
|
595
|
-
"GET / HTTP/1.2\r\n"
|
596
|
-
"Connection: close\r\n"
|
597
|
-
"Host: foo\r\n\r\n");
|
598
|
-
string response = readAll(fd);
|
599
|
-
ensure(containsSubstring(response,
|
600
|
-
"HTTP/1.1 505 HTTP Version Not Supported\r\n"
|
601
|
-
"Status: 505 HTTP Version Not Supported\r\n"
|
602
|
-
"Content-Type: text/html; charset=UTF-8\r\n"));
|
603
|
-
ensure(containsSubstring(response,
|
604
|
-
"Connection: close\r\n"
|
605
|
-
"Content-Length: 27\r\n"
|
606
|
-
"cache-control: no-cache, no-store, must-revalidate\r\n"
|
607
|
-
"\r\n"
|
608
|
-
"HTTP version not supported"));
|
609
|
-
}
|
610
|
-
|
611
|
-
TEST_METHOD(15) {
|
612
|
-
set_test_name("Transfer-Encoding and Content-Length given simultaneously");
|
613
|
-
|
614
|
-
connectToServer();
|
615
|
-
sendRequest(
|
616
|
-
"GET / HTTP/1.1\r\n"
|
617
|
-
"Connection: close\r\n"
|
618
|
-
"Content-Length: 3\r\n"
|
619
|
-
"Transfer-Encoding: chunked\r\n\r\n");
|
620
|
-
string response = readAll(fd);
|
621
|
-
ensure(containsSubstring(response,
|
622
|
-
"HTTP/1.1 400 Bad Request\r\n"
|
623
|
-
"Status: 400 Bad Request\r\n"
|
624
|
-
"Content-Type: text/html; charset=UTF-8\r\n"));
|
625
|
-
ensure(containsSubstring(response,
|
626
|
-
"Connection: close\r\n"
|
627
|
-
"Content-Length: 79\r\n"
|
628
|
-
"cache-control: no-cache, no-store, must-revalidate\r\n"
|
629
|
-
"\r\n"
|
630
|
-
"Bad request (request may not contain both Content-Length and Transfer-Encoding)"));
|
631
|
-
}
|
632
|
-
|
633
|
-
|
634
|
-
/***** Fixed body handling *****/
|
635
|
-
|
636
|
-
TEST_METHOD(20) {
|
637
|
-
set_test_name("An empty body is treated the same as no body");
|
638
|
-
|
639
|
-
connectToServer();
|
640
|
-
sendRequest(
|
641
|
-
"GET /body_test HTTP/1.1\r\n"
|
642
|
-
"Connection: close\r\n"
|
643
|
-
"Content-Length: 0\r\n\r\n");
|
644
|
-
string response = readAll(fd);
|
645
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 422 Unprocessable Entity\r\n"));
|
646
|
-
ensure("(2)", containsSubstring(response, "Body required"));
|
647
|
-
}
|
648
|
-
|
649
|
-
TEST_METHOD(21) {
|
650
|
-
set_test_name("Non-empty body in one part");
|
651
|
-
|
652
|
-
connectToServer();
|
653
|
-
sendRequest(
|
654
|
-
"GET /body_test HTTP/1.1\r\n"
|
655
|
-
"Connection: close\r\n"
|
656
|
-
"Content-Length: 2\r\n\r\n"
|
657
|
-
"ok");
|
658
|
-
string response = readAll(fd);
|
659
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
660
|
-
ensure("(2)", containsSubstring(response, "2 bytes: ok"));
|
661
|
-
}
|
662
|
-
|
663
|
-
TEST_METHOD(22) {
|
664
|
-
set_test_name("Non-empty body in multiple parts");
|
665
|
-
|
666
|
-
connectToServer();
|
667
|
-
sendRequestAndWait(
|
668
|
-
"GET /body_test HTTP/1.1\r\n"
|
669
|
-
"Connection: close\r\n"
|
670
|
-
"Content-Length: 7\r\n\r\n"
|
671
|
-
"hm");
|
672
|
-
ensure(!hasResponseData());
|
673
|
-
sendRequestAndWait("ok");
|
674
|
-
ensure(!hasResponseData());
|
675
|
-
sendRequest("!!!");
|
676
|
-
|
677
|
-
string response = readAll(fd);
|
678
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
679
|
-
ensure("(2)", containsSubstring(response, "7 bytes: hmok!!!"));
|
680
|
-
}
|
681
|
-
|
682
|
-
TEST_METHOD(23) {
|
683
|
-
set_test_name("req->bodyChannel is stopped before request body data is received");
|
684
|
-
|
685
|
-
connectToServer();
|
686
|
-
sendRequest(
|
687
|
-
"GET /body_stop_test HTTP/1.1\r\n"
|
688
|
-
"Connection: close\r\n"
|
689
|
-
"Content-Length: 7\r\n\r\n"
|
690
|
-
"hmok!!!");
|
691
|
-
EVENTUALLY(5,
|
692
|
-
result = getNumRequestsWaitingToStartAcceptingBody() == 1;
|
693
|
-
);
|
694
|
-
SHOULD_NEVER_HAPPEN(100,
|
695
|
-
result = hasResponseData();
|
696
|
-
);
|
697
|
-
|
698
|
-
startAcceptingBody();
|
699
|
-
string response = readAll(fd);
|
700
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
701
|
-
ensure("(2)", containsSubstring(response, "7 bytes: hmok!!!"));
|
702
|
-
}
|
703
|
-
|
704
|
-
TEST_METHOD(24) {
|
705
|
-
set_test_name("req->bodyChannel is stopped before unexpected request body EOF is encountered");
|
706
|
-
|
707
|
-
connectToServer();
|
708
|
-
sendRequest(
|
709
|
-
"GET /body_stop_test HTTP/1.1\r\n"
|
710
|
-
"Connection: close\r\n"
|
711
|
-
"Content-Length: 3\r\n\r\n");
|
712
|
-
syscalls::shutdown(fd, SHUT_WR);
|
713
|
-
EVENTUALLY(5,
|
714
|
-
result = getNumRequestsWaitingToStartAcceptingBody() == 1;
|
715
|
-
);
|
716
|
-
SHOULD_NEVER_HAPPEN(100,
|
717
|
-
result = hasResponseData();
|
718
|
-
);
|
719
|
-
|
720
|
-
startAcceptingBody();
|
721
|
-
string response = readAll(fd);
|
722
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 422 Unprocessable Entity\r\n"));
|
723
|
-
ensure("(2)", containsSubstring(response, "Request body error: Unexpected end-of-stream"));
|
724
|
-
}
|
725
|
-
|
726
|
-
TEST_METHOD(25) {
|
727
|
-
set_test_name("Premature body termination");
|
728
|
-
|
729
|
-
connectToServer();
|
730
|
-
sendRequestAndWait(
|
731
|
-
"GET /body_test HTTP/1.1\r\n"
|
732
|
-
"Connection: close\r\n"
|
733
|
-
"Content-Length: 7\r\n\r\n"
|
734
|
-
"hm");
|
735
|
-
ensure(!hasResponseData());
|
736
|
-
sendRequestAndWait("ok");
|
737
|
-
ensure(!hasResponseData());
|
738
|
-
sendRequestAndWait("!");
|
739
|
-
syscalls::shutdown(fd, SHUT_WR);
|
740
|
-
|
741
|
-
string response = readAll(fd);
|
742
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 422 Unprocessable Entity\r\n"));
|
743
|
-
ensure("(2)", containsSubstring(response,
|
744
|
-
"Request body error: Unexpected end-of-stream\n"
|
745
|
-
"5 bytes: hmok!"));
|
746
|
-
}
|
747
|
-
|
748
|
-
TEST_METHOD(26) {
|
749
|
-
set_test_name("Trailing data after body");
|
750
|
-
|
751
|
-
connectToServer();
|
752
|
-
sendRequest(
|
753
|
-
"GET /body_test HTTP/1.1\r\n"
|
754
|
-
"Connection: close\r\n"
|
755
|
-
"Content-Length: 2\r\n\r\n"
|
756
|
-
"hmok");
|
757
|
-
string response = readAll(fd);
|
758
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
759
|
-
ensure("(2)", containsSubstring(response, "2 bytes: hm"));
|
760
|
-
ensure("(3)", !containsSubstring(response, "ok"));
|
761
|
-
EVENTUALLY(5,
|
762
|
-
result = getTotalBytesConsumed() == strlen(
|
763
|
-
"GET /body_test HTTP/1.1\r\n"
|
764
|
-
"Connection: close\r\n"
|
765
|
-
"Content-Length: 2\r\n\r\n"
|
766
|
-
"hm");
|
767
|
-
);
|
768
|
-
}
|
769
|
-
|
770
|
-
|
771
|
-
/***** Chunked body handling *****/
|
772
|
-
|
773
|
-
TEST_METHOD(30) {
|
774
|
-
set_test_name("Empty body");
|
775
|
-
|
776
|
-
connectToServer();
|
777
|
-
sendRequest(
|
778
|
-
"GET /body_test HTTP/1.1\r\n"
|
779
|
-
"Connection: close\r\n"
|
780
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
781
|
-
"0\r\n\r\n");
|
782
|
-
string response = readAll(fd);
|
783
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
784
|
-
ensure("(2)", containsSubstring(response, "0 bytes: "));
|
785
|
-
}
|
786
|
-
|
787
|
-
TEST_METHOD(31) {
|
788
|
-
set_test_name("Non-empty body in one part");
|
789
|
-
|
790
|
-
connectToServer();
|
791
|
-
sendRequest(
|
792
|
-
"GET /body_test HTTP/1.1\r\n"
|
793
|
-
"Connection: close\r\n"
|
794
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
795
|
-
"2\r\n"
|
796
|
-
"ok\r\n"
|
797
|
-
"0\r\n\r\n");
|
798
|
-
string response = readAll(fd);
|
799
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
800
|
-
ensure("(2)", containsSubstring(response, "2 bytes: ok"));
|
801
|
-
}
|
802
|
-
|
803
|
-
TEST_METHOD(32) {
|
804
|
-
set_test_name("Non-empty body in multiple parts");
|
805
|
-
|
806
|
-
connectToServer();
|
807
|
-
sendRequestAndWait(
|
808
|
-
"GET /body_test HTTP/1.1\r\n"
|
809
|
-
"Connection: close\r\n"
|
810
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
811
|
-
"2\r\n"
|
812
|
-
"h");
|
813
|
-
ensure(!hasResponseData());
|
814
|
-
sendRequestAndWait("m\r");
|
815
|
-
ensure(!hasResponseData());
|
816
|
-
sendRequestAndWait("\n2\r");
|
817
|
-
ensure(!hasResponseData());
|
818
|
-
sendRequestAndWait("\no");
|
819
|
-
ensure(!hasResponseData());
|
820
|
-
sendRequestAndWait("k");
|
821
|
-
ensure(!hasResponseData());
|
822
|
-
sendRequestAndWait("\r\n3\r\n");
|
823
|
-
ensure(!hasResponseData());
|
824
|
-
sendRequestAndWait("!");
|
825
|
-
ensure(!hasResponseData());
|
826
|
-
sendRequestAndWait("!!\r\n0");
|
827
|
-
ensure(!hasResponseData());
|
828
|
-
sendRequest("\r\n\r\n");
|
829
|
-
|
830
|
-
string response = readAll(fd);
|
831
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
832
|
-
ensure("(2)", containsSubstring(response, "7 bytes: hmok!!!"));
|
833
|
-
}
|
834
|
-
|
835
|
-
TEST_METHOD(33) {
|
836
|
-
set_test_name("Premature body termination");
|
837
|
-
|
838
|
-
connectToServer();
|
839
|
-
sendRequestAndWait(
|
840
|
-
"GET /body_test HTTP/1.1\r\n"
|
841
|
-
"Connection: close\r\n"
|
842
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
843
|
-
"7\r\nhmok!");
|
844
|
-
ensure(!hasResponseData());
|
845
|
-
syscalls::shutdown(fd, SHUT_WR);
|
846
|
-
|
847
|
-
string response = readAll(fd);
|
848
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 422 Unprocessable Entity\r\n"));
|
849
|
-
ensure("(2)", containsSubstring(response,
|
850
|
-
"Request body error: Unexpected end-of-stream\n"
|
851
|
-
"5 bytes: hmok!"));
|
852
|
-
}
|
853
|
-
|
854
|
-
TEST_METHOD(34) {
|
855
|
-
set_test_name("req->bodyChannel is stopped before request body data is received");
|
856
|
-
|
857
|
-
connectToServer();
|
858
|
-
sendRequest(
|
859
|
-
"GET /body_stop_test HTTP/1.1\r\n"
|
860
|
-
"Connection: close\r\n"
|
861
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
862
|
-
"3\r\n"
|
863
|
-
"abc\r\n"
|
864
|
-
"0\r\n"
|
865
|
-
"\r\n");
|
866
|
-
EVENTUALLY(5,
|
867
|
-
result = getNumRequestsWaitingToStartAcceptingBody() == 1;
|
868
|
-
);
|
869
|
-
SHOULD_NEVER_HAPPEN(100,
|
870
|
-
result = hasResponseData();
|
871
|
-
);
|
872
|
-
|
873
|
-
startAcceptingBody();
|
874
|
-
string response = readAll(fd);
|
875
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
876
|
-
ensure("(2)", containsSubstring(response, "3 bytes: abc"));
|
877
|
-
}
|
878
|
-
|
879
|
-
TEST_METHOD(35) {
|
880
|
-
set_test_name("Trailing data after body");
|
881
|
-
|
882
|
-
connectToServer();
|
883
|
-
sendRequest(
|
884
|
-
"GET /body_test HTTP/1.1\r\n"
|
885
|
-
"Connection: close\r\n"
|
886
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
887
|
-
"2\r\n"
|
888
|
-
"hm\r\n"
|
889
|
-
"0\r\n\r\n"
|
890
|
-
"ok");
|
891
|
-
string response = readAll(fd);
|
892
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
893
|
-
ensure("(2)", containsSubstring(response, "2 bytes: hm"));
|
894
|
-
ensure("(3)", !containsSubstring(response, "ok"));
|
895
|
-
EVENTUALLY(5,
|
896
|
-
result = getTotalBytesConsumed() == strlen(
|
897
|
-
"GET /body_test HTTP/1.1\r\n"
|
898
|
-
"Connection: close\r\n"
|
899
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
900
|
-
"2\r\n"
|
901
|
-
"hm\r\n"
|
902
|
-
"0\r\n\r\n");
|
903
|
-
);
|
904
|
-
}
|
905
|
-
|
906
|
-
TEST_METHOD(36) {
|
907
|
-
set_test_name("Unterminated final chunk");
|
908
|
-
|
909
|
-
connectToServer();
|
910
|
-
sendRequestAndWait(
|
911
|
-
"GET /body_test HTTP/1.1\r\n"
|
912
|
-
"Connection: close\r\n"
|
913
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
914
|
-
"7\r\nhmok!!!\r\n0\r\n\r");
|
915
|
-
ensure(!hasResponseData());
|
916
|
-
syscalls::shutdown(fd, SHUT_WR);
|
917
|
-
|
918
|
-
string response = readAll(fd);
|
919
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 422 Unprocessable Entity\r\n"));
|
920
|
-
ensure("(2)", containsSubstring(response,
|
921
|
-
"Request body error: Unexpected end-of-stream\n"
|
922
|
-
"7 bytes: hmok!!!"));
|
923
|
-
}
|
924
|
-
|
925
|
-
TEST_METHOD(37) {
|
926
|
-
set_test_name("Invalid chunk header");
|
927
|
-
|
928
|
-
connectToServer();
|
929
|
-
sendRequest(
|
930
|
-
"GET /body_test HTTP/1.1\r\n"
|
931
|
-
"Connection: close\r\n"
|
932
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
933
|
-
"!");
|
934
|
-
string response = readAll(fd);
|
935
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 422 Unprocessable Entity\r\n"));
|
936
|
-
ensure("(2)", containsSubstring(response, "0 bytes: "));
|
937
|
-
ensure("(3)", !containsSubstring(response, "!"));
|
938
|
-
}
|
939
|
-
|
940
|
-
TEST_METHOD(38) {
|
941
|
-
set_test_name("Invalid chunk footer");
|
942
|
-
|
943
|
-
connectToServer();
|
944
|
-
sendRequest(
|
945
|
-
"GET /body_test HTTP/1.1\r\n"
|
946
|
-
"Connection: close\r\n"
|
947
|
-
"Transfer-Encoding: chunked\r\n\r\n"
|
948
|
-
"2\r\nok!");
|
949
|
-
string response = readAll(fd);
|
950
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 422 Unprocessable Entity\r\n"));
|
951
|
-
ensure("(2)", containsSubstring(response, "2 bytes: ok"));
|
952
|
-
ensure("(3)", !containsSubstring(response, "!"));
|
953
|
-
}
|
954
|
-
|
955
|
-
|
956
|
-
/***** Upgrade handling *****/
|
957
|
-
|
958
|
-
TEST_METHOD(40) {
|
959
|
-
set_test_name("Empty body");
|
960
|
-
|
961
|
-
connectToServer();
|
962
|
-
sendRequest(
|
963
|
-
"GET /body_test HTTP/1.1\r\n"
|
964
|
-
"Connection: upgrade\r\n"
|
965
|
-
"Upgrade: raw\r\n\r\n");
|
966
|
-
syscalls::shutdown(fd, SHUT_WR);
|
967
|
-
string response = readAll(fd);
|
968
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
969
|
-
ensure("(2)", containsSubstring(response, "0 bytes: "));
|
970
|
-
}
|
971
|
-
|
972
|
-
TEST_METHOD(41) {
|
973
|
-
set_test_name("Non-empty data in one part");
|
974
|
-
|
975
|
-
connectToServer();
|
976
|
-
sendRequest(
|
977
|
-
"GET /body_test HTTP/1.1\r\n"
|
978
|
-
"Connection: upgrade\r\n"
|
979
|
-
"Upgrade: raw\r\n\r\n"
|
980
|
-
"ok");
|
981
|
-
syscalls::shutdown(fd, SHUT_WR);
|
982
|
-
string response = readAll(fd);
|
983
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
984
|
-
ensure("(2)", containsSubstring(response, "2 bytes: ok"));
|
985
|
-
}
|
986
|
-
|
987
|
-
TEST_METHOD(42) {
|
988
|
-
set_test_name("Non-empty body in multiple parts");
|
989
|
-
|
990
|
-
connectToServer();
|
991
|
-
sendRequestAndWait(
|
992
|
-
"GET /body_test HTTP/1.1\r\n"
|
993
|
-
"Connection: upgrade\r\n"
|
994
|
-
"Upgrade: raw\r\n\r\n"
|
995
|
-
"hm");
|
996
|
-
ensure(!hasResponseData());
|
997
|
-
sendRequestAndWait("ok");
|
998
|
-
ensure(!hasResponseData());
|
999
|
-
sendRequest("!!!");
|
1000
|
-
syscalls::shutdown(fd, SHUT_WR);
|
1001
|
-
|
1002
|
-
string response = readAll(fd);
|
1003
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
1004
|
-
ensure("(2)", containsSubstring(response, "7 bytes: hmok!!!"));
|
1005
|
-
}
|
1006
|
-
|
1007
|
-
TEST_METHOD(43) {
|
1008
|
-
set_test_name("req->bodyChannel is stopped before request body data is received");
|
1009
|
-
|
1010
|
-
connectToServer();
|
1011
|
-
sendRequest(
|
1012
|
-
"GET /body_stop_test HTTP/1.1\r\n"
|
1013
|
-
"Connection: upgrade\r\n"
|
1014
|
-
"Upgrade: raw\r\n\r\n"
|
1015
|
-
"hmok!!!");
|
1016
|
-
syscalls::shutdown(fd, SHUT_WR);
|
1017
|
-
EVENTUALLY(5,
|
1018
|
-
result = getNumRequestsWaitingToStartAcceptingBody() == 1;
|
1019
|
-
);
|
1020
|
-
SHOULD_NEVER_HAPPEN(100,
|
1021
|
-
result = hasResponseData();
|
1022
|
-
);
|
1023
|
-
|
1024
|
-
startAcceptingBody();
|
1025
|
-
string response = readAll(fd);
|
1026
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
1027
|
-
ensure("(2)", containsSubstring(response, "7 bytes: hmok!!!"));
|
1028
|
-
}
|
1029
|
-
|
1030
|
-
TEST_METHOD(44) {
|
1031
|
-
set_test_name("req->bodyChannel is stopped before request body EOF is encountered");
|
1032
|
-
|
1033
|
-
connectToServer();
|
1034
|
-
sendRequest(
|
1035
|
-
"GET /body_stop_test HTTP/1.1\r\n"
|
1036
|
-
"Connection: upgrade\r\n"
|
1037
|
-
"Upgrade: raw\r\n\r\n");
|
1038
|
-
syscalls::shutdown(fd, SHUT_WR);
|
1039
|
-
EVENTUALLY(5,
|
1040
|
-
result = getNumRequestsWaitingToStartAcceptingBody() == 1;
|
1041
|
-
);
|
1042
|
-
SHOULD_NEVER_HAPPEN(100,
|
1043
|
-
result = hasResponseData();
|
1044
|
-
);
|
1045
|
-
|
1046
|
-
startAcceptingBody();
|
1047
|
-
string response = readAll(fd);
|
1048
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
1049
|
-
ensure("(2)", containsSubstring(response, "0 bytes: "));
|
1050
|
-
}
|
1051
|
-
|
1052
|
-
TEST_METHOD(45) {
|
1053
|
-
set_test_name("It rejects the upgrade if supportsUpgrade() returns false");
|
1054
|
-
|
1055
|
-
server->allowUpgrades = false;
|
1056
|
-
connectToServer();
|
1057
|
-
sendRequest(
|
1058
|
-
"GET /body_test HTTP/1.1\r\n"
|
1059
|
-
"Connection: upgrade\r\n"
|
1060
|
-
"Upgrade: raw\r\n\r\n");
|
1061
|
-
string response = readAll(fd);
|
1062
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 422 Unprocessable Entity\r\n"));
|
1063
|
-
ensure("(2)", containsSubstring(response, "Connection upgrading not allowed for this request"));
|
1064
|
-
}
|
1065
|
-
|
1066
|
-
TEST_METHOD(46) {
|
1067
|
-
set_test_name("It rejects the upgrade if the request contains a request body");
|
1068
|
-
|
1069
|
-
connectToServer();
|
1070
|
-
sendRequest(
|
1071
|
-
"GET /body_test HTTP/1.1\r\n"
|
1072
|
-
"Connection: upgrade\r\n"
|
1073
|
-
"Upgrade: raw\r\n"
|
1074
|
-
"Content-Length: 3\r\n\r\n");
|
1075
|
-
string response = readAll(fd);
|
1076
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 400 Bad Request\r\n"));
|
1077
|
-
ensure("(2)", containsSubstring(response,
|
1078
|
-
"Connection upgrading is only allowed for requests without request body"));
|
1079
|
-
}
|
1080
|
-
|
1081
|
-
TEST_METHOD(47) {
|
1082
|
-
set_test_name("It rejects the upgrade if the request is HEAD");
|
1083
|
-
|
1084
|
-
connectToServer();
|
1085
|
-
sendRequest(
|
1086
|
-
"HEAD /body_test HTTP/1.1\r\n"
|
1087
|
-
"Connection: upgrade\r\n"
|
1088
|
-
"Upgrade: raw\r\n\r\n");
|
1089
|
-
string response = readAll(fd);
|
1090
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 400 Bad Request\r\n"));
|
1091
|
-
}
|
1092
|
-
|
1093
|
-
|
1094
|
-
/***** Secure headers handling *****/
|
1095
|
-
|
1096
|
-
TEST_METHOD(50) {
|
1097
|
-
set_test_name("It stores secure headers in req->secureHeaders");
|
1098
|
-
|
1099
|
-
connectToServer();
|
1100
|
-
sendRequest(
|
1101
|
-
"GET /joo HTTP/1.1\r\n"
|
1102
|
-
"Connection: close\r\n"
|
1103
|
-
"Host: foo\r\n"
|
1104
|
-
"!~: x\r\n"
|
1105
|
-
"!~Secure: secret\r\n"
|
1106
|
-
"\r\n");
|
1107
|
-
string response = readAll(fd);
|
1108
|
-
ensure_equals(response,
|
1109
|
-
"HTTP/1.1 200 OK\r\n"
|
1110
|
-
"Status: 200 OK\r\n"
|
1111
|
-
"Content-Type: text/plain\r\n"
|
1112
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
1113
|
-
"Connection: close\r\n"
|
1114
|
-
"Content-Length: 25\r\n\r\n"
|
1115
|
-
"hello /joo\n"
|
1116
|
-
"Secure: secret");
|
1117
|
-
}
|
1118
|
-
|
1119
|
-
TEST_METHOD(51) {
|
1120
|
-
set_test_name("It rejects normal headers while in secure mode");
|
1121
|
-
|
1122
|
-
connectToServer();
|
1123
|
-
sendRequest(
|
1124
|
-
"GET / HTTP/1.1\r\n"
|
1125
|
-
"Connection: close\r\n"
|
1126
|
-
"Host: foo\r\n"
|
1127
|
-
"!~: x\r\n"
|
1128
|
-
"!~Secure: secret\r\n"
|
1129
|
-
"Foo: bar\r\n"
|
1130
|
-
"\r\n");
|
1131
|
-
string response = readAll(fd);
|
1132
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.0 400 Bad Request\r\n"));
|
1133
|
-
ensure("(2)", containsSubstring(response,
|
1134
|
-
"A normal header was encountered after the security password header"));
|
1135
|
-
}
|
1136
|
-
|
1137
|
-
TEST_METHOD(52) {
|
1138
|
-
set_test_name("It rejects secure headers while in normal mode");
|
1139
|
-
|
1140
|
-
connectToServer();
|
1141
|
-
sendRequest(
|
1142
|
-
"GET / HTTP/1.1\r\n"
|
1143
|
-
"Connection: close\r\n"
|
1144
|
-
"Host: foo\r\n"
|
1145
|
-
"!~Secure: secret\r\n"
|
1146
|
-
"\r\n");
|
1147
|
-
string response = readAll(fd);
|
1148
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.0 400 Bad Request\r\n"));
|
1149
|
-
ensure("(2)", containsSubstring(response,
|
1150
|
-
"A secure header was provided, but no security password was provided"));
|
1151
|
-
}
|
1152
|
-
|
1153
|
-
TEST_METHOD(53) {
|
1154
|
-
set_test_name("If no secure mode password is given in the context, "
|
1155
|
-
"switching to secure mode is always possible");
|
1156
|
-
|
1157
|
-
connectToServer();
|
1158
|
-
sendRequest(
|
1159
|
-
"GET / HTTP/1.1\r\n"
|
1160
|
-
"Connection: close\r\n"
|
1161
|
-
"Host: foo\r\n"
|
1162
|
-
"!~: anything\r\n"
|
1163
|
-
"\r\n");
|
1164
|
-
string response = readAll(fd);
|
1165
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
1166
|
-
}
|
1167
|
-
|
1168
|
-
TEST_METHOD(54) {
|
1169
|
-
set_test_name("If a secure mode password is given in the context, "
|
1170
|
-
"it rejects requests that specify the wrong secure mode password");
|
1171
|
-
|
1172
|
-
context.secureModePassword = "secret";
|
1173
|
-
connectToServer();
|
1174
|
-
sendRequest(
|
1175
|
-
"GET / HTTP/1.1\r\n"
|
1176
|
-
"Connection: close\r\n"
|
1177
|
-
"Host: foo\r\n"
|
1178
|
-
"!~: wrong\r\n"
|
1179
|
-
"\r\n");
|
1180
|
-
string response = readAll(fd);
|
1181
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.0 400 Bad Request\r\n"));
|
1182
|
-
ensure("(2)", containsSubstring(response,
|
1183
|
-
"Security password mismatch"));
|
1184
|
-
}
|
1185
|
-
|
1186
|
-
TEST_METHOD(55) {
|
1187
|
-
set_test_name("If a secure mode password is given in the context, "
|
1188
|
-
"it accepts requests that specify the correct secure mode password");
|
1189
|
-
|
1190
|
-
context.secureModePassword = "secret";
|
1191
|
-
connectToServer();
|
1192
|
-
sendRequest(
|
1193
|
-
"GET / HTTP/1.1\r\n"
|
1194
|
-
"Connection: close\r\n"
|
1195
|
-
"Host: foo\r\n"
|
1196
|
-
"!~: secret\r\n"
|
1197
|
-
"!~Foo: bar\r\n"
|
1198
|
-
"\r\n");
|
1199
|
-
string response = readAll(fd);
|
1200
|
-
ensure("(1)", containsSubstring(response, "HTTP/1.1 200 OK\r\n"));
|
1201
|
-
}
|
1202
|
-
|
1203
|
-
|
1204
|
-
/***** Request ending *****/
|
1205
|
-
|
1206
|
-
TEST_METHOD(60) {
|
1207
|
-
set_test_name("If all output data is flushed, and keep-alive is not possible, "
|
1208
|
-
"it disconnects the client immediately");
|
1209
|
-
|
1210
|
-
connectToServer();
|
1211
|
-
sendRequest(
|
1212
|
-
"GET / HTTP/1.1\r\n"
|
1213
|
-
"Connection: close\r\n"
|
1214
|
-
"Host: foo\r\n\r\n");
|
1215
|
-
readAll(fd); // Does not block
|
1216
|
-
}
|
1217
|
-
|
1218
|
-
TEST_METHOD(61) {
|
1219
|
-
set_test_name("If all output data is flushed, and keep-alive is possible, "
|
1220
|
-
"it handles the next request immediately");
|
1221
|
-
|
1222
|
-
connectToServer();
|
1223
|
-
sendRequest(
|
1224
|
-
"GET / HTTP/1.1\r\n"
|
1225
|
-
"Connection: keep-alive\r\n"
|
1226
|
-
"Host: foo\r\n\r\n"
|
1227
|
-
"GET /foo HTTP/1.1\r\n"
|
1228
|
-
"Connection: close\r\n"
|
1229
|
-
"Host: foo\r\n\r\n");
|
1230
|
-
|
1231
|
-
string response = readAll(fd);
|
1232
|
-
ensure_equals(response,
|
1233
|
-
"HTTP/1.1 200 OK\r\n"
|
1234
|
-
"Status: 200 OK\r\n"
|
1235
|
-
"Content-Type: text/plain\r\n"
|
1236
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
1237
|
-
"Connection: keep-alive\r\n"
|
1238
|
-
"Content-Length: 7\r\n\r\n"
|
1239
|
-
"hello /"
|
1240
|
-
"HTTP/1.1 200 OK\r\n"
|
1241
|
-
"Status: 200 OK\r\n"
|
1242
|
-
"Content-Type: text/plain\r\n"
|
1243
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
1244
|
-
"Connection: close\r\n"
|
1245
|
-
"Content-Length: 10\r\n\r\n"
|
1246
|
-
"hello /foo");
|
1247
|
-
}
|
1248
|
-
|
1249
|
-
TEST_METHOD(62) {
|
1250
|
-
set_test_name("If there is unflushed output data, and keep-alive is not possible, "
|
1251
|
-
"it disconnects the client after all output data is flushed");
|
1252
|
-
|
1253
|
-
connectToServer();
|
1254
|
-
sendRequest(
|
1255
|
-
"GET /large_response HTTP/1.1\r\n"
|
1256
|
-
"Connection: close\r\n"
|
1257
|
-
"Host: foo\r\n"
|
1258
|
-
"Size: 1000000\r\n\r\n");
|
1259
|
-
string response = readAll(fd);
|
1260
|
-
string body = stripHeaders(response);
|
1261
|
-
ensure(startsWith(response, "HTTP/1.1 200 OK\r\n"));
|
1262
|
-
ensure_equals(body.size(), 1000000u);
|
1263
|
-
}
|
1264
|
-
|
1265
|
-
TEST_METHOD(63) {
|
1266
|
-
set_test_name("If there is unflushed output data, and keep-alive is possible, "
|
1267
|
-
"it handles the next request after all output data is flushed");
|
1268
|
-
|
1269
|
-
connectToServer();
|
1270
|
-
sendRequest(
|
1271
|
-
"GET /large_response HTTP/1.1\r\n"
|
1272
|
-
"Connection: keep-alive\r\n"
|
1273
|
-
"Host: foo\r\n"
|
1274
|
-
"Size: 1000000\r\n\r\n"
|
1275
|
-
"GET /foo HTTP/1.1\r\n"
|
1276
|
-
"Connection: close\r\n"
|
1277
|
-
"Host: foo\r\n\r\n");
|
1278
|
-
SHOULD_NEVER_HAPPEN(100,
|
1279
|
-
result = getTotalRequestsBegun() > 1;
|
1280
|
-
);
|
1281
|
-
|
1282
|
-
string data = readAll(fd);
|
1283
|
-
string response2 =
|
1284
|
-
"HTTP/1.1 200 OK\r\n"
|
1285
|
-
"Status: 200 OK\r\n"
|
1286
|
-
"Content-Type: text/plain\r\n"
|
1287
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
1288
|
-
"Connection: close\r\n"
|
1289
|
-
"Content-Length: 10\r\n\r\n"
|
1290
|
-
"hello /foo";
|
1291
|
-
|
1292
|
-
string body = stripHeaders(data);
|
1293
|
-
ensure(startsWith(data, "HTTP/1.1 200 OK\r\n"));
|
1294
|
-
ensure_equals(body.size(), 1000000u + response2.size());
|
1295
|
-
ensure_equals(body.substr(1000000), response2);
|
1296
|
-
}
|
1297
|
-
|
1298
|
-
TEST_METHOD(64) {
|
1299
|
-
set_test_name("If a request with body is ended but output is being flushed, "
|
1300
|
-
"then any received request body data will be discard");
|
1301
|
-
|
1302
|
-
connectToServer();
|
1303
|
-
sendRequest(
|
1304
|
-
"GET /large_response HTTP/1.1\r\n"
|
1305
|
-
"Connection: close\r\n"
|
1306
|
-
"Host: foo\r\n"
|
1307
|
-
"Size: 1000000\r\n"
|
1308
|
-
"Content-Length: 4\r\n\r\n");
|
1309
|
-
EVENTUALLY(1,
|
1310
|
-
result = getTotalRequestsBegun() == 1;
|
1311
|
-
);
|
1312
|
-
|
1313
|
-
unsigned long long previouslyBytesConsumed;
|
1314
|
-
previouslyBytesConsumed = getTotalBytesConsumed();
|
1315
|
-
|
1316
|
-
writeExact(fd, "abcd");
|
1317
|
-
string response = readAll(fd);
|
1318
|
-
string body = stripHeaders(response);
|
1319
|
-
ensure(startsWith(response, "HTTP/1.1 200 OK\r\n"));
|
1320
|
-
ensure_equals(body.size(), 1000000u);
|
1321
|
-
EVENTUALLY(1,
|
1322
|
-
result = getTotalBytesConsumed() > previouslyBytesConsumed;
|
1323
|
-
);
|
1324
|
-
ensure_equals(getBodyBytesRead(), 0u);
|
1325
|
-
}
|
1326
|
-
|
1327
|
-
TEST_METHOD(65) {
|
1328
|
-
set_test_name("If a request with body is ended but output is being flushed, "
|
1329
|
-
"then it won't attempt to keep-alive the connection after the output is flushed");
|
1330
|
-
|
1331
|
-
connectToServer();
|
1332
|
-
sendRequest(
|
1333
|
-
"GET /large_response HTTP/1.1\r\n"
|
1334
|
-
"Connection: keep-alive\r\n"
|
1335
|
-
"Host: foo\r\n"
|
1336
|
-
"Size: 1000000\r\n"
|
1337
|
-
"Content-Length: 4\r\n\r\n");
|
1338
|
-
EVENTUALLY(1,
|
1339
|
-
result = getTotalRequestsBegun() == 1;
|
1340
|
-
);
|
1341
|
-
|
1342
|
-
unsigned long long previouslyBytesConsumed;
|
1343
|
-
previouslyBytesConsumed = getTotalBytesConsumed();
|
1344
|
-
|
1345
|
-
writeExact(fd,
|
1346
|
-
"abcd"
|
1347
|
-
"GET /foo HTTP/1.1\r\n"
|
1348
|
-
"Connection: close\r\n"
|
1349
|
-
"Host: foo\r\n\r\n");
|
1350
|
-
string response = readAll(fd);
|
1351
|
-
string body = stripHeaders(response);
|
1352
|
-
ensure(startsWith(response, "HTTP/1.1 200 OK\r\n"));
|
1353
|
-
ensure_equals(body.size(), 1000000u);
|
1354
|
-
EVENTUALLY(1,
|
1355
|
-
result = getTotalBytesConsumed() > previouslyBytesConsumed;
|
1356
|
-
);
|
1357
|
-
ensure_equals(getBodyBytesRead(), 0u);
|
1358
|
-
|
1359
|
-
SHOULD_NEVER_HAPPEN(100,
|
1360
|
-
result = getTotalRequestsBegun() > 1;
|
1361
|
-
);
|
1362
|
-
}
|
1363
|
-
|
1364
|
-
|
1365
|
-
/***** Miscellaneous *****/
|
1366
|
-
|
1367
|
-
TEST_METHOD(70) {
|
1368
|
-
set_test_name("It responds with the same HTTP version as the request");
|
1369
|
-
|
1370
|
-
connectToServer();
|
1371
|
-
sendRequest(
|
1372
|
-
"GET / HTTP/1.0\r\n"
|
1373
|
-
"Connection: close\r\n"
|
1374
|
-
"Host: foo\r\n\r\n");
|
1375
|
-
string response = readAll(fd);
|
1376
|
-
ensure_equals(response,
|
1377
|
-
"HTTP/1.0 200 OK\r\n"
|
1378
|
-
"Status: 200 OK\r\n"
|
1379
|
-
"Content-Type: text/plain\r\n"
|
1380
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
1381
|
-
"Connection: close\r\n"
|
1382
|
-
"Content-Length: 7\r\n\r\n"
|
1383
|
-
"hello /");
|
1384
|
-
}
|
1385
|
-
|
1386
|
-
TEST_METHOD(71) {
|
1387
|
-
set_test_name("For requests without body, keep-alive is possible");
|
1388
|
-
|
1389
|
-
connectToServer();
|
1390
|
-
sendRequest(
|
1391
|
-
"GET / HTTP/1.1\r\n"
|
1392
|
-
"Connection: keep-alive\r\n"
|
1393
|
-
"Host: foo\r\n\r\n");
|
1394
|
-
string header = readResponseHeader();
|
1395
|
-
ensure(containsSubstring(header, "Connection: keep-alive"));
|
1396
|
-
}
|
1397
|
-
|
1398
|
-
TEST_METHOD(72) {
|
1399
|
-
set_test_name("If the request body is fully read, keep-alive is possible");
|
1400
|
-
|
1401
|
-
connectToServer();
|
1402
|
-
sendRequest(
|
1403
|
-
"GET /body_test HTTP/1.1\r\n"
|
1404
|
-
"Connection: keep-alive\r\n"
|
1405
|
-
"Host: foo\r\n"
|
1406
|
-
"Content-Length: 2\r\n\r\n"
|
1407
|
-
"ok");
|
1408
|
-
string header = readResponseHeader();
|
1409
|
-
ensure(containsSubstring(header, "Connection: keep-alive"));
|
1410
|
-
}
|
1411
|
-
|
1412
|
-
TEST_METHOD(73) {
|
1413
|
-
set_test_name("If the request body is not fully read, keep-alive is not possible");
|
1414
|
-
|
1415
|
-
connectToServer();
|
1416
|
-
sendRequest(
|
1417
|
-
"GET / HTTP/1.1\r\n"
|
1418
|
-
"Connection: keep-alive\r\n"
|
1419
|
-
"Host: foo\r\n"
|
1420
|
-
"Content-Length: 2\r\n\r\n");
|
1421
|
-
string header = readResponseHeader();
|
1422
|
-
ensure(containsSubstring(header, "Connection: close"));
|
1423
|
-
}
|
1424
|
-
|
1425
|
-
TEST_METHOD(74) {
|
1426
|
-
set_test_name("It defaults to not using keep-alive for HTTP <= 1.0 requests");
|
1427
|
-
|
1428
|
-
connectToServer();
|
1429
|
-
sendRequest(
|
1430
|
-
"GET / HTTP/1.0\r\n"
|
1431
|
-
"Host: foo\r\n\r\n");
|
1432
|
-
string header = readResponseHeader();
|
1433
|
-
ensure(containsSubstring(header, "Connection: close"));
|
1434
|
-
}
|
1435
|
-
|
1436
|
-
TEST_METHOD(75) {
|
1437
|
-
set_test_name("It defaults to using keep-alive for HTTP >= 1.1 requests");
|
1438
|
-
|
1439
|
-
connectToServer();
|
1440
|
-
sendRequest(
|
1441
|
-
"GET / HTTP/1.1\r\n"
|
1442
|
-
"Host: foo\r\n\r\n");
|
1443
|
-
string header = readResponseHeader();
|
1444
|
-
ensure(containsSubstring(header, "Connection: keep-alive"));
|
1445
|
-
}
|
1446
|
-
|
1447
|
-
TEST_METHOD(76) {
|
1448
|
-
set_test_name("writeSimpleResponse() doesn't output the body for HEAD requests");
|
1449
|
-
|
1450
|
-
connectToServer();
|
1451
|
-
sendRequest(
|
1452
|
-
"HEAD / HTTP/1.1\r\n"
|
1453
|
-
"Connection: close\r\n"
|
1454
|
-
"Host: foo\r\n\r\n");
|
1455
|
-
string response = readAll(fd);
|
1456
|
-
ensure_equals(response,
|
1457
|
-
"HTTP/1.1 200 OK\r\n"
|
1458
|
-
"Status: 200 OK\r\n"
|
1459
|
-
"Content-Type: text/plain\r\n"
|
1460
|
-
"Date: Thu, 11 Sep 2014 12:54:09 GMT\r\n"
|
1461
|
-
"Connection: close\r\n"
|
1462
|
-
"Content-Length: 7\r\n\r\n");
|
1463
|
-
}
|
1464
|
-
|
1465
|
-
TEST_METHOD(77) {
|
1466
|
-
set_test_name("Client socket write error handling");
|
1467
|
-
|
1468
|
-
setLogLevel(LVL_CRIT);
|
1469
|
-
connectToServer();
|
1470
|
-
sendRequest(
|
1471
|
-
"GET /large_response HTTP/1.1\r\n"
|
1472
|
-
"Connection: close\r\n"
|
1473
|
-
"Size: 1000000\r\n\r\n");
|
1474
|
-
fd.close();
|
1475
|
-
|
1476
|
-
EVENTUALLY(5,
|
1477
|
-
result = getActiveClientCount() == 0;
|
1478
|
-
);
|
1479
|
-
}
|
1480
|
-
|
1481
|
-
TEST_METHOD(78) {
|
1482
|
-
set_test_name("Upon shutting down the server, no requests will be "
|
1483
|
-
"eligible for keep-alive");
|
1484
|
-
|
1485
|
-
connectToServer();
|
1486
|
-
sendRequestAndWait(
|
1487
|
-
"GET /body_test HTTP/1.1\r\n"
|
1488
|
-
"Connection: keep-alive\r\n"
|
1489
|
-
"Content-Length: 3\r\n\r\n");
|
1490
|
-
shutdownServer();
|
1491
|
-
|
1492
|
-
sendRequest("ab\n"
|
1493
|
-
"GET / HTTP/1.1\r\n"
|
1494
|
-
"Connection: close\r\n\r\n");
|
1495
|
-
string response = readAll(fd);
|
1496
|
-
ensure("(1)", containsSubstring(response, "Connection: close"));
|
1497
|
-
ensure("(2)", !containsSubstring(response, "Connection: keep-alive"));
|
1498
|
-
ensure("(3)", !containsSubstring(response, "hello /"));
|
1499
|
-
}
|
1500
|
-
|
1501
|
-
TEST_METHOD(79) {
|
1502
|
-
set_test_name("Upon shutting down the server, requests for which the "
|
1503
|
-
"headers are being parsed are not disconnected");
|
1504
|
-
|
1505
|
-
connectToServer();
|
1506
|
-
sendRequestAndWait(
|
1507
|
-
"GET / HTTP/1.1\r\n");
|
1508
|
-
shutdownServer();
|
1509
|
-
EVENTUALLY(100,
|
1510
|
-
result = !hasResponseData();
|
1511
|
-
);
|
1512
|
-
|
1513
|
-
sendRequest("\r\n");
|
1514
|
-
string response = readAll(fd);
|
1515
|
-
ensure("(1)", containsSubstring(response, "Connection: close"));
|
1516
|
-
ensure("(2)", !containsSubstring(response, "Connection: keep-alive"));
|
1517
|
-
ensure("(3)", containsSubstring(response, "hello /"));
|
1518
|
-
}
|
1519
|
-
|
1520
|
-
TEST_METHOD(80) {
|
1521
|
-
set_test_name("Upon shutting down the server, requests for which the "
|
1522
|
-
"headers are being parsed are disconnected when they've been "
|
1523
|
-
"identified as upgraded requests");
|
1524
|
-
|
1525
|
-
connectToServer();
|
1526
|
-
sendRequestAndWait(
|
1527
|
-
"GET / HTTP/1.1\r\n"
|
1528
|
-
"Connection: upgrade\r\n"
|
1529
|
-
"Upgrade: tcp\r\n");
|
1530
|
-
shutdownServer();
|
1531
|
-
EVENTUALLY(100,
|
1532
|
-
result = !hasResponseData();
|
1533
|
-
);
|
1534
|
-
|
1535
|
-
sendRequest("\r\n");
|
1536
|
-
string response = readAll(fd);
|
1537
|
-
ensure("(1)", containsSubstring(response, "503 Service Unavailable"));
|
1538
|
-
ensure("(2)", containsSubstring(response, "Connection: close"));
|
1539
|
-
ensure("(3)", !containsSubstring(response, "Connection: keep-alive"));
|
1540
|
-
}
|
1541
|
-
|
1542
|
-
TEST_METHOD(81) {
|
1543
|
-
set_test_name("Upon shutting down the server, normal requests which "
|
1544
|
-
"are being processed are not disconnected");
|
1545
|
-
|
1546
|
-
connectToServer();
|
1547
|
-
sendRequestAndWait(
|
1548
|
-
"GET /body_test HTTP/1.1\r\n"
|
1549
|
-
"Content-Length: 2\r\n\r\n");
|
1550
|
-
shutdownServer();
|
1551
|
-
EVENTUALLY(100,
|
1552
|
-
result = !hasResponseData();
|
1553
|
-
);
|
1554
|
-
|
1555
|
-
sendRequest("ab");
|
1556
|
-
string response = readAll(fd);
|
1557
|
-
ensure("(1)", containsSubstring(response, "Connection: close"));
|
1558
|
-
ensure("(2)", !containsSubstring(response, "Connection: keep-alive"));
|
1559
|
-
ensure("(3)", containsSubstring(response, "2 bytes: ab"));
|
1560
|
-
}
|
1561
|
-
|
1562
|
-
TEST_METHOD(82) {
|
1563
|
-
set_test_name("Upon shutting down the server, upgraded requests which "
|
1564
|
-
"are being processed are disconnected");
|
1565
|
-
|
1566
|
-
setLogLevel(LVL_CRIT);
|
1567
|
-
connectToServer();
|
1568
|
-
sendRequestAndWait(
|
1569
|
-
"GET /body_test HTTP/1.1\r\n"
|
1570
|
-
"Connection: upgrade\r\n"
|
1571
|
-
"Upgrade: tcp\r\n\r\n");
|
1572
|
-
shutdownServer();
|
1573
|
-
EVENTUALLY(5,
|
1574
|
-
result = hasResponseData();
|
1575
|
-
);
|
1576
|
-
|
1577
|
-
string response = readAll(fd);
|
1578
|
-
ensure_equals(response, "");
|
1579
|
-
}
|
1580
|
-
}
|