forked from ravinet/mahimahi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbacking_store.cc
42 lines (32 loc) · 1.48 KB
/
backing_store.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include "backing_store.hh"
#include "http_record.pb.h"
#include "temp_file.hh"
#include "util.hh"
using namespace std;
HTTPDiskStore::HTTPDiskStore( const string & record_folder )
: record_folder_( record_folder ),
mutex_()
{
TemporarilyUnprivileged temp_unprivileged;
make_directory( record_folder_ );
}
void HTTPDiskStore::save( const HTTPResponse & response, const Address & server_address )
{
unique_lock<mutex> ul( mutex_ );
/* output file to write current request/response pair protobuf (user has all permissions) */
UniqueFile file( record_folder_ + "save" );
/* construct protocol buffer */
MahimahiProtobufs::RequestResponse output;
output.set_ip( server_address.ip() );
output.set_port( server_address.port() );
output.set_scheme( server_address.port() == 443
? MahimahiProtobufs::RequestResponse_Scheme_HTTPS
: MahimahiProtobufs::RequestResponse_Scheme_HTTP );
output.mutable_request()->CopyFrom( response.request().toprotobuf() );
output.mutable_response()->CopyFrom( response.toprotobuf() );
if ( not output.SerializeToFileDescriptor( file.fd().num() ) ) {
throw Exception( "save_to_disk", "failure to serialize HTTP request/response pair" );
}
}
void HTTPDiskStore::serialize_to_socket( Socket && client __attribute__ ( ( unused ) ) ) { printf("WARNING: IGNORING Socket that was passed\n"); }