https://github.com/ncordon/files-web-server
Test of a C++ web server to index folders
https://github.com/ncordon/files-web-server
Last synced: 11 months ago
JSON representation
Test of a C++ web server to index folders
- Host: GitHub
- URL: https://github.com/ncordon/files-web-server
- Owner: ncordon
- License: gpl-2.0
- Created: 2019-05-11T22:21:34.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-13T10:07:15.000Z (about 7 years ago)
- Last Synced: 2025-02-10T06:14:41.922Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 43 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# File indexer
It works under Linux. It has not been tested on Windows.
# Compilation
It suffices to do:
```bash
mkdir bin obj
make
```
# Test
From one terminal, we should do, once compiled:
```bash
./bin/file-indexer 8000 .
```
This would mount this folder in the 8000 port. We have a test file named `requests` into this directory. To test the concurrent requests it contains, we should do, from another terminal:
```bash
cat requests | while read n; do printf "%q\n" "$n"; done | xargs -P 4 -I % bash -c %
```
This last test generates 4 concurrent requests, whose result will sometimes be unordered. An example:
```
#ifndef FILE__H
#define FILE__H
#include
#include
#include
#include
using std::string;
using std::vector;
class File {
private:
string path;
public:
File(string path);
bool is_file();
bool is_folder();
vector list_files();
File operator /(string file);
string get_path() {
return path;
}
};
#endif
#ifndef SERVER__H
#define SERVER__H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "file.h"
#define BACKLOG 5
using std::string;
using std::vector;
using std::ifstream;
using std::cout;
using std::endl;
struct HttpResponses {
string NOT_FOUND();
string OK(string msg);
};
class Request {
private:
int fd;
string root_folder;
const int BUFFER_SIZE = 1024;
HttpResponses responses;
public:
Request(string root_folder, int fd);
void answer();
};
class FileServer {
private:
int socket_fd;
string root_folder;
public:
FileServer(int port, string root_folder);
Request await_request();
};
#endif
Not Found
Not Found
```
