static int http_open(URLContext *h, const char *uri, int flags, AVDictionary **options) { HTTPContext *s = h->priv_data; int ret; if( s->seekable == 1 ) h->is_streamed = 0; else h->is_streamed = 1; s->filesize = -1; s->location = av_strdup(uri); if (!s->location) return AVERROR(ENOMEM); if (options) av_dict_copy(&s->chained_options, *options, 0); if (s->headers) { int len = strlen(s->headers); if (len < 2 || strcmp("\r\n", s->headers + len - 2)) av_log(h, AV_LOG_WARNING, "No trailing CRLF found in HTTP header.\n"); } if (s->listen) { return http_listen(h, uri, flags, options); } ret = http_open_cnx(h, options); if (ret < 0) av_dict_free(&s->chained_options); return ret; }
int prepare(struct httpd *httpd, const char *to_bind) { int err; struct sa local_addr; err = sa_decode(&local_addr, to_bind, strlen(to_bind)); if(err != 0) return err; err = http_listen(&httpd->hsp, &local_addr, http_request_h, httpd); return err; }
int main(int argc, char *argv[]) { cmd_options_t options; if (!get_options(argc, argv, cmd_options, countof(cmd_options), options)) return EXIT_FAILURE; if (get_option_exists(options, option_verbose)) log_enable(log_error | log_warning | log_info); else log_enable(log_error); uv_default_loop(); std::string url; if (get_option(options, option_get, url)) { /* issue a GET request */ http_get(url, 8080 /*port*/, [](const http_client_response_t &res) { for (auto &field : res.fields) { dlog(log_info, "%s: %s\n", field.key.c_str(), field.value.c_str()); } dlog(log_info, "http_get callback called\n"); }); } else { http_use_route("/", HTTP_GET, [](const http_request_ptr_t &request, const http_response_ptr_t &response) { dlog(log_info, "received get against \"%s\"\n", request->uri_path().c_str()); response->set_response(200, "OK", "text/html"); response->send("<html>SUCCESS!</html>"); response->end(); }); http_use_route("/objects", HTTP_GET, [](const http_request_ptr_t &request, const http_response_ptr_t &response) { dlog(log_info, "received get against \"%s\"\n", request->uri_path().c_str()); response->set_response(200, "OK", "text/html"); std::stringstream ss; ss << "<code>report<br/>test</code>"; response->send(ss.str()); response->end(); }); /* Consider consulting ulimit -aH as a signpost for what's a good backlog? */ http_listen(8000 /*port*/, 6000 /*backlog*/); } uv_run(uv_default_loop(), UV_RUN_DEFAULT); return EXIT_SUCCESS; }
static int module_init(void) { struct sa laddr; int err; if (conf_get_sa(conf_cur(), "http_listen", &laddr)) { sa_set_str(&laddr, "0.0.0.0", 8000); } err = http_listen(&httpsock, &laddr, http_req_handler, NULL); if (err) return err; ui_register(&ui_http); info("httpd: listening on %J\n", &laddr); return 0; }