projects
/
Biblio-RFID.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bd04ced
)
slurp index.html from __DATA__ just once
author
Dobrica Pavlinusic
<dpavlin@rot13.org>
Tue, 27 Jul 2010 18:39:40 +0000
(20:39 +0200)
committer
Dobrica Pavlinusic
<dpavlin@rot13.org>
Tue, 27 Jul 2010 18:39:40 +0000
(20:39 +0200)
scripts/RFID-JSONP-server.pl
patch
|
blob
|
history
diff --git
a/scripts/RFID-JSONP-server.pl
b/scripts/RFID-JSONP-server.pl
index
9f1e3d6
..
34dfaa9
100755
(executable)
--- a/
scripts/RFID-JSONP-server.pl
+++ b/
scripts/RFID-JSONP-server.pl
@@
-28,6
+28,12
@@
use lib 'lib';
use RFID::Serial::3M810;
my $rfid = RFID::Serial::3M810->new;
use RFID::Serial::3M810;
my $rfid = RFID::Serial::3M810->new;
+my $index_html;
+{
+ local $/ = undef;
+ $index_html = <DATA>;
+}
+
sub http_server {
my $server = IO::Socket::INET->new(
sub http_server {
my $server = IO::Socket::INET->new(
@@
-41,24
+47,12
@@
sub http_server {
print "Server $0 ready at $server_url\n";
print "Server $0 ready at $server_url\n";
- sub static {
- my ($client,$path) = @_;
-
- return unless $path eq '/';
-
- print $client "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n";
- while(<DATA>) {
- print $client $_;
- }
-
- return $path;
- }
-
while (my $client = $server->accept()) {
$client->autoflush(1);
my $request = <$client>;
warn "WEB << $request\n" if $debug;
while (my $client = $server->accept()) {
$client->autoflush(1);
my $request = <$client>;
warn "WEB << $request\n" if $debug;
+ my $path;
if ($request =~ m{^GET (/.*) HTTP/1.[01]}) {
my $method = $1;
if ($request =~ m{^GET (/.*) HTTP/1.[01]}) {
my $method = $1;
@@
-70,8
+64,10
@@
sub http_server {
}
warn "WEB << param: ",dump( $param ) if $debug;
}
}
warn "WEB << param: ",dump( $param ) if $debug;
}
- if ( my $path = static( $client,$1 ) ) {
- warn "WEB >> $path" if $debug;
+ $path = $method;
+
+ if ( $path eq '/' ) {
+ print $client "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n$index_html";
} elsif ( $method =~ m{/scan} ) {
my $tags = $rfid->scan;
my $json = {
} elsif ( $method =~ m{/scan} ) {
my $tags = $rfid->scan;
my $json = {
@@
-138,7
+134,7
@@
http_server;
__DATA__
<html>
<head>
__DATA__
<html>
<head>
-<title>
3M RFID
</title>
+<title>
RFID JSONP
</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
.status {
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
.status {