summaryrefslogtreecommitdiff
path: root/pinyweb
diff options
context:
space:
mode:
authorJulian Blake Kongslie <jblake@omgwallhack.org>2011-01-18 19:46:33 -0800
committerJulian Blake Kongslie <jblake@omgwallhack.org>2011-01-18 19:46:33 -0800
commiteb8dc87dca8089bfccaed79db0ed3b5483054472 (patch)
tree81fa88a651f3c6e5880f69d9f323c986e9c694af /pinyweb
parentbc398e23ce4e682fc84f84c40037ba8eae052a70 (diff)
downloadpiny-code-eb8dc87dca8089bfccaed79db0ed3b5483054472.tar.gz
piny-code-eb8dc87dca8089bfccaed79db0ed3b5483054472.zip
Do something more reasonable with OPTIONS requests.
Diffstat (limited to 'pinyweb')
-rwxr-xr-xpinyweb/cgi-bin/checkconstraint.cgi36
1 files changed, 21 insertions, 15 deletions
diff --git a/pinyweb/cgi-bin/checkconstraint.cgi b/pinyweb/cgi-bin/checkconstraint.cgi
index 8db0903..757bcaa 100755
--- a/pinyweb/cgi-bin/checkconstraint.cgi
+++ b/pinyweb/cgi-bin/checkconstraint.cgi
@@ -11,29 +11,35 @@ use Piny;
my $q = CGI->new( );
-my $type = $q->param( 't' );
-my $value = $q->param( 'v' );
-
-if ( not defined $type or not defined $value ) {
- print "Status: 400 Bad Request\nContent-type: application/json\n\n";
- print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Required parameter missing." } );
+if ( $q->request_method( ) eq "OPTIONS" ) {
+ print "Status: 204 No Content\nAccess-Control-Allow-Origin: *\n\n";
} else {
- my $constraint = find_type_constraint( $type );
+ my $type = $q->param( 't' );
+ my $value = $q->param( 'v' );
- if ( not defined $constraint ) {
+ if ( not defined $type or not defined $value ) {
print "Status: 400 Bad Request\nContent-type: application/json\n\n";
- print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Invalid constraint name." } );
+ print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Required parameter missing." } );
} else {
- print "Status: 200 OK\nContent-type: application/json\n\n";
-
- my $error = $constraint->validate( $value );
+ my $constraint = find_type_constraint( $type );
- if ( defined $error ) {
- print encode_json( { "ok" => JSON::false, "msg" => $error } );
+ if ( not defined $constraint ) {
+ print "Status: 400 Bad Request\nContent-type: application/json\n\n";
+ print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Invalid constraint name." } );
} else {
- print encode_json( { "ok" => JSON::true } );
+
+ print "Status: 200 OK\nContent-type: application/json\n\n";
+
+ my $error = $constraint->validate( $value );
+
+ if ( defined $error ) {
+ print encode_json( { "ok" => JSON::false, "msg" => $error } );
+ } else {
+ print encode_json( { "ok" => JSON::true } );
+ };
+
};
};