tree: a719980370b3d0223907e9217f20c7156895ca4b [path history] [download]
  1. README.md
  2. http-mime-types.c
  3. http-mime-types.h
  4. http-objpool.c
  5. http-objpool.h
  6. http-protocol.c
  7. http-protocol.h
  8. http-request.c
  9. http-request.h
  10. http-response.c
  11. http-response.h
  12. http-status.c
  13. http-status.h
  14. http.h
  15. websockets.c
  16. websockets.h
src/http/README.md

HTTP extension for lib-server

This folder contains HTTP Protocol (HttpProtocol) extension for lib-server... However, although this project's makefile contains instructions for subfolder compilation... you might want to copy all the files to a single folder when incorporating these libraries in your own project.

The folder hierarchy in this project is for maintenance convenience only and probably shouldn't be used in actual projects.

Demo code

Here's a simple “Hello World” using the Http extensions:

// include location may vary according to your makefile and project hierarchy.
#include "http.h"

#define THREAD_COUNT 1
#define WORKER_COUNT 1

void on_request(struct HttpRequest* request) {
  struct HttpResponse* response = HttpResponse.create(request);
  HttpResponse.write_body(response, "Hello World!", 12);
  HttpResponse.destroy(response);
}

/*****************************
The main function
*/
int main(int argc, char const* argv[]) {
  start_http_server(on_request, NULL,
                    .threads = THREAD_COUNT,
                    .processes = WORKER_COUNT );
  return 0;
}