From eb8dc87dca8089bfccaed79db0ed3b5483054472 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Tue, 18 Jan 2011 19:46:33 -0800 Subject: Do something more reasonable with OPTIONS requests. --- pinyweb/cgi-bin/checkconstraint.cgi | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'pinyweb/cgi-bin') 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 } ); + }; + }; }; -- cgit v1.2.3