GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — libhttpserver/examples at master · Lihis/libhttpserver

Expand file tree

/

examples

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

examples

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Makefile.am
Makefile.am
 
 
README.md
README.md
 
 
allowing_disallowing_methods.cpp
allowing_disallowing_methods.cpp
 
 
basic_authentication.cpp
basic_authentication.cpp
 
 
benchmark_nodelay.cpp
benchmark_nodelay.cpp
 
 
benchmark_select.cpp
benchmark_select.cpp
 
 
benchmark_threads.cpp
benchmark_threads.cpp
 
 
cert.pem
cert.pem
 
 
custom_access_log.cpp
custom_access_log.cpp
 
 
custom_error.cpp
custom_error.cpp
 
 
deferred_with_accumulator.cpp
deferred_with_accumulator.cpp
 
 
digest_authentication.cpp
digest_authentication.cpp
 
 
file_upload.cpp
file_upload.cpp
 
 
handlers.cpp
handlers.cpp
 
 
hello_with_get_arg.cpp
hello_with_get_arg.cpp
 
 
hello_world.cpp
hello_world.cpp
 
 
key.pem
key.pem
 
 
minimal_deferred.cpp
minimal_deferred.cpp
 
 
minimal_file_response.cpp
minimal_file_response.cpp
 
 
minimal_hello_world.cpp
minimal_hello_world.cpp
 
 
minimal_https.cpp
minimal_https.cpp
 
 
minimal_ip_ban.cpp
minimal_ip_ban.cpp
 
 
service.cpp
service.cpp
 
 
setting_headers.cpp
setting_headers.cpp
 
 
test_content
test_content
 
 
url_registration.cpp
url_registration.cpp
 
 

README.md

Outline

Example Programs

hello_world.cpp - a very simple example of using libhttpserver to create a Rest server capable of receiving and processing HTTP requests. The server will be listening on port 8080.

service.cpp - an example using more of the libhttpserver API. This creates a Rest server capable of running with HTTP or HTTPS (provided that libhttpserver and libmicrohttpd have been compiled with SSL support.

	  The server can be configured via command line
	  arguments:

	  -p <port>  - port number to listen on (default 8080)
	  -s         - enable HTTPS
	  -k         - server key filename (default "key.pem")
	  -c         - server certificate filename (default "cert.pem")

Creating Certificates

Self-signed certificates can be created using OpenSSL using the following steps:

  $ openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
  $ openssl rsa -passin pass:x -in server.pass.key -out server.key
  $ openssl req -new -key server.key -out server.csr
  $ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

On the last step when prompted for a challenge password it can be left empty.

Thanks to https://devcenter.heroku.com/articles/ssl-certificate-self for these instructions.

Keystore configuration

If using a local client such as RestClient (https://github.com/wiztools/rest-client) for testing the Rest server then a keystore needs to be established. These commands should be bundled with your Java installation.

$ keytool -noprompt -import -keystore /path/to/restclient.store -alias restclient -file /path/to/server.crt

The keys in the store can be listed as follows:

$ keytool -list -v -keystore /path/to/restclient.store

The client can then be configured to use this keystore. Thanks to http://rubensgomes.blogspot.com/2012/01/how-to-set-up-restclient-for-ssl.html for instructions on configuring RestClient.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.