1 module hunt.http.MultipartOptions;
2 
3 import std.concurrency : initOnce;
4 import std.file;
5 
6 deprecated("Using MultipartOptions instead.")
7 alias MultipartConfig = MultipartOptions;
8 
9 /**
10  * Class represntation of an {@link MultipartConfig} value.
11  */
12 class MultipartOptions {
13 
14     static MultipartOptions Default() {
15         __gshared MultipartOptions inst;
16         return initOnce!inst(new MultipartOptions(tempDir()));
17     }
18 
19     private string location;
20     private long maxFileSize;
21     private long maxRequestSize;
22     private int fileSizeThreshold;
23     private bool _writeFilesWithFilenames;
24 
25     /**
26      * Constructs an instance with defaults for all but location.
27      *
28      * @param location defualts to "" if values is null.
29      */
30     this(string location) {
31         if (location is null) {
32             this.location = "";
33         } else {
34             this.location = location;
35         }
36         this.maxFileSize = -1L;
37         this.maxRequestSize = -1L;
38         this.fileSizeThreshold = 0;
39     }
40 
41     /**
42      * Constructs an instance with all values specified.
43      *
44      * @param location the directory location where files will be stored
45      * @param maxFileSize the maximum size allowed for uploaded files
46      * @param maxRequestSize the maximum size allowed for
47      * multipart/form-data requests
48      * @param fileSizeThreshold the size threshold after which files will
49      * be written to disk
50      */
51     this(string location, long maxFileSize,
52             long maxRequestSize, int fileSizeThreshold) {
53         if (location is null) {
54             this.location = "";
55         } else {
56             this.location = location;
57         }
58         this.maxFileSize = maxFileSize;
59         this.maxRequestSize = maxRequestSize;
60         this.fileSizeThreshold = fileSizeThreshold;
61     }
62 
63 
64     /**
65      * Gets the directory location where files will be stored.
66      *
67      * @return the directory location where files will be stored
68      */
69     string getLocation() {
70         return this.location;
71     }
72 
73     /**
74      * Gets the maximum size allowed for uploaded files.
75      *
76      * @return the maximum size allowed for uploaded files
77      */
78     long getMaxFileSize() {
79         return this.maxFileSize;
80     }
81 
82     /**
83      * Gets the maximum size allowed for multipart/form-data requests.
84      *
85      * @return the maximum size allowed for multipart/form-data requests
86      */
87     long getMaxRequestSize() {
88         return this.maxRequestSize;
89     }
90 
91     /**
92      * Gets the size threshold after which files will be written to disk.
93      *
94      * @return the size threshold after which files will be written to disk
95      */
96     int getFileSizeThreshold() {
97         return this.fileSizeThreshold;
98     }
99 
100     
101     void setWriteFilesWithFilenames(bool writeFilesWithFilenames) {
102         _writeFilesWithFilenames = writeFilesWithFilenames;
103     }
104 
105     bool isWriteFilesWithFilenames() {
106         return _writeFilesWithFilenames;
107     }
108 
109 }