Skip to content
Browse files

using shortcuts in examples now

  • Loading branch information...
1 parent b4b8eef commit 8d28882634c9e69f0ed0c1078452239440ced374 @abhinavsingh abhinavsingh committed
Showing with 7 additions and 13 deletions.
  1. +2 −9 examples/echo_http_server.php
  2. +5 −4 examples/http_rest_server.php
View
11 examples/echo_http_server.php
@@ -50,15 +50,8 @@
// catch all incoming requests here
function on_request($request) {
- if($request->method == 'GET') {
- $body = json_encode($request);
- $request->ok($body, array('Content-Type'=>'application/json'));
- $request->close();
- }
- else {
- $request->not_found();
- $request->close();
- }
+ $body = json_encode($request);
+ $request->ok($body, array('Content-Type'=>'application/json'));
}
// start http server
View
9 examples/http_rest_server.php
@@ -60,9 +60,9 @@ function index($request) {
// callback method for dispatch rule (see below)
function upload($request) {
if($request->method == 'GET') {
- $request->send_response(
- 200, array('Content-Type'=>'text/html'),
- '<html><head/><body><h1>Jaxl Http Server</h1><form enctype="multipart/form-data" method="POST" action=""><input type="file" name="file"/><input type="submit" value="upload"/></form></body></html>'
+ $request->ok(array(
+ 'Content-Type'=>'text/html'),
+ '<html><head/><body><h1>Jaxl Http Server</h1><form enctype="multipart/form-data" method="POST" action="http://127.0.0.1:9699/upload/"><input type="file" name="file"/><input type="submit" value="upload"/></form></body></html>'
);
}
else if($request->method == 'POST') {
@@ -72,7 +72,8 @@ function upload($request) {
else {
// got upload body, save it
_debug("file upload complete, got ".strlen($request->body)." bytes of data");
- $request->close();
+ $upload_data = $request->multipart->form_data[0]['body'];
+ $request->ok($upload_data, array('Content-Type'=>$request->multipart->form_data[0]['headers']['Content-Type']));
}
}
}

0 comments on commit 8d28882

Please sign in to comment.
Something went wrong with that request. Please try again.