• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/uclient/uclient-test.uc

  1 #!/usr/bin/env ucode
  2 'use strict';
  3 import { basename, stdout } from "fs";
  4 let uloop = require("uloop");
  5 let uclient = require("uclient");
  6 
  7 function fetch_data() {
  8         let data;
  9         while (length(data = uc.read()) > 0)
 10                 print(data);
 11 }
 12 
 13 let url = shift(ARGV);
 14 if (!url) {
 15         warn(`Usage: ${basename(sourcepath())} <url>\n`);
 16         exit(1);
 17 }
 18 
 19 uloop.init();
 20 uc = uclient.new(url, null, {
 21         header_done: (cb) => {
 22                 warn(sprintf("Headers: %.J\nStatus: %.J\n", uc.get_headers(), uc.status()));
 23         },
 24         data_read: fetch_data,
 25         data_eof: (cb) => {
 26                 stdout.flush();
 27                 uloop.end();
 28         },
 29         error: (cb, code) => {
 30                 warn(`Error: ${code}\n`);
 31                 uloop.end();
 32         }
 33 });
 34 
 35 if (!uc.ssl_init({ verify: false })) {
 36         warn(`Failed to initialize SSL\n`);
 37         exit(1);
 38 }
 39 
 40 if (!uc.connect()) {
 41         warn(`Failed to connect\n`);
 42         exit(1);
 43 }
 44 
 45 if (!uc.request("GET")) {
 46         warn(`Failed to send request\n`);
 47         exit(1);
 48 }
 49 
 50 uloop.run();

This page was automatically generated by LXR 0.3.1.  •  OpenWrt