Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 149 lines (122 sloc) 5.349 kB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (** Content.
19 Allow HTML body data to reside either on disc or in memory.
20 Note that we can't call this module "Content" because of the module of that name
21 in social_network.
22 *)
23
24 (** Holding datatype
25 We keep an optional stat for the file in case of multiple length calls.
26 We don't really need ContentNone since it is exactly equivalent to (ContentString "") but
27 when we finally send the response, ContentNone doesn't call the write function whereas (ContentString "") does.
28 *)
29 type content =
30 ContentString of string
31 | ContentBuffer of Buffer.t
32 | ContentFBuffer of FBuffer.t
33 | ContentFile of string * in_channel option * out_channel option * Unix.stats option * bool
34 | ContentNone
35
36 (** Indicator type for buffer types, used by content_make.
37 *)
38 type content_type = CT_STRING | CT_BUFFER | CT_FBUFFER | CT_FILE | CT_NONE
39
40 (** Turn content_type into string.
41 *)
42 val string_of_content_type : content_type -> string
43
44 (** content_temporary_files:
45 List of temporary files created by content_force_file etc.
46 *)
47 val content_temporary_files : string list ref
48
49 (** content_unlink_temporary_files:
50 Delete all of the temporary files created by this session.
51 *)
52 val content_unlink_temporary_files : unit -> unit
53
54 (** content_make content_type hint:
55 Create a content of the given type with given hint size.
56 Note that the hint is ignored for files unless truncate is set to true (default is false).
57 Extreme caution should be used with truncate.
58 *)
59 val content_make : ?truncate:bool -> ?hint:int -> content_type -> content
60
61 (** content_unallocate content:
62 Release any resources built into content (file handles, memory etc.)
63 *)
64 val content_unallocate : content -> unit
65
66 (** content_add str content:
67 Add a string to the end of content. Imperative for Buffer, functional for FBuffer...
68 Adding to a to ContentNone returns a ContentString, adding to a ContentString returns a
69 ContentBuffer, adding to a buffer of more than max_buffer_size returns a ContentFile.
70 The max_buffer_size parameter default is 10Mb. ContentFBuffers grow indefinitely.
71 *)
72 val content_add : ?evolve:bool -> ?max_buffer_size:int -> string -> content -> content
73
74 (** content_add_content c1 c2:
75 Add the contents of c2 to c1.
76 *)
77 val content_add_content : ?max_buffer_size:int -> content -> content -> content
78
79 (** content_length content:
80 Return the size of the content, uses the stat, if present.
81 *)
82 val content_length : content -> int
83
84 (** get_contencontent_type content:
85 Return the content_type.
86 *)
87 val get_content_type : content -> content_type
88
89 (** get_content content:
90 Return the content as a string, reads file, if necessary.
91 *)
92 val get_content : content -> string
93
94 (** bodystr ?max_body ?escaped ?hex content:
95 Return a length limited string for content.
96 Length limited to max_body (default: 50).
97 Only reads max_body from file.
98 Terminates string with "..." if content is truncated.
99 Optionally converts to hex bytes.
100 *)
101 val bodystr : ?max_body:int -> ?escaped:bool -> ?hex:bool -> content -> string
102
103 (** content_is_string content: Predicate for string content (includes (f)buffer and none). *)
104 val content_is_string : content -> bool
105
106 (** content_is_buffer content: Specific predicate for buffer content. *)
107 val content_is_buffer : content -> bool
108
109 (** content_is_fbuffer content: Specific predicate for fbuffer content. *)
110 val content_is_fbuffer : content -> bool
111
112 (** content_is_file content: Predicate for file content. *)
113 val content_is_file : content -> bool
114
115 (** content_force_string content:
116 Ensure content is string-based, reads file, if necessary.
117 *)
118 val content_force_string : ?unallocate:bool -> content -> content
119
120 (** content_from_file filename:
121 Create content from file.
122 *)
123 val content_from_file : ?unlinkable:bool -> ?stat:bool -> string -> content
124
125 (** content_force_file content:
126 Ensure content is file-based.
127 Creates temporary file according to Filename.temp_file.
128 Writes string to file.
129 Temp file name can be read back from datatype.
130 *)
131 val content_force_file : ?close:bool -> content -> content
132
133 (** content_rename_file:
134 Creates the given target file from content.
135 For ContentFile contents:
136 - Rename internal file to target name.
137 - The force arg and return int as per File.mv.
138 For other content types, a file is created and the content dumped to the file.
139 Note that if you call this function, Rcontent assumes no further reponsability
140 for any internal designated file.
141 *)
142 val content_rename_file : ?force:bool -> content -> string -> int
143
144 (** content_md5 content:
145 Return MD5 string for content.
146 Does not read file in.
147 *)
148 val content_md5 : content -> string
Something went wrong with that request. Please try again.