-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmd5_v4.vcl
53 lines (42 loc) · 1.57 KB
/
md5_v4.vcl
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
43
44
45
46
47
48
49
50
51
52
53
#Add the following to your Varnish 4 vcl file
#In varnish 4 inlice C disabled by default. You must enable it using -p vcc_allow_inline_c=true
C{
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
static const char* (*md5_hash)(char* str) = NULL;
__attribute__((constructor)) void
load_module()
{
const char* symbol_name = "md5_hash";
const char* plugin_name = "/etc/varnish/modules/md5/libmd5varnish.so";
void* handle = NULL;
handle = dlopen( plugin_name, RTLD_NOW );
if (handle != NULL) {
md5_hash = dlsym( handle, symbol_name );
if (md5_hash == NULL)
fprintf( stderr, "\nError: Could not load MD5 plugin:\n%s\n\n", dlerror() );
else
printf( "MD5 plugin loaded successfully.\n");
}
else
fprintf( stderr, "\nError: Could not load MD5 plugin:\n%s\n\n", dlerror() );
}
}C
## An Example of How to use it in vcl_recv
#
sub vcl_recv {
C{
//\6X-MD5: - \6 is length of string in octal encoding
static const struct gethdr_s VGC_HDR_REQ_VARNISH_X_MD5 = {
HDR_REQ, "\6X-MD5:"
};
static const struct gethdr_s VGC_HDR_REQ_VARNISH_X_DIGEST = {
HDR_REQ, "\24X-MD5-Digest-String:"
};
char* md5DigestString = VRT_GetHdr(ctx, &VGC_HDR_REQ_VARNISH_X_DIGEST);
const char* calculatedMD5 = (*md5_hash)(md5DigestString);
VRT_SetHdr(ctx, &VGC_HDR_REQ_VARNISH_X_MD5, calculatedMD5, vrt_magic_string_end);
free((char*)calculatedMD5);
}C
}