Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow OPTIONS and PATCH requests in the standalone server. #535

Merged
merged 1 commit into from

3 participants

@veryrusty
Owner

Overrides the valid_http_method() method inherited from HTTP::Server::Simple
to allow all request types that the DSL supports in the standalone server. Closes #523.

@veryrusty veryrusty Allow OPTIONS and PATCH requests in the standalone server.
Overrides the valid_http_method() method inherited from HTTP::Server::Simple
to allow all request types that the DSL supports.
cc35c46
@racke
Owner

This makes a lot of sense and should be applied to Dancer 1 as well. Do we need a specific version o f HTTP::Server::Simple::PSGI for that?

Regards
Racke

@xsawyerx
Owner

:+1: !

@racke
Owner

valid_http_method was introduced into HTTP::Server::Simple ages ago (2006), so IMHO we are fine without an dependency on that.

@racke racke merged commit 763a1bd into master
@racke
Owner

Thanks a lot, veryrusty!

@veryrusty veryrusty deleted the pr/server_standalone_options_patch branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 16, 2014
  1. @veryrusty

    Allow OPTIONS and PATCH requests in the standalone server.

    veryrusty authored
    Overrides the valid_http_method() method inherited from HTTP::Server::Simple
    to allow all request types that the DSL supports.
This page is out of date. Refresh to see the latest.
Showing with 53 additions and 0 deletions.
  1. +14 −0 lib/Dancer2/Core/Server/Standalone.pm
  2. +39 −0 t/server_standalone.t
View
14 lib/Dancer2/Core/Server/Standalone.pm
@@ -80,4 +80,18 @@ sub print_banner {
}
}
+
+=method valid_http_method
+
+Overrides method inherited from L<HTTP::Server::Simple>, allowing C<GET>, C<POST>,
+C<HEAD>, C<PUT>, C<DELETE>, C<OPTIONS> and C<PATCH> requests.
+
+=cut
+
+sub valid_http_method {
+ my $self = shift;
+ my $method = shift or return 0;
+ return $method =~ /^(?:GET|POST|HEAD|PUT|DELETE|OPTIONS|PATCH)$/;
+}
+
1;
View
39 t/server_standalone.t
@@ -0,0 +1,39 @@
+use Test::More;
+use strict;
+use warnings;
+use Encode;
+use utf8;
+
+use Test::TCP 1.13;
+use HTTP::Headers;
+use HTTP::Request;
+use LWP::UserAgent;
+
+plan tests => 7;
+
+Test::TCP::test_tcp(
+ client => sub {
+ my $port = shift;
+ my $ua = LWP::UserAgent->new;
+ # Ensure the standalone standaloneerver responds to all the
+ # HTTP methods the DSL supports
+ for my $method ( qw/HEAD GET PUT POST DELETE OPTIONS PATCH/ ) {
+ my $req = HTTP::Request->new($method => "http://127.0.0.1:$port/foo");
+ my $res = $ua->request($req);
+ ok( $res->is_success, "$method return a 200 response");
+ }
+ },
+ server => sub {
+ my $port = shift;
+ use Dancer2;
+ set charset => 'utf-8';
+
+ any '/foo' => sub {
+ header "Allow" => "HEAD,GET,PUT,POST,DELETE,OPTIONS,PATCH";
+ "foo";
+ };
+
+ Dancer2->runner->server->port($port);
+ start;
+ },
+);
Something went wrong with that request. Please try again.