]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - docs/frontends/webapi.rst
webapi.rst: document Range: header on GET requests
[tahoe-lafs/tahoe-lafs.git] / docs / frontends / webapi.rst
1 .. -*- coding: utf-8-with-signature -*-
2
3 ==========================
4 The Tahoe REST-ful Web API
5 ==========================
6
7 1.  `Enabling the web-API port`_
8 2.  `Basic Concepts: GET, PUT, DELETE, POST`_
9 3.  `URLs`_
10
11     1. `Child Lookup`_
12
13 4.  `Slow Operations, Progress, and Cancelling`_
14 5.  `Programmatic Operations`_
15
16     1. `Reading a file`_
17     2. `Writing/Uploading a File`_
18     3. `Creating a New Directory`_
19     4. `Getting Information About a File Or Directory (as JSON)`_
20     5. `Attaching an Existing File or Directory by its read- or write-cap`_
21     6. `Adding Multiple Files or Directories to a Parent Directory at Once`_
22     7. `Unlinking a File or Directory`_
23
24 6.  `Browser Operations: Human-Oriented Interfaces`_
25
26     1.  `Viewing a Directory (as HTML)`_
27     2.  `Viewing/Downloading a File`_
28     3.  `Getting Information About a File Or Directory (as HTML)`_
29     4.  `Creating a Directory`_
30     5.  `Uploading a File`_
31     6.  `Attaching an Existing File Or Directory (by URI)`_
32     7.  `Unlinking a Child`_
33     8.  `Renaming a Child`_
34     9.  `Relinking ("Moving") a Child`_
35     10. `Other Utilities`_
36     11. `Debugging and Testing Features`_
37
38 7.  `Other Useful Pages`_
39 8.  `Static Files in /public_html`_
40 9.  `Safety and Security Issues -- Names vs. URIs`_
41 10. `Concurrency Issues`_
42 11. `Access Blacklist`_
43
44
45 Enabling the web-API port
46 =========================
47
48 Every Tahoe node is capable of running a built-in HTTP server. To enable
49 this, just write a port number into the "[node]web.port" line of your node's
50 tahoe.cfg file. For example, writing "web.port = 3456" into the "[node]"
51 section of $NODEDIR/tahoe.cfg will cause the node to run a webserver on port
52 3456.
53
54 This string is actually a Twisted "strports" specification, meaning you can
55 get more control over the interface to which the server binds by supplying
56 additional arguments. For more details, see the documentation on
57 `twisted.application.strports`_.
58
59 Writing "tcp:3456:interface=127.0.0.1" into the web.port line does the same
60 but binds to the loopback interface, ensuring that only the programs on the
61 local host can connect. Using "ssl:3456:privateKey=mykey.pem:certKey=cert.pem"
62 runs an SSL server.
63
64 This webport can be set when the node is created by passing a --webport
65 option to the 'tahoe create-node' command. By default, the node listens on
66 port 3456, on the loopback (127.0.0.1) interface.
67
68 .. _twisted.application.strports: https://twistedmatrix.com/documents/current/api/twisted.application.strports.html
69
70
71 Basic Concepts: GET, PUT, DELETE, POST
72 ======================================
73
74 As described in `docs/architecture.rst`_, each file and directory in a Tahoe
75 virtual filesystem is referenced by an identifier that combines the
76 designation of the object with the authority to do something with it (such as
77 read or modify the contents). This identifier is called a "read-cap" or
78 "write-cap", depending upon whether it enables read-only or read-write
79 access. These "caps" are also referred to as URIs (which may be confusing
80 because they are not currently RFC3986_-compliant URIs).
81
82 The Tahoe web-based API is "REST-ful", meaning it implements the concepts of
83 "REpresentational State Transfer": the original scheme by which the World
84 Wide Web was intended to work. Each object (file or directory) is referenced
85 by a URL that includes the read- or write- cap. HTTP methods (GET, PUT, and
86 DELETE) are used to manipulate these objects. You can think of the URL as a
87 noun, and the method as a verb.
88
89 In REST, the GET method is used to retrieve information about an object, or
90 to retrieve some representation of the object itself. When the object is a
91 file, the basic GET method will simply return the contents of that file.
92 Other variations (generally implemented by adding query parameters to the
93 URL) will return information about the object, such as metadata. GET
94 operations are required to have no side-effects.
95
96 PUT is used to upload new objects into the filesystem, or to replace an
97 existing link or the contents of a mutable file. DELETE is used to unlink
98 objects from directories. Both PUT and DELETE are required to be idempotent:
99 performing the same operation multiple times must have the same side-effects
100 as only performing it once.
101
102 POST is used for more complicated actions that cannot be expressed as a GET,
103 PUT, or DELETE. POST operations can be thought of as a method call: sending
104 some message to the object referenced by the URL. In Tahoe, POST is also used
105 for operations that must be triggered by an HTML form (including upload and
106 unlinking), because otherwise a regular web browser has no way to accomplish
107 these tasks. In general, everything that can be done with a PUT or DELETE can
108 also be done with a POST.
109
110 Tahoe's web API is designed for two different kinds of consumer. The first is
111 a program that needs to manipulate the virtual file system. Such programs are
112 expected to use the RESTful interface described above. The second is a human
113 using a standard web browser to work with the filesystem. This user is given
114 a series of HTML pages with links to download files, and forms that use POST
115 actions to upload, rename, and unlink files.
116
117 When an error occurs, the HTTP response code will be set to an appropriate
118 400-series code (like 404 Not Found for an unknown childname, or 400 Bad Request
119 when the parameters to a web-API operation are invalid), and the HTTP response
120 body will usually contain a few lines of explanation as to the cause of the
121 error and possible responses. Unusual exceptions may result in a 500 Internal
122 Server Error as a catch-all, with a default response body containing
123 a Nevow-generated HTML-ized representation of the Python exception stack trace
124 that caused the problem. CLI programs which want to copy the response body to
125 stderr should provide an "Accept: text/plain" header to their requests to get
126 a plain text stack trace instead. If the Accept header contains ``*/*``, or
127 ``text/*``, or text/html (or if there is no Accept header), HTML tracebacks will
128 be generated.
129
130 .. _RFC3986: https://tools.ietf.org/html/rfc3986
131 .. _docs/architecture.rst: ../architecture.rst
132
133
134 URLs
135 ====
136
137 Tahoe uses a variety of read- and write- caps to identify files and
138 directories. The most common of these is the "immutable file read-cap", which
139 is used for most uploaded files. These read-caps look like the following::
140
141  URI:CHK:ime6pvkaxuetdfah2p2f35pe54:4btz54xk3tew6nd4y2ojpxj4m6wxjqqlwnztgre6gnjgtucd5r4a:3:10:202
142
143 The next most common is a "directory write-cap", which provides both read and
144 write access to a directory, and look like this::
145
146  URI:DIR2:djrdkfawoqihigoett4g6auz6a:jx5mplfpwexnoqff7y5e4zjus4lidm76dcuarpct7cckorh2dpgq
147
148 There are also "directory read-caps", which start with "URI:DIR2-RO:", and
149 give read-only access to a directory. Finally there are also mutable file
150 read- and write- caps, which start with "URI:SSK", and give access to mutable
151 files.
152
153 (Later versions of Tahoe will make these strings shorter, and will remove the
154 unfortunate colons, which must be escaped when these caps are embedded in
155 URLs.)
156
157 To refer to any Tahoe object through the web API, you simply need to combine
158 a prefix (which indicates the HTTP server to use) with the cap (which
159 indicates which object inside that server to access). Since the default Tahoe
160 webport is 3456, the most common prefix is one that will use a local node
161 listening on this port::
162
163  http://127.0.0.1:3456/uri/ + $CAP
164
165 So, to access the directory named above, the URL would be::
166
167  http://127.0.0.1:3456/uri/URI%3ADIR2%3Adjrdkfawoqihigoett4g6auz6a%3Ajx5mplfpwexnoqff7y5e4zjus4lidm76dcuarpct7cckorh2dpgq/
168
169 (note that the colons in the directory-cap are url-encoded into "%3A"
170 sequences).
171
172 Likewise, to access the file named above, use::
173
174  http://127.0.0.1:3456/uri/URI%3ACHK%3Aime6pvkaxuetdfah2p2f35pe54%3A4btz54xk3tew6nd4y2ojpxj4m6wxjqqlwnztgre6gnjgtucd5r4a%3A3%3A10%3A202
175
176 In the rest of this document, we'll use "$DIRCAP" as shorthand for a read-cap
177 or write-cap that refers to a directory, and "$FILECAP" to abbreviate a cap
178 that refers to a file (whether mutable or immutable). So those URLs above can
179 be abbreviated as::
180
181  http://127.0.0.1:3456/uri/$DIRCAP/
182  http://127.0.0.1:3456/uri/$FILECAP
183
184 The operation summaries below will abbreviate these further, by eliding the
185 server prefix. They will be displayed like this::
186
187  /uri/$DIRCAP/
188  /uri/$FILECAP
189
190 /cap can be used as a synonym for /uri.  If interoperability with older web-API
191 servers is required, /uri should be used.
192
193 Child Lookup
194 ------------
195
196 Tahoe directories contain named child entries, just like directories in a regular
197 local filesystem. These child entries, called "dirnodes", consist of a name,
198 metadata, a write slot, and a read slot. The write and read slots normally contain
199 a write-cap and read-cap referring to the same object, which can be either a file
200 or a subdirectory. The write slot may be empty (actually, both may be empty,
201 but that is unusual).
202
203 If you have a Tahoe URL that refers to a directory, and want to reference a
204 named child inside it, just append the child name to the URL. For example, if
205 our sample directory contains a file named "welcome.txt", we can refer to
206 that file with::
207
208  http://127.0.0.1:3456/uri/$DIRCAP/welcome.txt
209
210 (or http://127.0.0.1:3456/uri/URI%3ADIR2%3Adjrdkfawoqihigoett4g6auz6a%3Ajx5mplfpwexnoqff7y5e4zjus4lidm76dcuarpct7cckorh2dpgq/welcome.txt)
211
212 Multiple levels of subdirectories can be handled this way::
213
214  http://127.0.0.1:3456/uri/$DIRCAP/tahoe-source/docs/architecture.rst
215
216 In this document, when we need to refer to a URL that references a file using
217 this child-of-some-directory format, we'll use the following string::
218
219  /uri/$DIRCAP/[SUBDIRS../]FILENAME
220
221 The "[SUBDIRS../]" part means that there are zero or more (optional)
222 subdirectory names in the middle of the URL. The "FILENAME" at the end means
223 that this whole URL refers to a file of some sort, rather than to a
224 directory.
225
226 When we need to refer specifically to a directory in this way, we'll write::
227
228  /uri/$DIRCAP/[SUBDIRS../]SUBDIR
229
230
231 Note that all components of pathnames in URLs are required to be UTF-8
232 encoded, so "resume.doc" (with an acute accent on both E's) would be accessed
233 with::
234
235  http://127.0.0.1:3456/uri/$DIRCAP/r%C3%A9sum%C3%A9.doc
236
237 Also note that the filenames inside upload POST forms are interpreted using
238 whatever character set was provided in the conventional '_charset' field, and
239 defaults to UTF-8 if not otherwise specified. The JSON representation of each
240 directory contains native Unicode strings. Tahoe directories are specified to
241 contain Unicode filenames, and cannot contain binary strings that are not
242 representable as such.
243
244 All Tahoe operations that refer to existing files or directories must include
245 a suitable read- or write- cap in the URL: the web-API server won't add one
246 for you. If you don't know the cap, you can't access the file. This allows
247 the security properties of Tahoe caps to be extended across the web-API
248 interface.
249
250
251 Slow Operations, Progress, and Cancelling
252 =========================================
253
254 Certain operations can be expected to take a long time. The "t=deep-check",
255 described below, will recursively visit every file and directory reachable
256 from a given starting point, which can take minutes or even hours for
257 extremely large directory structures. A single long-running HTTP request is a
258 fragile thing: proxies, NAT boxes, browsers, and users may all grow impatient
259 with waiting and give up on the connection.
260
261 For this reason, long-running operations have an "operation handle", which
262 can be used to poll for status/progress messages while the operation
263 proceeds. This handle can also be used to cancel the operation. These handles
264 are created by the client, and passed in as a an "ophandle=" query argument
265 to the POST or PUT request which starts the operation. The following
266 operations can then be used to retrieve status:
267
268 ``GET /operations/$HANDLE?output=HTML   (with or without t=status)``
269
270 ``GET /operations/$HANDLE?output=JSON   (same)``
271
272  These two retrieve the current status of the given operation. Each operation
273  presents a different sort of information, but in general the page retrieved
274  will indicate:
275
276  * whether the operation is complete, or if it is still running
277  * how much of the operation is complete, and how much is left, if possible
278
279  Note that the final status output can be quite large: a deep-manifest of a
280  directory structure with 300k directories and 200k unique files is about
281  275MB of JSON, and might take two minutes to generate. For this reason, the
282  full status is not provided until the operation has completed.
283
284  The HTML form will include a meta-refresh tag, which will cause a regular
285  web browser to reload the status page about 60 seconds later. This tag will
286  be removed once the operation has completed.
287
288  There may be more status information available under
289  /operations/$HANDLE/$ETC : i.e., the handle forms the root of a URL space.
290
291 ``POST /operations/$HANDLE?t=cancel``
292
293  This terminates the operation, and returns an HTML page explaining what was
294  cancelled. If the operation handle has already expired (see below), this
295  POST will return a 404, which indicates that the operation is no longer
296  running (either it was completed or terminated). The response body will be
297  the same as a GET /operations/$HANDLE on this operation handle, and the
298  handle will be expired immediately afterwards.
299
300 The operation handle will eventually expire, to avoid consuming an unbounded
301 amount of memory. The handle's time-to-live can be reset at any time, by
302 passing a retain-for= argument (with a count of seconds) to either the
303 initial POST that starts the operation, or the subsequent GET request which
304 asks about the operation. For example, if a 'GET
305 /operations/$HANDLE?output=JSON&retain-for=600' query is performed, the
306 handle will remain active for 600 seconds (10 minutes) after the GET was
307 received.
308
309 In addition, if the GET includes a release-after-complete=True argument, and
310 the operation has completed, the operation handle will be released
311 immediately.
312
313 If a retain-for= argument is not used, the default handle lifetimes are:
314
315  * handles will remain valid at least until their operation finishes
316  * uncollected handles for finished operations (i.e. handles for
317    operations that have finished but for which the GET page has not been
318    accessed since completion) will remain valid for four days, or for
319    the total time consumed by the operation, whichever is greater.
320  * collected handles (i.e. the GET page has been retrieved at least once
321    since the operation completed) will remain valid for one day.
322
323 Many "slow" operations can begin to use unacceptable amounts of memory when
324 operating on large directory structures. The memory usage increases when the
325 ophandle is polled, as the results must be copied into a JSON string, sent
326 over the wire, then parsed by a client. So, as an alternative, many "slow"
327 operations have streaming equivalents. These equivalents do not use operation
328 handles. Instead, they emit line-oriented status results immediately. Client
329 code can cancel the operation by simply closing the HTTP connection.
330
331
332 Programmatic Operations
333 =======================
334
335 Now that we know how to build URLs that refer to files and directories in a
336 Tahoe virtual filesystem, what sorts of operations can we do with those URLs?
337 This section contains a catalog of GET, PUT, DELETE, and POST operations that
338 can be performed on these URLs. This set of operations are aimed at programs
339 that use HTTP to communicate with a Tahoe node. A later section describes
340 operations that are intended for web browsers.
341
342
343 Reading a File
344 --------------
345
346 ``GET /uri/$FILECAP``
347
348 ``GET /uri/$DIRCAP/[SUBDIRS../]FILENAME``
349
350  This will retrieve the contents of the given file. The HTTP response body
351  will contain the sequence of bytes that make up the file. The "Range:"
352  header can be used to restrict which portions of the file are returned (see
353  RFC 2616 section 14.35.1 "Byte Ranges"), however Tahoe only supports a
354  single "bytes" range and never provides a `multipart/byteranges` response.
355
356  To view files in a web browser, you may want more control over the
357  Content-Type and Content-Disposition headers. Please see the next section
358  "Browser Operations", for details on how to modify these URLs for that
359  purpose.
360
361
362 Writing/Uploading a File
363 ------------------------
364
365 ``PUT /uri/$FILECAP``
366
367 ``PUT /uri/$DIRCAP/[SUBDIRS../]FILENAME``
368
369  Upload a file, using the data from the HTTP request body, and add whatever
370  child links and subdirectories are necessary to make the file available at
371  the given location. Once this operation succeeds, a GET on the same URL will
372  retrieve the same contents that were just uploaded. This will create any
373  necessary intermediate subdirectories.
374
375  To use the /uri/$FILECAP form, $FILECAP must be a write-cap for a mutable file.
376
377  In the /uri/$DIRCAP/[SUBDIRS../]FILENAME form, if the target file is a
378  writeable mutable file, that file's contents will be overwritten
379  in-place. If it is a read-cap for a mutable file, an error will occur.
380  If it is an immutable file, the old file will be discarded, and a new
381  one will be put in its place. If the target file is a writable mutable
382  file, you may also specify an "offset" parameter -- a byte offset that
383  determines where in the mutable file the data from the HTTP request
384  body is placed. This operation is relatively efficient for MDMF mutable
385  files, and is relatively inefficient (but still supported) for SDMF
386  mutable files. If no offset parameter is specified, then the entire
387  file is replaced with the data from the HTTP request body. For an
388  immutable file, the "offset" parameter is not valid.
389
390  When creating a new file, you can control the type of file created by
391  specifying a format= argument in the query string. format=MDMF creates an
392  MDMF mutable file. format=SDMF creates an SDMF mutable file. format=CHK
393  creates an immutable file. The value of the format argument is
394  case-insensitive. If no format is specified, the newly-created file will be
395  immutable (but see below).
396
397  For compatibility with previous versions of Tahoe-LAFS, the web-API will
398  also accept a mutable=true argument in the query string. If mutable=true is
399  given, then the new file will be mutable, and its format will be the default
400  mutable file format, as configured by the [client]mutable.format option of
401  tahoe.cfg on the Tahoe-LAFS node hosting the webapi server. Use of
402  mutable=true is discouraged; new code should use format= instead of
403  mutable=true (unless it needs to be compatible with web-API servers older
404  than v1.9.0). If neither format= nor mutable=true are given, the
405  newly-created file will be immutable.
406
407  This returns the file-cap of the resulting file. If a new file was created
408  by this method, the HTTP response code (as dictated by rfc2616) will be set
409  to 201 CREATED. If an existing file was replaced or modified, the response
410  code will be 200 OK.
411
412  Note that the 'curl -T localfile http://127.0.0.1:3456/uri/$DIRCAP/foo.txt'
413  command can be used to invoke this operation.
414
415 ``PUT /uri``
416
417  This uploads a file, and produces a file-cap for the contents, but does not
418  attach the file into the filesystem. No directories will be modified by
419  this operation. The file-cap is returned as the body of the HTTP response.
420
421  This method accepts format= and mutable=true as query string arguments, and
422  interprets those arguments in the same way as the linked forms of PUT
423  described immediately above.
424
425 Creating a New Directory
426 ------------------------
427
428 ``POST /uri?t=mkdir``
429
430 ``PUT /uri?t=mkdir``
431
432  Create a new empty directory and return its write-cap as the HTTP response
433  body. This does not make the newly created directory visible from the
434  filesystem. The "PUT" operation is provided for backwards compatibility:
435  new code should use POST.
436
437  This supports a format= argument in the query string. The format=
438  argument, if specified, controls the format of the directory. format=MDMF
439  indicates that the directory should be stored as an MDMF file; format=SDMF
440  indicates that the directory should be stored as an SDMF file. The value of
441  the format= argument is case-insensitive. If no format= argument is
442  given, the directory's format is determined by the default mutable file
443  format, as configured on the Tahoe-LAFS node responding to the request.
444
445 ``POST /uri?t=mkdir-with-children``
446
447  Create a new directory, populated with a set of child nodes, and return its
448  write-cap as the HTTP response body. The new directory is not attached to
449  any other directory: the returned write-cap is the only reference to it.
450
451  The format of the directory can be controlled with the format= argument in
452  the query string, as described above.
453
454  Initial children are provided as the body of the POST form (this is more
455  efficient than doing separate mkdir and set_children operations). If the
456  body is empty, the new directory will be empty. If not empty, the body will
457  be interpreted as a UTF-8 JSON-encoded dictionary of children with which the
458  new directory should be populated, using the same format as would be
459  returned in the 'children' value of the t=json GET request, described below.
460  Each dictionary key should be a child name, and each value should be a list
461  of [TYPE, PROPDICT], where PROPDICT contains "rw_uri", "ro_uri", and
462  "metadata" keys (all others are ignored). For example, the PUT request body
463  could be::
464
465   {
466     "Fran\u00e7ais": [ "filenode", {
467         "ro_uri": "URI:CHK:...",
468         "metadata": {
469           "ctime": 1202777696.7564139,
470           "mtime": 1202777696.7564139,
471           "tahoe": {
472             "linkcrtime": 1202777696.7564139,
473             "linkmotime": 1202777696.7564139
474             } } } ],
475     "subdir":  [ "dirnode", {
476         "rw_uri": "URI:DIR2:...",
477         "ro_uri": "URI:DIR2-RO:...",
478         "metadata": {
479           "ctime": 1202778102.7589991,
480           "mtime": 1202778111.2160511,
481           "tahoe": {
482             "linkcrtime": 1202777696.7564139,
483             "linkmotime": 1202777696.7564139
484           } } } ]
485   }
486
487  For forward-compatibility, a mutable directory can also contain caps in
488  a format that is unknown to the web-API server. When such caps are retrieved
489  from a mutable directory in a "ro_uri" field, they will be prefixed with
490  the string "ro.", indicating that they must not be decoded without
491  checking that they are read-only. The "ro." prefix must not be stripped
492  off without performing this check. (Future versions of the web-API server
493  will perform it where necessary.)
494
495  If both the "rw_uri" and "ro_uri" fields are present in a given PROPDICT,
496  and the web-API server recognizes the rw_uri as a write cap, then it will
497  reset the ro_uri to the corresponding read cap and discard the original
498  contents of ro_uri (in order to ensure that the two caps correspond to the
499  same object and that the ro_uri is in fact read-only). However this may not
500  happen for caps in a format unknown to the web-API server. Therefore, when
501  writing a directory the web-API client should ensure that the contents
502  of "rw_uri" and "ro_uri" for a given PROPDICT are a consistent
503  (write cap, read cap) pair if possible. If the web-API client only has
504  one cap and does not know whether it is a write cap or read cap, then
505  it is acceptable to set "rw_uri" to that cap and omit "ro_uri". The
506  client must not put a write cap into a "ro_uri" field.
507
508  The metadata may have a "no-write" field. If this is set to true in the
509  metadata of a link, it will not be possible to open that link for writing
510  via the SFTP frontend; see FTP-and-SFTP.rst_ for details.  Also, if the
511  "no-write" field is set to true in the metadata of a link to a mutable
512  child, it will cause the link to be diminished to read-only.
513
514  Note that the web-API-using client application must not provide the
515  "Content-Type: multipart/form-data" header that usually accompanies HTML
516  form submissions, since the body is not formatted this way. Doing so will
517  cause a server error as the lower-level code misparses the request body.
518
519  Child file names should each be expressed as a Unicode string, then used as
520  keys of the dictionary. The dictionary should then be converted into JSON,
521  and the resulting string encoded into UTF-8. This UTF-8 bytestring should
522  then be used as the POST body.
523
524 ``POST /uri?t=mkdir-immutable``
525
526  Like t=mkdir-with-children above, but the new directory will be
527  deep-immutable. This means that the directory itself is immutable, and that
528  it can only contain objects that are treated as being deep-immutable, like
529  immutable files, literal files, and deep-immutable directories.
530
531  For forward-compatibility, a deep-immutable directory can also contain caps
532  in a format that is unknown to the web-API server. When such caps are retrieved
533  from a deep-immutable directory in a "ro_uri" field, they will be prefixed
534  with the string "imm.", indicating that they must not be decoded without
535  checking that they are immutable. The "imm." prefix must not be stripped
536  off without performing this check. (Future versions of the web-API server
537  will perform it where necessary.)
538  
539  The cap for each child may be given either in the "rw_uri" or "ro_uri"
540  field of the PROPDICT (not both). If a cap is given in the "rw_uri" field,
541  then the web-API server will check that it is an immutable read-cap of a
542  *known* format, and give an error if it is not. If a cap is given in the
543  "ro_uri" field, then the web-API server will still check whether known
544  caps are immutable, but for unknown caps it will simply assume that the
545  cap can be stored, as described above. Note that an attacker would be
546  able to store any cap in an immutable directory, so this check when
547  creating the directory is only to help non-malicious clients to avoid
548  accidentally giving away more authority than intended.
549
550  A non-empty request body is mandatory, since after the directory is created,
551  it will not be possible to add more children to it.
552
553 ``POST /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir``
554
555 ``PUT /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir``
556
557  Create new directories as necessary to make sure that the named target
558  ($DIRCAP/SUBDIRS../SUBDIR) is a directory. This will create additional
559  intermediate mutable directories as necessary. If the named target directory
560  already exists, this will make no changes to it.
561
562  If the final directory is created, it will be empty.
563
564  This accepts a format= argument in the query string, which controls the
565  format of the named target directory, if it does not already exist. format=
566  is interpreted in the same way as in the POST /uri?t=mkdir form. Note that
567  format= only controls the format of the named target directory;
568  intermediate directories, if created, are created based on the default
569  mutable type, as configured on the Tahoe-LAFS server responding to the
570  request.
571
572  This operation will return an error if a blocking file is present at any of
573  the parent names, preventing the server from creating the necessary parent
574  directory; or if it would require changing an immutable directory.
575
576  The write-cap of the new directory will be returned as the HTTP response
577  body.
578
579 ``POST /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir-with-children``
580
581  Like /uri?t=mkdir-with-children, but the final directory is created as a
582  child of an existing mutable directory. This will create additional
583  intermediate mutable directories as necessary. If the final directory is
584  created, it will be populated with initial children from the POST request
585  body, as described above.
586
587  This accepts a format= argument in the query string, which controls the
588  format of the target directory, if the target directory is created as part
589  of the operation. format= is interpreted in the same way as in the POST/
590  uri?t=mkdir-with-children operation. Note that format= only controls the
591  format of the named target directory; intermediate directories, if created,
592  are created using the default mutable type setting, as configured on the
593  Tahoe-LAFS server responding to the request.
594  
595  This operation will return an error if a blocking file is present at any of
596  the parent names, preventing the server from creating the necessary parent
597  directory; or if it would require changing an immutable directory; or if
598  the immediate parent directory already has a a child named SUBDIR.
599
600 ``POST /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir-immutable``
601
602  Like /uri?t=mkdir-immutable, but the final directory is created as a child
603  of an existing mutable directory. The final directory will be deep-immutable,
604  and will be populated with the children specified as a JSON dictionary in
605  the POST request body.
606
607  In Tahoe 1.6 this operation creates intermediate mutable directories if
608  necessary, but that behaviour should not be relied on; see ticket #920.
609
610  This operation will return an error if the parent directory is immutable,
611  or already has a child named SUBDIR.
612
613 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir&name=NAME``
614
615  Create a new empty mutable directory and attach it to the given existing
616  directory. This will create additional intermediate directories as necessary.
617
618  This accepts a format= argument in the query string, which controls the
619  format of the named target directory, if it does not already exist. format=
620  is interpreted in the same way as in the POST /uri?t=mkdir form. Note that
621  format= only controls the format of the named target directory;
622  intermediate directories, if created, are created based on the default
623  mutable type, as configured on the Tahoe-LAFS server responding to the
624  request.
625
626  This operation will return an error if a blocking file is present at any of
627  the parent names, preventing the server from creating the necessary parent
628  directory, or if it would require changing any immutable directory.
629
630  The URL of this operation points to the parent of the bottommost new directory,
631  whereas the /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir operation above has a URL
632  that points directly to the bottommost new directory.
633
634 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir-with-children&name=NAME``
635
636  Like /uri/$DIRCAP/[SUBDIRS../]?t=mkdir&name=NAME, but the new directory will
637  be populated with initial children via the POST request body. This command
638  will create additional intermediate mutable directories as necessary.
639
640  This accepts a format= argument in the query string, which controls the
641  format of the target directory, if the target directory is created as part
642  of the operation. format= is interpreted in the same way as in the POST/
643  uri?t=mkdir-with-children operation. Note that format= only controls the
644  format of the named target directory; intermediate directories, if created,
645  are created using the default mutable type setting, as configured on the
646  Tahoe-LAFS server responding to the request.
647
648  This operation will return an error if a blocking file is present at any of
649  the parent names, preventing the server from creating the necessary parent
650  directory; or if it would require changing an immutable directory; or if
651  the immediate parent directory already has a a child named NAME.
652
653  Note that the name= argument must be passed as a queryarg, because the POST
654  request body is used for the initial children JSON. 
655
656 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir-immutable&name=NAME``
657
658  Like /uri/$DIRCAP/[SUBDIRS../]?t=mkdir-with-children&name=NAME, but the
659  final directory will be deep-immutable. The children are specified as a
660  JSON dictionary in the POST request body. Again, the name= argument must be
661  passed as a queryarg.
662
663  In Tahoe 1.6 this operation creates intermediate mutable directories if
664  necessary, but that behaviour should not be relied on; see ticket #920.
665
666  This operation will return an error if the parent directory is immutable,
667  or already has a child named NAME.
668
669 .. _FTP-and-SFTP.rst: FTP-and-SFTP.rst
670
671
672 Getting Information About a File Or Directory (as JSON)
673 -------------------------------------------------------
674
675 ``GET /uri/$FILECAP?t=json``
676
677 ``GET /uri/$DIRCAP?t=json``
678
679 ``GET /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=json``
680
681 ``GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=json``
682
683  This returns a machine-parseable JSON-encoded description of the given
684  object. The JSON always contains a list, and the first element of the list is
685  always a flag that indicates whether the referenced object is a file or a
686  directory. If it is a capability to a file, then the information includes
687  file size and URI, like this::
688
689   GET /uri/$FILECAP?t=json :
690
691    [ "filenode", {
692       "ro_uri": file_uri,
693       "verify_uri": verify_uri,
694       "size": bytes,
695       "mutable": false,
696       "format": "CHK"
697      } ]
698
699  If it is a capability to a directory followed by a path from that directory
700  to a file, then the information also includes metadata from the link to the
701  file in the parent directory, like this::
702
703   GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=json
704
705    [ "filenode", {
706       "ro_uri": file_uri,
707       "verify_uri": verify_uri,
708       "size": bytes,
709       "mutable": false,
710       "format": "CHK",
711       "metadata": {
712        "ctime": 1202777696.7564139,
713        "mtime": 1202777696.7564139,
714        "tahoe": {
715         "linkcrtime": 1202777696.7564139,
716         "linkmotime": 1202777696.7564139
717        } } } ]
718
719  If it is a directory, then it includes information about the children of
720  this directory, as a mapping from child name to a set of data about the
721  child (the same data that would appear in a corresponding GET?t=json of the
722  child itself). The child entries also include metadata about each child,
723  including link-creation- and link-change- timestamps. The output looks like
724  this::
725
726   GET /uri/$DIRCAP?t=json :
727   GET /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=json :
728
729    [ "dirnode", {
730      "rw_uri": read_write_uri,
731      "ro_uri": read_only_uri,
732      "verify_uri": verify_uri,
733      "mutable": true,
734      "format": "SDMF",
735      "children": {
736       "foo.txt": [ "filenode",
737                    {
738                      "ro_uri": uri,
739                      "size": bytes,
740                      "metadata": {
741                        "ctime": 1202777696.7564139,
742                        "mtime": 1202777696.7564139,
743                        "tahoe": {
744                          "linkcrtime": 1202777696.7564139,
745                          "linkmotime": 1202777696.7564139
746                        } } } ],
747       "subdir":  [ "dirnode",
748                    {
749                      "rw_uri": rwuri,
750                      "ro_uri": rouri,
751                      "metadata": {
752                        "ctime": 1202778102.7589991,
753                        "mtime": 1202778111.2160511,
754                        "tahoe": {
755                          "linkcrtime": 1202777696.7564139,
756                          "linkmotime": 1202777696.7564139
757                        } } } ]
758       } } ]
759
760  In the above example, note how 'children' is a dictionary in which the keys
761  are child names and the values depend upon whether the child is a file or a
762  directory. The value is mostly the same as the JSON representation of the
763  child object (except that directories do not recurse -- the "children"
764  entry of the child is omitted, and the directory view includes the metadata
765  that is stored on the directory edge).
766
767  The rw_uri field will be present in the information about a directory
768  if and only if you have read-write access to that directory. The verify_uri
769  field will be present if and only if the object has a verify-cap
770  (non-distributed LIT files do not have verify-caps).
771  
772  If the cap is of an unknown format, then the file size and verify_uri will
773  not be available::
774
775   GET /uri/$UNKNOWNCAP?t=json :
776
777    [ "unknown", {
778        "ro_uri": unknown_read_uri
779        } ]
780
781   GET /uri/$DIRCAP/[SUBDIRS../]UNKNOWNCHILDNAME?t=json :
782
783    [ "unknown", {
784        "rw_uri": unknown_write_uri,
785        "ro_uri": unknown_read_uri,
786        "mutable": true,
787        "metadata": {
788          "ctime": 1202777696.7564139,
789          "mtime": 1202777696.7564139,
790          "tahoe": {
791            "linkcrtime": 1202777696.7564139,
792            "linkmotime": 1202777696.7564139
793          } } } ]
794
795  As in the case of file nodes, the metadata will only be present when the
796  capability is to a directory followed by a path. The "mutable" field is also
797  not always present; when it is absent, the mutability of the object is not
798  known.
799
800 About the metadata
801 ``````````````````
802
803 The value of the 'tahoe':'linkmotime' key is updated whenever a link to a
804 child is set. The value of the 'tahoe':'linkcrtime' key is updated whenever
805 a link to a child is created -- i.e. when there was not previously a link
806 under that name.
807
808 Note however, that if the edge in the Tahoe filesystem points to a mutable
809 file and the contents of that mutable file is changed, then the
810 'tahoe':'linkmotime' value on that edge will *not* be updated, since the
811 edge itself wasn't updated -- only the mutable file was.
812
813 The timestamps are represented as a number of seconds since the UNIX epoch
814 (1970-01-01 00:00:00 UTC), with leap seconds not being counted in the long
815 term.
816
817 In Tahoe earlier than v1.4.0, 'mtime' and 'ctime' keys were populated
818 instead of the 'tahoe':'linkmotime' and 'tahoe':'linkcrtime' keys. Starting
819 in Tahoe v1.4.0, the 'linkmotime'/'linkcrtime' keys in the 'tahoe' sub-dict
820 are populated. However, prior to Tahoe v1.7beta, a bug caused the 'tahoe'
821 sub-dict to be deleted by web-API requests in which new metadata is
822 specified, and not to be added to existing child links that lack it.
823
824 From Tahoe v1.7.0 onward, the 'mtime' and 'ctime' fields are no longer
825 populated or updated (see ticket #924), except by "tahoe backup" as
826 explained below. For backward compatibility, when an existing link is
827 updated and 'tahoe':'linkcrtime' is not present in the previous metadata
828 but 'ctime' is, the old value of 'ctime' is used as the new value of
829 'tahoe':'linkcrtime'.
830
831 The reason we added the new fields in Tahoe v1.4.0 is that there is a
832 "set_children" API (described below) which you can use to overwrite the
833 values of the 'mtime'/'ctime' pair, and this API is used by the
834 "tahoe backup" command (in Tahoe v1.3.0 and later) to set the 'mtime' and
835 'ctime' values when backing up files from a local filesystem into the
836 Tahoe filesystem. As of Tahoe v1.4.0, the set_children API cannot be used
837 to set anything under the 'tahoe' key of the metadata dict -- if you
838 include 'tahoe' keys in your 'metadata' arguments then it will silently
839 ignore those keys.
840
841 Therefore, if the 'tahoe' sub-dict is present, you can rely on the
842 'linkcrtime' and 'linkmotime' values therein to have the semantics described
843 above. (This is assuming that only official Tahoe clients have been used to
844 write those links, and that their system clocks were set to what you expected
845 -- there is nothing preventing someone from editing their Tahoe client or
846 writing their own Tahoe client which would overwrite those values however
847 they like, and there is nothing to constrain their system clock from taking
848 any value.)
849
850 When an edge is created or updated by "tahoe backup", the 'mtime' and
851 'ctime' keys on that edge are set as follows:
852
853 * 'mtime' is set to the timestamp read from the local filesystem for the
854   "mtime" of the local file in question, which means the last time the
855   contents of that file were changed.
856
857 * On Windows, 'ctime' is set to the creation timestamp for the file
858   read from the local filesystem. On other platforms, 'ctime' is set to
859   the UNIX "ctime" of the local file, which means the last time that
860   either the contents or the metadata of the local file was changed.
861
862 There are several ways that the 'ctime' field could be confusing: 
863
864 1. You might be confused about whether it reflects the time of the creation
865    of a link in the Tahoe filesystem (by a version of Tahoe < v1.7.0) or a
866    timestamp copied in by "tahoe backup" from a local filesystem.
867
868 2. You might be confused about whether it is a copy of the file creation
869    time (if "tahoe backup" was run on a Windows system) or of the last
870    contents-or-metadata change (if "tahoe backup" was run on a different
871    operating system).
872
873 3. You might be confused by the fact that changing the contents of a
874    mutable file in Tahoe doesn't have any effect on any links pointing at
875    that file in any directories, although "tahoe backup" sets the link
876    'ctime'/'mtime' to reflect timestamps about the local file corresponding
877    to the Tahoe file to which the link points.
878
879 4. Also, quite apart from Tahoe, you might be confused about the meaning
880    of the "ctime" in UNIX local filesystems, which people sometimes think
881    means file creation time, but which actually means, in UNIX local
882    filesystems, the most recent time that the file contents or the file
883    metadata (such as owner, permission bits, extended attributes, etc.)
884    has changed. Note that although "ctime" does not mean file creation time
885    in UNIX, links created by a version of Tahoe prior to v1.7.0, and never
886    written by "tahoe backup", will have 'ctime' set to the link creation
887    time.
888
889
890 Attaching an Existing File or Directory by its read- or write-cap
891 -----------------------------------------------------------------
892
893 ``PUT /uri/$DIRCAP/[SUBDIRS../]CHILDNAME?t=uri``
894
895  This attaches a child object (either a file or directory) to a specified
896  location in the virtual filesystem. The child object is referenced by its
897  read- or write- cap, as provided in the HTTP request body. This will create
898  intermediate directories as necessary.
899
900  This is similar to a UNIX hardlink: by referencing a previously-uploaded file
901  (or previously-created directory) instead of uploading/creating a new one,
902  you can create two references to the same object.
903
904  The read- or write- cap of the child is provided in the body of the HTTP
905  request, and this same cap is returned in the response body.
906
907  The default behavior is to overwrite any existing object at the same
908  location. To prevent this (and make the operation return an error instead
909  of overwriting), add a "replace=false" argument, as "?t=uri&replace=false".
910  With replace=false, this operation will return an HTTP 409 "Conflict" error
911  if there is already an object at the given location, rather than
912  overwriting the existing object. To allow the operation to overwrite a
913  file, but return an error when trying to overwrite a directory, use
914  "replace=only-files" (this behavior is closer to the traditional UNIX "mv"
915  command). Note that "true", "t", and "1" are all synonyms for "True", and
916  "false", "f", and "0" are synonyms for "False", and the parameter is
917  case-insensitive.
918  
919  Note that this operation does not take its child cap in the form of
920  separate "rw_uri" and "ro_uri" fields. Therefore, it cannot accept a
921  child cap in a format unknown to the web-API server, unless its URI
922  starts with "ro." or "imm.". This restriction is necessary because the
923  server is not able to attenuate an unknown write cap to a read cap.
924  Unknown URIs starting with "ro." or "imm.", on the other hand, are
925  assumed to represent read caps. The client should not prefix a write
926  cap with "ro." or "imm." and pass it to this operation, since that
927  would result in granting the cap's write authority to holders of the
928  directory read cap.
929
930
931 Adding Multiple Files or Directories to a Parent Directory at Once
932 ------------------------------------------------------------------
933
934 ``POST /uri/$DIRCAP/[SUBDIRS..]?t=set_children``
935
936 ``POST /uri/$DIRCAP/[SUBDIRS..]?t=set-children``    (Tahoe >= v1.6)
937
938  This command adds multiple children to a directory in a single operation.
939  It reads the request body and interprets it as a JSON-encoded description
940  of the child names and read/write-caps that should be added.
941
942  The body should be a JSON-encoded dictionary, in the same format as the
943  "children" value returned by the "GET /uri/$DIRCAP?t=json" operation
944  described above. In this format, each key is a child names, and the
945  corresponding value is a tuple of (type, childinfo). "type" is ignored, and
946  "childinfo" is a dictionary that contains "rw_uri", "ro_uri", and
947  "metadata" keys. You can take the output of "GET /uri/$DIRCAP1?t=json" and
948  use it as the input to "POST /uri/$DIRCAP2?t=set_children" to make DIR2
949  look very much like DIR1 (except for any existing children of DIR2 that
950  were not overwritten, and any existing "tahoe" metadata keys as described
951  below).
952
953  When the set_children request contains a child name that already exists in
954  the target directory, this command defaults to overwriting that child with
955  the new value (both child cap and metadata, but if the JSON data does not
956  contain a "metadata" key, the old child's metadata is preserved). The
957  command takes a boolean "overwrite=" query argument to control this
958  behavior. If you use "?t=set_children&overwrite=false", then an attempt to
959  replace an existing child will instead cause an error.
960
961  Any "tahoe" key in the new child's "metadata" value is ignored. Any
962  existing "tahoe" metadata is preserved. The metadata["tahoe"] value is
963  reserved for metadata generated by the tahoe node itself. The only two keys
964  currently placed here are "linkcrtime" and "linkmotime". For details, see
965  the section above entitled "Getting Information About a File Or Directory (as
966  JSON)", in the "About the metadata" subsection.
967  
968  Note that this command was introduced with the name "set_children", which
969  uses an underscore rather than a hyphen as other multi-word command names
970  do. The variant with a hyphen is now accepted, but clients that desire
971  backward compatibility should continue to use "set_children".
972
973
974 Unlinking a File or Directory
975 -----------------------------
976
977 ``DELETE /uri/$DIRCAP/[SUBDIRS../]CHILDNAME``
978
979  This removes the given name from its parent directory. CHILDNAME is the
980  name to be removed, and $DIRCAP/SUBDIRS.. indicates the directory that will
981  be modified.
982
983  Note that this does not actually delete the file or directory that the name
984  points to from the tahoe grid -- it only unlinks the named reference from
985  this directory. If there are other names in this directory or in other
986  directories that point to the resource, then it will remain accessible
987  through those paths. Even if all names pointing to this object are removed
988  from their parent directories, then someone with possession of its read-cap
989  can continue to access the object through that cap.
990
991  The object will only become completely unreachable once 1: there are no
992  reachable directories that reference it, and 2: nobody is holding a read-
993  or write- cap to the object. (This behavior is very similar to the way
994  hardlinks and anonymous files work in traditional UNIX filesystems).
995
996  This operation will not modify more than a single directory. Intermediate
997  directories which were implicitly created by PUT or POST methods will *not*
998  be automatically removed by DELETE.
999
1000  This method returns the file- or directory- cap of the object that was just
1001  removed.
1002
1003
1004 Browser Operations: Human-oriented interfaces
1005 =============================================
1006
1007 This section describes the HTTP operations that provide support for humans
1008 running a web browser. Most of these operations use HTML forms that use POST
1009 to drive the Tahoe node. This section is intended for HTML authors who want
1010 to write web pages that contain forms and buttons which manipulate the Tahoe
1011 filesystem.
1012
1013 Note that for all POST operations, the arguments listed can be provided
1014 either as URL query arguments or as form body fields. URL query arguments are
1015 separated from the main URL by "?", and from each other by "&". For example,
1016 "POST /uri/$DIRCAP?t=upload&mutable=true". Form body fields are usually
1017 specified by using <input type="hidden"> elements. For clarity, the
1018 descriptions below display the most significant arguments as URL query args.
1019
1020
1021 Viewing a Directory (as HTML)
1022 -----------------------------
1023
1024 ``GET /uri/$DIRCAP/[SUBDIRS../]``
1025
1026  This returns an HTML page, intended to be displayed to a human by a web
1027  browser, which contains HREF links to all files and directories reachable
1028  from this directory. These HREF links do not have a t= argument, meaning
1029  that a human who follows them will get pages also meant for a human. It also
1030  contains forms to upload new files, and to unlink files and directories
1031  from their parent directory. Those forms use POST methods to do their job.
1032
1033
1034 Viewing/Downloading a File
1035 --------------------------
1036
1037 ``GET /uri/$FILECAP``
1038
1039 ``GET /uri/$DIRCAP/[SUBDIRS../]FILENAME``
1040
1041  This will retrieve the contents of the given file. The HTTP response body
1042  will contain the sequence of bytes that make up the file.
1043
1044  If you want the HTTP response to include a useful Content-Type header,
1045  either use the second form (which starts with a $DIRCAP), or add a
1046  "filename=foo" query argument, like "GET /uri/$FILECAP?filename=foo.jpg".
1047  The bare "GET /uri/$FILECAP" does not give the Tahoe node enough information
1048  to determine a Content-Type (since Tahoe immutable files are merely
1049  sequences of bytes, not typed+named file objects).
1050
1051  If the URL has both filename= and "save=true" in the query arguments, then
1052  the server to add a "Content-Disposition: attachment" header, along with a
1053  filename= parameter. When a user clicks on such a link, most browsers will
1054  offer to let the user save the file instead of displaying it inline (indeed,
1055  most browsers will refuse to display it inline). "true", "t", "1", and other
1056  case-insensitive equivalents are all treated the same.
1057
1058  Character-set handling in URLs and HTTP headers is a dubious art [1]_. For
1059  maximum compatibility, Tahoe simply copies the bytes from the filename=
1060  argument into the Content-Disposition header's filename= parameter, without
1061  trying to interpret them in any particular way.
1062
1063
1064 ``GET /named/$FILECAP/FILENAME``
1065
1066  This is an alternate download form which makes it easier to get the correct
1067  filename. The Tahoe server will provide the contents of the given file, with
1068  a Content-Type header derived from the given filename. This form is used to
1069  get browsers to use the "Save Link As" feature correctly, and also helps
1070  command-line tools like "wget" and "curl" use the right filename. Note that
1071  this form can *only* be used with file caps; it is an error to use a
1072  directory cap after the /named/ prefix.
1073
1074  URLs may also use /file/$FILECAP/FILENAME as a synonym for
1075  /named/$FILECAP/FILENAME.
1076
1077 Getting Information About a File Or Directory (as HTML)
1078 -------------------------------------------------------
1079
1080 ``GET /uri/$FILECAP?t=info``
1081
1082 ``GET /uri/$DIRCAP/?t=info``
1083
1084 ``GET /uri/$DIRCAP/[SUBDIRS../]SUBDIR/?t=info``
1085
1086 ``GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=info``
1087
1088  This returns a human-oriented HTML page with more detail about the selected
1089  file or directory object. This page contains the following items:
1090
1091  * object size
1092  * storage index
1093  * JSON representation
1094  * raw contents (text/plain)
1095  * access caps (URIs): verify-cap, read-cap, write-cap (for mutable objects)
1096  * check/verify/repair form
1097  * deep-check/deep-size/deep-stats/manifest (for directories)
1098  * replace-contents form (for mutable files)
1099
1100
1101 Creating a Directory
1102 --------------------
1103
1104 ``POST /uri?t=mkdir``
1105
1106  This creates a new empty directory, but does not attach it to the virtual
1107  filesystem.
1108
1109  If a "redirect_to_result=true" argument is provided, then the HTTP response
1110  will cause the web browser to be redirected to a /uri/$DIRCAP page that
1111  gives access to the newly-created directory. If you bookmark this page,
1112  you'll be able to get back to the directory again in the future. This is the
1113  recommended way to start working with a Tahoe server: create a new unlinked
1114  directory (using redirect_to_result=true), then bookmark the resulting
1115  /uri/$DIRCAP page. There is a "create directory" button on the Welcome page
1116  to invoke this action.
1117
1118  This accepts a format= argument in the query string. Refer to the
1119  documentation of the PUT /uri?t=mkdir operation in `Creating A
1120  New Directory`_ for information on the behavior of the format= argument.
1121
1122  If "redirect_to_result=true" is not provided (or is given a value of
1123  "false"), then the HTTP response body will simply be the write-cap of the
1124  new directory.
1125
1126 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir&name=CHILDNAME``
1127
1128  This creates a new empty directory as a child of the designated SUBDIR. This
1129  will create additional intermediate directories as necessary.
1130
1131  This accepts a format= argument in the query string. Refer to the
1132  documentation of POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir&name=CHILDNAME in
1133  `Creating a New Directory`_ for information on the behavior of the format=
1134  argument.
1135
1136  If a "when_done=URL" argument is provided, the HTTP response will cause the
1137  web browser to redirect to the given URL. This provides a convenient way to
1138  return the browser to the directory that was just modified. Without a
1139  when_done= argument, the HTTP response will simply contain the write-cap of
1140  the directory that was just created.
1141
1142
1143 Uploading a File
1144 ----------------
1145
1146 ``POST /uri?t=upload``
1147
1148  This uploads a file, and produces a file-cap for the contents, but does not
1149  attach the file into the filesystem. No directories will be modified by
1150  this operation.
1151
1152  The file must be provided as the "file" field of an HTML encoded form body,
1153  produced in response to an HTML form like this::
1154  
1155   <form action="/uri" method="POST" enctype="multipart/form-data">
1156    <input type="hidden" name="t" value="upload" />
1157    <input type="file" name="file" />
1158    <input type="submit" value="Upload Unlinked" />
1159   </form>
1160
1161  If a "when_done=URL" argument is provided, the response body will cause the
1162  browser to redirect to the given URL. If the when_done= URL has the string
1163  "%(uri)s" in it, that string will be replaced by a URL-escaped form of the
1164  newly created file-cap. (Note that without this substitution, there is no
1165  way to access the file that was just uploaded).
1166
1167  The default (in the absence of when_done=) is to return an HTML page that
1168  describes the results of the upload. This page will contain information
1169  about which storage servers were used for the upload, how long each
1170  operation took, etc.
1171
1172  This accepts format= and mutable=true query string arguments. Refer to
1173  `Writing/Uploading a File`_ for information on the behavior of format= and
1174  mutable=true.
1175
1176 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=upload``
1177
1178  This uploads a file, and attaches it as a new child of the given directory,
1179  which must be mutable. The file must be provided as the "file" field of an
1180  HTML-encoded form body, produced in response to an HTML form like this::
1181  
1182   <form action="." method="POST" enctype="multipart/form-data">
1183    <input type="hidden" name="t" value="upload" />
1184    <input type="file" name="file" />
1185    <input type="submit" value="Upload" />
1186   </form>
1187
1188  A "name=" argument can be provided to specify the new child's name,
1189  otherwise it will be taken from the "filename" field of the upload form
1190  (most web browsers will copy the last component of the original file's
1191  pathname into this field). To avoid confusion, name= is not allowed to
1192  contain a slash.
1193
1194  If there is already a child with that name, and it is a mutable file, then
1195  its contents are replaced with the data being uploaded. If it is not a
1196  mutable file, the default behavior is to remove the existing child before
1197  creating a new one. To prevent this (and make the operation return an error
1198  instead of overwriting the old child), add a "replace=false" argument, as
1199  "?t=upload&replace=false". With replace=false, this operation will return an
1200  HTTP 409 "Conflict" error if there is already an object at the given
1201  location, rather than overwriting the existing object. Note that "true",
1202  "t", and "1" are all synonyms for "True", and "false", "f", and "0" are
1203  synonyms for "False". the parameter is case-insensitive.
1204
1205  This will create additional intermediate directories as necessary, although
1206  since it is expected to be triggered by a form that was retrieved by "GET
1207  /uri/$DIRCAP/[SUBDIRS../]", it is likely that the parent directory will
1208  already exist.
1209
1210  This accepts format= and mutable=true query string arguments. Refer to
1211  `Writing/Uploading a File`_ for information on the behavior of format= and
1212  mutable=true.
1213
1214  If a "when_done=URL" argument is provided, the HTTP response will cause the
1215  web browser to redirect to the given URL. This provides a convenient way to
1216  return the browser to the directory that was just modified. Without a
1217  when_done= argument, the HTTP response will simply contain the file-cap of
1218  the file that was just uploaded (a write-cap for mutable files, or a
1219  read-cap for immutable files).
1220
1221 ``POST /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=upload``
1222
1223  This also uploads a file and attaches it as a new child of the given
1224  directory, which must be mutable. It is a slight variant of the previous
1225  operation, as the URL refers to the target file rather than the parent
1226  directory. It is otherwise identical: this accepts mutable= and when_done=
1227  arguments too.
1228
1229 ``POST /uri/$FILECAP?t=upload``
1230
1231  This modifies the contents of an existing mutable file in-place. An error is
1232  signalled if $FILECAP does not refer to a mutable file. It behaves just like
1233  the "PUT /uri/$FILECAP" form, but uses a POST for the benefit of HTML forms
1234  in a web browser.
1235
1236
1237 Attaching An Existing File Or Directory (by URI)
1238 ------------------------------------------------
1239
1240 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=uri&name=CHILDNAME&uri=CHILDCAP``
1241
1242  This attaches a given read- or write- cap "CHILDCAP" to the designated
1243  directory, with a specified child name. This behaves much like the PUT t=uri
1244  operation, and is a lot like a UNIX hardlink. It is subject to the same
1245  restrictions as that operation on the use of cap formats unknown to the
1246  web-API server.
1247
1248  This will create additional intermediate directories as necessary, although
1249  since it is expected to be triggered by a form that was retrieved by "GET
1250  /uri/$DIRCAP/[SUBDIRS../]", it is likely that the parent directory will
1251  already exist.
1252
1253  This accepts the same replace= argument as POST t=upload.
1254
1255
1256 Unlinking a Child
1257 -----------------
1258
1259 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=delete&name=CHILDNAME``
1260
1261 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=unlink&name=CHILDNAME``    (Tahoe >= v1.9)
1262
1263  This instructs the node to remove a child object (file or subdirectory) from
1264  the given directory, which must be mutable. Note that the entire subtree is
1265  unlinked from the parent. Unlike deleting a subdirectory in a UNIX local
1266  filesystem, the subtree need not be empty; if it isn't, then other references
1267  into the subtree will see that the child subdirectories are not modified by
1268  this operation. Only the link from the given directory to its child is severed.
1269
1270  In Tahoe-LAFS v1.9.0 and later, t=unlink can be used as a synonym for t=delete.
1271  If interoperability with older web-API servers is required, t=delete should
1272  be used.
1273
1274
1275 Renaming a Child
1276 ----------------
1277
1278 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=rename&from_name=OLD&to_name=NEW``
1279
1280  This instructs the node to rename a child of the given directory, which must
1281  be mutable. This has a similar effect to removing the child, then adding the
1282  same child-cap under the new name, except that it preserves metadata. This
1283  operation cannot move the child to a different directory.
1284
1285  The default behavior is to overwrite any existing link at the destination
1286  (replace=true). To prevent this (and make the operation return an error
1287  instead of overwriting), add a "replace=false" argument. With replace=false,
1288  this operation will return an HTTP 409 "Conflict" error if the destination
1289  is not the same link as the source and there is already a link at the
1290  destination, rather than overwriting the existing link. To allow the
1291  operation to overwrite a link to a file, but return an HTTP 409 error when
1292  trying to overwrite a link to a directory, use "replace=only-files" (this
1293  behavior is closer to the traditional UNIX "mv" command). Note that "true",
1294  "t", and "1" are all synonyms for "True"; "false", "f", and "0" are synonyms
1295  for "False"; and the parameter is case-insensitive.
1296
1297
1298 Relinking ("Moving") a Child
1299 ----------------------------
1300
1301 ``POST /uri/$DIRCAP/[SUBDIRS../]?t=relink&from_name=OLD&to_dir=$NEWDIRCAP/[NEWSUBDIRS../]&to_name=NEW``
1302  ``[&replace=true|false|only-files]``    (Tahoe >= v1.10)
1303
1304  This instructs the node to move a child of the given source directory, into
1305  a different directory and/or to a different name. The command is named
1306  ``relink`` because what it does is add a new link to the child from the new
1307  location, then remove the old link. Nothing is actually "moved": the child
1308  is still reachable through any path from which it was formerly reachable,
1309  and the storage space occupied by its ciphertext is not affected.
1310
1311  The source and destination directories must be writeable. If {{{to_dir}}} is
1312  not present, the child link is renamed within the same directory. If
1313  {{{to_name}}} is not present then it defaults to {{{from_name}}}. If the
1314  destination link (directory and name) is the same as the source link, the
1315  operation has no effect.
1316
1317  Metadata from the source directory entry is preserved. Multiple levels of
1318  descent in the source and destination paths are supported.
1319
1320  This operation will return an HTTP 404 "Not Found" error if
1321  ``$DIRCAP/[SUBDIRS../]``, the child being moved, or the destination
1322  directory does not exist. It will return an HTTP 400 "Bad Request" error
1323  if any entry in the source or destination paths is not a directory.
1324
1325  The default behavior is to overwrite any existing link at the destination
1326  (replace=true). To prevent this (and make the operation return an error
1327  instead of overwriting), add a "replace=false" argument. With replace=false,
1328  this operation will return an HTTP 409 "Conflict" error if the destination
1329  is not the same link as the source and there is already a link at the
1330  destination, rather than overwriting the existing link. To allow the
1331  operation to overwrite a link to a file, but return an HTTP 409 error when
1332  trying to overwrite a link to a directory, use "replace=only-files" (this
1333  behavior is closer to the traditional UNIX "mv" command). Note that "true",
1334  "t", and "1" are all synonyms for "True"; "false", "f", and "0" are synonyms
1335  for "False"; and the parameter is case-insensitive.
1336
1337  When relinking into a different directory, for safety, the child link is
1338  not removed from the old directory until it has been successfully added to
1339  the new directory. This implies that in case of a crash or failure, the
1340  link to the child will not be lost, but it could be linked at both the old
1341  and new locations.
1342
1343  The source link should not be the same as any link (directory and child name)
1344  in the ``to_dir`` path. This restriction is not enforced, but it may be
1345  enforced in a future version. If it were violated then the result would be
1346  to create a cycle in the directory structure that is not necessarily reachable
1347  from the root of the destination path (``$NEWDIRCAP``), which could result in
1348  data loss, as described in ticket `#943`_.
1349
1350 .. _`#943`: https://tahoe-lafs.org/trac/tahoe-lafs/ticket/943
1351
1352
1353 Other Utilities
1354 ---------------
1355
1356 ``GET /uri?uri=$CAP``
1357
1358   This causes a redirect to /uri/$CAP, and retains any additional query
1359   arguments (like filename= or save=). This is for the convenience of web
1360   forms which allow the user to paste in a read- or write- cap (obtained
1361   through some out-of-band channel, like IM or email).
1362
1363   Note that this form merely redirects to the specific file or directory
1364   indicated by the $CAP: unlike the GET /uri/$DIRCAP form, you cannot
1365   traverse to children by appending additional path segments to the URL.
1366
1367 ``GET /uri/$DIRCAP/[SUBDIRS../]?t=rename-form&name=$CHILDNAME``
1368
1369   This provides a useful facility to browser-based user interfaces. It
1370   returns a page containing a form targetting the "POST $DIRCAP t=rename"
1371   functionality described above, with the provided $CHILDNAME present in the
1372   'from_name' field of that form. I.e. this presents a form offering to
1373   rename $CHILDNAME, requesting the new name, and submitting POST rename.
1374   This same URL format can also be used with "move-form" with the expected
1375   results.
1376
1377 ``GET /uri/$DIRCAP/[SUBDIRS../]CHILDNAME?t=uri``
1378
1379  This returns the file- or directory- cap for the specified object.
1380
1381 ``GET /uri/$DIRCAP/[SUBDIRS../]CHILDNAME?t=readonly-uri``
1382
1383  This returns a read-only file- or directory- cap for the specified object.
1384  If the object is an immutable file, this will return the same value as
1385  t=uri.
1386
1387
1388 Debugging and Testing Features
1389 ------------------------------
1390
1391 These URLs are less-likely to be helpful to the casual Tahoe user, and are
1392 mainly intended for developers.
1393
1394 ``POST $URL?t=check``
1395
1396  This triggers the FileChecker to determine the current "health" of the
1397  given file or directory, by counting how many shares are available. The
1398  page that is returned will display the results. This can be used as a "show
1399  me detailed information about this file" page.
1400
1401  If a verify=true argument is provided, the node will perform a more
1402  intensive check, downloading and verifying every single bit of every share.
1403
1404  If an add-lease=true argument is provided, the node will also add (or
1405  renew) a lease to every share it encounters. Each lease will keep the share
1406  alive for a certain period of time (one month by default). Once the last
1407  lease expires or is explicitly cancelled, the storage server is allowed to
1408  delete the share.
1409
1410  If an output=JSON argument is provided, the response will be
1411  machine-readable JSON instead of human-oriented HTML. The data is a
1412  dictionary with the following keys::
1413
1414   storage-index: a base32-encoded string with the objects's storage index,
1415                  or an empty string for LIT files
1416   summary: a string, with a one-line summary of the stats of the file
1417   results: a dictionary that describes the state of the file. For LIT files,
1418            this dictionary has only the 'healthy' key, which will always be
1419            True. For distributed files, this dictionary has the following
1420            keys:
1421     count-happiness: the servers-of-happiness level of the file, as
1422                      defined in `docs/specifications/servers-of-happiness.rst`_.
1423     count-shares-good: the number of good shares that were found
1424     count-shares-needed: 'k', the number of shares required for recovery
1425     count-shares-expected: 'N', the number of total shares generated
1426     count-good-share-hosts: the number of distinct storage servers with
1427                             good shares. Note that a high value does not
1428                             necessarily imply good share distribution,
1429                             because some of these servers may only hold
1430                             duplicate shares.
1431     count-wrong-shares: for mutable files, the number of shares for
1432                         versions other than the 'best' one (highest
1433                         sequence number, highest roothash). These are
1434                         either old, or created by an uncoordinated or
1435                         not fully successful write.
1436     count-recoverable-versions: for mutable files, the number of
1437                                 recoverable versions of the file. For
1438                                 a healthy file, this will equal 1.
1439     count-unrecoverable-versions: for mutable files, the number of
1440                                   unrecoverable versions of the file.
1441                                   For a healthy file, this will be 0.
1442     count-corrupt-shares: the number of shares with integrity failures
1443     list-corrupt-shares: a list of "share locators", one for each share
1444                          that was found to be corrupt. Each share locator
1445                          is a list of (serverid, storage_index, sharenum).
1446     servers-responding: list of base32-encoded storage server identifiers,
1447                         one for each server which responded to the share
1448                         query.
1449     healthy: (bool) True if the file is completely healthy, False otherwise.
1450              Healthy files have at least N good shares. Overlapping shares
1451              do not currently cause a file to be marked unhealthy. If there
1452              are at least N good shares, then corrupt shares do not cause the
1453              file to be marked unhealthy, although the corrupt shares will be
1454              listed in the results (list-corrupt-shares) and should be manually
1455              removed to wasting time in subsequent downloads (as the
1456              downloader rediscovers the corruption and uses alternate shares).
1457              Future compatibility: the meaning of this field may change to
1458              reflect whether the servers-of-happiness criterion is met
1459              (see ticket #614).
1460     sharemap: dict mapping share identifier to list of serverids
1461               (base32-encoded strings). This indicates which servers are
1462               holding which shares. For immutable files, the shareid is
1463               an integer (the share number, from 0 to N-1). For
1464               immutable files, it is a string of the form
1465               'seq%d-%s-sh%d', containing the sequence number, the
1466               roothash, and the share number.
1467
1468 Before Tahoe-LAFS v1.11, the `results` dictionary also had a `needs-rebalancing`
1469 field, but that has been removed since it was computed incorrectly.
1470
1471 .. _`docs/specifications/servers-of-happiness.rst`: ../specifications/servers-of-happiness.rst
1472
1473
1474 ``POST $URL?t=start-deep-check``    (must add &ophandle=XYZ)
1475
1476  This initiates a recursive walk of all files and directories reachable from
1477  the target, performing a check on each one just like t=check. The result
1478  page will contain a summary of the results, including details on any
1479  file/directory that was not fully healthy.
1480
1481  t=start-deep-check can only be invoked on a directory. An error (400
1482  BAD_REQUEST) will be signalled if it is invoked on a file. The recursive
1483  walker will deal with loops safely.
1484
1485  This accepts the same verify= and add-lease= arguments as t=check.
1486
1487  Since this operation can take a long time (perhaps a second per object),
1488  the ophandle= argument is required (see "Slow Operations, Progress, and
1489  Cancelling" above). The response to this POST will be a redirect to the
1490  corresponding /operations/$HANDLE page (with output=HTML or output=JSON to
1491  match the output= argument given to the POST). The deep-check operation
1492  will continue to run in the background, and the /operations page should be
1493  used to find out when the operation is done.
1494
1495  Detailed check results for non-healthy files and directories will be
1496  available under /operations/$HANDLE/$STORAGEINDEX, and the HTML status will
1497  contain links to these detailed results.
1498
1499  The HTML /operations/$HANDLE page for incomplete operations will contain a
1500  meta-refresh tag, set to 60 seconds, so that a browser which uses
1501  deep-check will automatically poll until the operation has completed.
1502
1503  The JSON page (/options/$HANDLE?output=JSON) will contain a
1504  machine-readable JSON dictionary with the following keys::
1505
1506   finished: a boolean, True if the operation is complete, else False. Some
1507             of the remaining keys may not be present until the operation
1508             is complete.
1509   root-storage-index: a base32-encoded string with the storage index of the
1510                       starting point of the deep-check operation
1511   count-objects-checked: count of how many objects were checked. Note that
1512                          non-distributed objects (i.e. small immutable LIT
1513                          files) are not checked, since for these objects,
1514                          the data is contained entirely in the URI.
1515   count-objects-healthy: how many of those objects were completely healthy
1516   count-objects-unhealthy: how many were damaged in some way
1517   count-corrupt-shares: how many shares were found to have corruption,
1518                         summed over all objects examined
1519   list-corrupt-shares: a list of "share identifiers", one for each share
1520                        that was found to be corrupt. Each share identifier
1521                        is a list of (serverid, storage_index, sharenum).
1522   list-unhealthy-files: a list of (pathname, check-results) tuples, for
1523                         each file that was not fully healthy. 'pathname' is
1524                         a list of strings (which can be joined by "/"
1525                         characters to turn it into a single string),
1526                         relative to the directory on which deep-check was
1527                         invoked. The 'check-results' field is the same as
1528                         that returned by t=check&output=JSON, described
1529                         above.
1530   stats: a dictionary with the same keys as the t=start-deep-stats command
1531          (described below)
1532
1533 ``POST $URL?t=stream-deep-check``
1534
1535  This initiates a recursive walk of all files and directories reachable from
1536  the target, performing a check on each one just like t=check. For each
1537  unique object (duplicates are skipped), a single line of JSON is emitted to
1538  the HTTP response channel (or an error indication, see below). When the walk
1539  is complete, a final line of JSON is emitted which contains the accumulated
1540  file-size/count "deep-stats" data.
1541
1542  This command takes the same arguments as t=start-deep-check.
1543
1544  A CLI tool can split the response stream on newlines into "response units",
1545  and parse each response unit as JSON. Each such parsed unit will be a
1546  dictionary, and will contain at least the "type" key: a string, one of
1547  "file", "directory", or "stats".
1548
1549  For all units that have a type of "file" or "directory", the dictionary will
1550  contain the following keys::
1551
1552   "path": a list of strings, with the path that is traversed to reach the
1553           object
1554   "cap": a write-cap URI for the file or directory, if available, else a
1555          read-cap URI
1556   "verifycap": a verify-cap URI for the file or directory
1557   "repaircap": an URI for the weakest cap that can still be used to repair
1558                the object
1559   "storage-index": a base32 storage index for the object
1560   "check-results": a copy of the dictionary which would be returned by
1561                    t=check&output=json, with three top-level keys:
1562                    "storage-index", "summary", and "results", and a variety
1563                    of counts and sharemaps in the "results" value.
1564
1565  Note that non-distributed files (i.e. LIT files) will have values of None
1566  for verifycap, repaircap, and storage-index, since these files can neither
1567  be verified nor repaired, and are not stored on the storage servers.
1568  Likewise the check-results dictionary will be limited: an empty string for
1569  storage-index, and a results dictionary with only the "healthy" key.
1570
1571  The last unit in the stream will have a type of "stats", and will contain
1572  the keys described in the "start-deep-stats" operation, below.
1573
1574  If any errors occur during the traversal (specifically if a directory is
1575  unrecoverable, such that further traversal is not possible), an error
1576  indication is written to the response body, instead of the usual line of
1577  JSON. This error indication line will begin with the string "ERROR:" (in all
1578  caps), and contain a summary of the error on the rest of the line. The
1579  remaining lines of the response body will be a python exception. The client
1580  application should look for the ERROR: and stop processing JSON as soon as
1581  it is seen. Note that neither a file being unrecoverable nor a directory
1582  merely being unhealthy will cause traversal to stop. The line just before
1583  the ERROR: will describe the directory that was untraversable, since the
1584  unit is emitted to the HTTP response body before the child is traversed.
1585
1586
1587 ``POST $URL?t=check&repair=true``
1588
1589  This performs a health check of the given file or directory, and if the
1590  checker determines that the object is not healthy (some shares are missing
1591  or corrupted), it will perform a "repair". During repair, any missing
1592  shares will be regenerated and uploaded to new servers.
1593
1594  This accepts the same verify=true and add-lease= arguments as t=check. When
1595  an output=JSON argument is provided, the machine-readable JSON response
1596  will contain the following keys::
1597
1598   storage-index: a base32-encoded string with the objects's storage index,
1599                  or an empty string for LIT files
1600   repair-attempted: (bool) True if repair was attempted
1601   repair-successful: (bool) True if repair was attempted and the file was
1602                      fully healthy afterwards. False if no repair was
1603                      attempted, or if a repair attempt failed.
1604   pre-repair-results: a dictionary that describes the state of the file
1605                       before any repair was performed. This contains exactly
1606                       the same keys as the 'results' value of the t=check
1607                       response, described above.
1608   post-repair-results: a dictionary that describes the state of the file
1609                        after any repair was performed. If no repair was
1610                        performed, post-repair-results and pre-repair-results
1611                        will be the same. This contains exactly the same keys
1612                        as the 'results' value of the t=check response,
1613                        described above.
1614
1615 ``POST $URL?t=start-deep-check&repair=true``    (must add &ophandle=XYZ)
1616
1617  This triggers a recursive walk of all files and directories, performing a
1618  t=check&repair=true on each one.
1619
1620  Like t=start-deep-check without the repair= argument, this can only be
1621  invoked on a directory. An error (400 BAD_REQUEST) will be signalled if it
1622  is invoked on a file. The recursive walker will deal with loops safely.
1623
1624  This accepts the same verify= and add-lease= arguments as
1625  t=start-deep-check. It uses the same ophandle= mechanism as
1626  start-deep-check. When an output=JSON argument is provided, the response
1627  will contain the following keys::
1628
1629   finished: (bool) True if the operation has completed, else False
1630   root-storage-index: a base32-encoded string with the storage index of the
1631                       starting point of the deep-check operation
1632   count-objects-checked: count of how many objects were checked
1633
1634   count-objects-healthy-pre-repair: how many of those objects were completely
1635                                     healthy, before any repair
1636   count-objects-unhealthy-pre-repair: how many were damaged in some way
1637   count-objects-healthy-post-repair: how many of those objects were completely
1638                                       healthy, after any repair
1639   count-objects-unhealthy-post-repair: how many were damaged in some way
1640
1641   count-repairs-attempted: repairs were attempted on this many objects.
1642   count-repairs-successful: how many repairs resulted in healthy objects
1643   count-repairs-unsuccessful: how many repairs resulted did not results in
1644                               completely healthy objects
1645   count-corrupt-shares-pre-repair: how many shares were found to have
1646                                    corruption, summed over all objects
1647                                    examined, before any repair
1648   count-corrupt-shares-post-repair: how many shares were found to have
1649                                     corruption, summed over all objects
1650                                     examined, after any repair
1651   list-corrupt-shares: a list of "share identifiers", one for each share
1652                        that was found to be corrupt (before any repair).
1653                        Each share identifier is a list of (serverid,
1654                        storage_index, sharenum).
1655   list-remaining-corrupt-shares: like list-corrupt-shares, but mutable shares
1656                                  that were successfully repaired are not
1657                                  included. These are shares that need
1658                                  manual processing. Since immutable shares
1659                                  cannot be modified by clients, all corruption
1660                                  in immutable shares will be listed here.
1661   list-unhealthy-files: a list of (pathname, check-results) tuples, for
1662                         each file that was not fully healthy. 'pathname' is
1663                         relative to the directory on which deep-check was
1664                         invoked. The 'check-results' field is the same as
1665                         that returned by t=check&repair=true&output=JSON,
1666                         described above.
1667   stats: a dictionary with the same keys as the t=start-deep-stats command
1668          (described below)
1669
1670 ``POST $URL?t=stream-deep-check&repair=true``
1671
1672  This triggers a recursive walk of all files and directories, performing a
1673  t=check&repair=true on each one. For each unique object (duplicates are
1674  skipped), a single line of JSON is emitted to the HTTP response channel (or
1675  an error indication). When the walk is complete, a final line of JSON is
1676  emitted which contains the accumulated file-size/count "deep-stats" data.
1677
1678  This emits the same data as t=stream-deep-check (without the repair=true),
1679  except that the "check-results" field is replaced with a
1680  "check-and-repair-results" field, which contains the keys returned by
1681  t=check&repair=true&output=json (i.e. repair-attempted, repair-successful,
1682  pre-repair-results, and post-repair-results). The output does not contain
1683  the summary dictionary that is provied by t=start-deep-check&repair=true
1684  (the one with count-objects-checked and list-unhealthy-files), since the
1685  receiving client is expected to calculate those values itself from the
1686  stream of per-object check-and-repair-results.
1687
1688  Note that the "ERROR:" indication will only be emitted if traversal stops,
1689  which will only occur if an unrecoverable directory is encountered. If a
1690  file or directory repair fails, the traversal will continue, and the repair
1691  failure will be indicated in the JSON data (in the "repair-successful" key).
1692
1693 ``POST $DIRURL?t=start-manifest``    (must add &ophandle=XYZ)
1694
1695  This operation generates a "manfest" of the given directory tree, mostly
1696  for debugging. This is a table of (path, filecap/dircap), for every object
1697  reachable from the starting directory. The path will be slash-joined, and
1698  the filecap/dircap will contain a link to the object in question. This page
1699  gives immediate access to every object in the virtual filesystem subtree.
1700
1701  This operation uses the same ophandle= mechanism as deep-check. The
1702  corresponding /operations/$HANDLE page has three different forms. The
1703  default is output=HTML.
1704
1705  If output=text is added to the query args, the results will be a text/plain
1706  list. The first line is special: it is either "finished: yes" or "finished:
1707  no"; if the operation is not finished, you must periodically reload the
1708  page until it completes. The rest of the results are a plaintext list, with
1709  one file/dir per line, slash-separated, with the filecap/dircap separated
1710  by a space.
1711
1712  If output=JSON is added to the queryargs, then the results will be a
1713  JSON-formatted dictionary with six keys. Note that because large directory
1714  structures can result in very large JSON results, the full results will not
1715  be available until the operation is complete (i.e. until output["finished"]
1716  is True)::
1717
1718   finished (bool): if False then you must reload the page until True
1719   origin_si (base32 str): the storage index of the starting point
1720   manifest: list of (path, cap) tuples, where path is a list of strings.
1721   verifycaps: list of (printable) verify cap strings
1722   storage-index: list of (base32) storage index strings
1723   stats: a dictionary with the same keys as the t=start-deep-stats command
1724          (described below)
1725
1726 ``POST $DIRURL?t=start-deep-size``   (must add &ophandle=XYZ)
1727
1728  This operation generates a number (in bytes) containing the sum of the
1729  filesize of all directories and immutable files reachable from the given
1730  directory. This is a rough lower bound of the total space consumed by this
1731  subtree. It does not include space consumed by mutable files, nor does it
1732  take expansion or encoding overhead into account. Later versions of the
1733  code may improve this estimate upwards.
1734
1735  The /operations/$HANDLE status output consists of two lines of text::
1736
1737   finished: yes
1738   size: 1234
1739
1740 ``POST $DIRURL?t=start-deep-stats``    (must add &ophandle=XYZ)
1741
1742  This operation performs a recursive walk of all files and directories
1743  reachable from the given directory, and generates a collection of
1744  statistics about those objects.
1745
1746  The result (obtained from the /operations/$OPHANDLE page) is a
1747  JSON-serialized dictionary with the following keys (note that some of these
1748  keys may be missing until 'finished' is True)::
1749
1750   finished: (bool) True if the operation has finished, else False
1751   count-immutable-files: count of how many CHK files are in the set
1752   count-mutable-files: same, for mutable files (does not include directories)
1753   count-literal-files: same, for LIT files (data contained inside the URI)
1754   count-files: sum of the above three
1755   count-directories: count of directories
1756   count-unknown: count of unrecognized objects (perhaps from the future)
1757   size-immutable-files: total bytes for all CHK files in the set, =deep-size
1758   size-mutable-files (TODO): same, for current version of all mutable files
1759   size-literal-files: same, for LIT files
1760   size-directories: size of directories (includes size-literal-files)
1761   size-files-histogram: list of (minsize, maxsize, count) buckets,
1762                         with a histogram of filesizes, 5dB/bucket,
1763                         for both literal and immutable files
1764   largest-directory: number of children in the largest directory
1765   largest-immutable-file: number of bytes in the largest CHK file
1766
1767  size-mutable-files is not implemented, because it would require extra
1768  queries to each mutable file to get their size. This may be implemented in
1769  the future.
1770
1771  Assuming no sharing, the basic space consumed by a single root directory is
1772  the sum of size-immutable-files, size-mutable-files, and size-directories.
1773  The actual disk space used by the shares is larger, because of the
1774  following sources of overhead::
1775
1776   integrity data
1777   expansion due to erasure coding
1778   share management data (leases)
1779   backend (ext3) minimum block size
1780
1781 ``POST $URL?t=stream-manifest``
1782
1783  This operation performs a recursive walk of all files and directories
1784  reachable from the given starting point. For each such unique object
1785  (duplicates are skipped), a single line of JSON is emitted to the HTTP
1786  response channel (or an error indication, see below). When the walk is
1787  complete, a final line of JSON is emitted which contains the accumulated
1788  file-size/count "deep-stats" data.
1789
1790  A CLI tool can split the response stream on newlines into "response units",
1791  and parse each response unit as JSON. Each such parsed unit will be a
1792  dictionary, and will contain at least the "type" key: a string, one of
1793  "file", "directory", or "stats".
1794
1795  For all units that have a type of "file" or "directory", the dictionary will
1796  contain the following keys::
1797
1798   "path": a list of strings, with the path that is traversed to reach the
1799           object
1800   "cap": a write-cap URI for the file or directory, if available, else a
1801          read-cap URI
1802   "verifycap": a verify-cap URI for the file or directory
1803   "repaircap": an URI for the weakest cap that can still be used to repair
1804                the object
1805   "storage-index": a base32 storage index for the object
1806
1807  Note that non-distributed files (i.e. LIT files) will have values of None
1808  for verifycap, repaircap, and storage-index, since these files can neither
1809  be verified nor repaired, and are not stored on the storage servers.
1810
1811  The last unit in the stream will have a type of "stats", and will contain
1812  the keys described in the "start-deep-stats" operation, below.
1813
1814  If any errors occur during the traversal (specifically if a directory is
1815  unrecoverable, such that further traversal is not possible), an error
1816  indication is written to the response body, instead of the usual line of
1817  JSON. This error indication line will begin with the string "ERROR:" (in all
1818  caps), and contain a summary of the error on the rest of the line. The
1819  remaining lines of the response body will be a python exception. The client
1820  application should look for the ERROR: and stop processing JSON as soon as
1821  it is seen. The line just before the ERROR: will describe the directory that
1822  was untraversable, since the manifest entry is emitted to the HTTP response
1823  body before the child is traversed.
1824
1825
1826 Other Useful Pages
1827 ==================
1828
1829 The portion of the web namespace that begins with "/uri" (and "/named") is
1830 dedicated to giving users (both humans and programs) access to the Tahoe
1831 virtual filesystem. The rest of the namespace provides status information
1832 about the state of the Tahoe node.
1833
1834 ``GET /``   (the root page)
1835
1836 This is the "Welcome Page", and contains a few distinct sections::
1837
1838  Node information: library versions, local nodeid, services being provided.
1839
1840  Filesystem Access Forms: create a new directory, view a file/directory by
1841                           URI, upload a file (unlinked), download a file by
1842                           URI.
1843
1844  Grid Status: introducer information, helper information, connected storage
1845               servers.
1846
1847 ``GET /status/``
1848
1849  This page lists all active uploads and downloads, and contains a short list
1850  of recent upload/download operations. Each operation has a link to a page
1851  that describes file sizes, servers that were involved, and the time consumed
1852  in each phase of the operation.
1853
1854  A GET of /status/?t=json will contain a machine-readable subset of the same
1855  data. It returns a JSON-encoded dictionary. The only key defined at this
1856  time is "active", with a value that is a list of operation dictionaries, one
1857  for each active operation. Once an operation is completed, it will no longer
1858  appear in data["active"] .
1859
1860  Each op-dict contains a "type" key, one of "upload", "download",
1861  "mapupdate", "publish", or "retrieve" (the first two are for immutable
1862  files, while the latter three are for mutable files and directories).
1863
1864  The "upload" op-dict will contain the following keys::
1865
1866   type (string): "upload"
1867   storage-index-string (string): a base32-encoded storage index
1868   total-size (int): total size of the file
1869   status (string): current status of the operation
1870   progress-hash (float): 1.0 when the file has been hashed
1871   progress-ciphertext (float): 1.0 when the file has been encrypted.
1872   progress-encode-push (float): 1.0 when the file has been encoded and
1873                                 pushed to the storage servers. For helper
1874                                 uploads, the ciphertext value climbs to 1.0
1875                                 first, then encoding starts. For unassisted
1876                                 uploads, ciphertext and encode-push progress
1877                                 will climb at the same pace.
1878
1879  The "download" op-dict will contain the following keys::
1880
1881   type (string): "download"
1882   storage-index-string (string): a base32-encoded storage index
1883   total-size (int): total size of the file
1884   status (string): current status of the operation
1885   progress (float): 1.0 when the file has been fully downloaded
1886
1887  Front-ends which want to report progress information are advised to simply
1888  average together all the progress-* indicators. A slightly more accurate
1889  value can be found by ignoring the progress-hash value (since the current
1890  implementation hashes synchronously, so clients will probably never see
1891  progress-hash!=1.0).
1892
1893 ``GET /helper_status/``
1894
1895  If the node is running a helper (i.e. if [helper]enabled is set to True in
1896  tahoe.cfg), then this page will provide a list of all the helper operations
1897  currently in progress. If "?t=json" is added to the URL, it will return a
1898  JSON-formatted list of helper statistics, which can then be used to produce
1899  graphs to indicate how busy the helper is.
1900
1901 ``GET /statistics/``
1902
1903  This page provides "node statistics", which are collected from a variety of
1904  sources::
1905
1906    load_monitor: every second, the node schedules a timer for one second in
1907                  the future, then measures how late the subsequent callback
1908                  is. The "load_average" is this tardiness, measured in
1909                  seconds, averaged over the last minute. It is an indication
1910                  of a busy node, one which is doing more work than can be
1911                  completed in a timely fashion. The "max_load" value is the
1912                  highest value that has been seen in the last 60 seconds.
1913
1914    cpu_monitor: every minute, the node uses time.clock() to measure how much
1915                 CPU time it has used, and it uses this value to produce
1916                 1min/5min/15min moving averages. These values range from 0%
1917                 (0.0) to 100% (1.0), and indicate what fraction of the CPU
1918                 has been used by the Tahoe node. Not all operating systems
1919                 provide meaningful data to time.clock(): they may report 100%
1920                 CPU usage at all times.
1921
1922    uploader: this counts how many immutable files (and bytes) have been
1923              uploaded since the node was started
1924
1925    downloader: this counts how many immutable files have been downloaded
1926                since the node was started
1927
1928    publishes: this counts how many mutable files (including directories) have
1929               been modified since the node was started
1930
1931    retrieves: this counts how many mutable files (including directories) have
1932               been read since the node was started
1933
1934  There are other statistics that are tracked by the node. The "raw stats"
1935  section shows a formatted dump of all of them.
1936
1937  By adding "?t=json" to the URL, the node will return a JSON-formatted
1938  dictionary of stats values, which can be used by other tools to produce
1939  graphs of node behavior. The misc/munin/ directory in the source
1940  distribution provides some tools to produce these graphs.
1941
1942 ``GET /``   (introducer status)
1943
1944  For Introducer nodes, the welcome page displays information about both
1945  clients and servers which are connected to the introducer. Servers make
1946  "service announcements", and these are listed in a table. Clients will
1947  subscribe to hear about service announcements, and these subscriptions are
1948  listed in a separate table. Both tables contain information about what
1949  version of Tahoe is being run by the remote node, their advertised and
1950  outbound IP addresses, their nodeid and nickname, and how long they have
1951  been available.
1952
1953  By adding "?t=json" to the URL, the node will return a JSON-formatted
1954  dictionary of stats values, which can be used to produce graphs of connected
1955  clients over time. This dictionary has the following keys::
1956
1957   ["subscription_summary"] : a dictionary mapping service name (like
1958                              "storage") to an integer with the number of
1959                              clients that have subscribed to hear about that
1960                              service
1961   ["announcement_summary"] : a dictionary mapping service name to an integer
1962                              with the number of servers which are announcing
1963                              that service
1964   ["announcement_distinct_hosts"] : a dictionary mapping service name to an
1965                                     integer which represents the number of
1966                                     distinct hosts that are providing that
1967                                     service. If two servers have announced
1968                                     FURLs which use the same hostnames (but
1969                                     different ports and tubids), they are
1970                                     considered to be on the same host.
1971
1972
1973 Static Files in /public_html
1974 ============================
1975
1976 The web-API server will take any request for a URL that starts with /static
1977 and serve it from a configurable directory which defaults to
1978 $BASEDIR/public_html . This is configured by setting the "[node]web.static"
1979 value in $BASEDIR/tahoe.cfg . If this is left at the default value of
1980 "public_html", then http://127.0.0.1:3456/static/subdir/foo.html will be
1981 served with the contents of the file $BASEDIR/public_html/subdir/foo.html .
1982
1983 This can be useful to serve a javascript application which provides a
1984 prettier front-end to the rest of the Tahoe web-API.
1985
1986
1987 Safety and Security Issues -- Names vs. URIs
1988 ============================================
1989
1990 Summary: use explicit file- and dir- caps whenever possible, to reduce the
1991 potential for surprises when the filesystem structure is changed.
1992
1993 Tahoe provides a mutable filesystem, but the ways that the filesystem can
1994 change are limited. The only thing that can change is that the mapping from
1995 child names to child objects that each directory contains can be changed by
1996 adding a new child name pointing to an object, removing an existing child name,
1997 or changing an existing child name to point to a different object.
1998
1999 Obviously if you query Tahoe for information about the filesystem and then act
2000 to change the filesystem (such as by getting a listing of the contents of a
2001 directory and then adding a file to the directory), then the filesystem might
2002 have been changed after you queried it and before you acted upon it.  However,
2003 if you use the URI instead of the pathname of an object when you act upon the
2004 object, then the only change that can happen is if the object is a directory
2005 then the set of child names it has might be different. If, on the other hand,
2006 you act upon the object using its pathname, then a different object might be in
2007 that place, which can result in more kinds of surprises.
2008
2009 For example, suppose you are writing code which recursively downloads the
2010 contents of a directory. The first thing your code does is fetch the listing
2011 of the contents of the directory. For each child that it fetched, if that
2012 child is a file then it downloads the file, and if that child is a directory
2013 then it recurses into that directory. Now, if the download and the recurse
2014 actions are performed using the child's name, then the results might be
2015 wrong, because for example a child name that pointed to a sub-directory when
2016 you listed the directory might have been changed to point to a file (in which
2017 case your attempt to recurse into it would result in an error and the file
2018 would be skipped), or a child name that pointed to a file when you listed the
2019 directory might now point to a sub-directory (in which case your attempt to
2020 download the child would result in a file containing HTML text describing the
2021 sub-directory!).
2022
2023 If your recursive algorithm uses the uri of the child instead of the name of
2024 the child, then those kinds of mistakes just can't happen. Note that both the
2025 child's name and the child's URI are included in the results of listing the
2026 parent directory, so it isn't any harder to use the URI for this purpose.
2027
2028 The read and write caps in a given directory node are separate URIs, and
2029 can't be assumed to point to the same object even if they were retrieved in
2030 the same operation (although the web-API server attempts to ensure this
2031 in most cases). If you need to rely on that property, you should explicitly
2032 verify it. More generally, you should not make assumptions about the
2033 internal consistency of the contents of mutable directories. As a result
2034 of the signatures on mutable object versions, it is guaranteed that a given
2035 version was written in a single update, but -- as in the case of a file --
2036 the contents may have been chosen by a malicious writer in a way that is
2037 designed to confuse applications that rely on their consistency.
2038
2039 In general, use names if you want "whatever object (whether file or
2040 directory) is found by following this name (or sequence of names) when my
2041 request reaches the server". Use URIs if you want "this particular object".
2042
2043
2044 Concurrency Issues
2045 ==================
2046
2047 Tahoe uses both mutable and immutable files. Mutable files can be created
2048 explicitly by doing an upload with ?mutable=true added, or implicitly by
2049 creating a new directory (since a directory is just a special way to
2050 interpret a given mutable file).
2051
2052 Mutable files suffer from the same consistency-vs-availability tradeoff that
2053 all distributed data storage systems face. It is not possible to
2054 simultaneously achieve perfect consistency and perfect availability in the
2055 face of network partitions (servers being unreachable or faulty).
2056
2057 Tahoe tries to achieve a reasonable compromise, but there is a basic rule in
2058 place, known as the Prime Coordination Directive: "Don't Do That". What this
2059 means is that if write-access to a mutable file is available to several
2060 parties, then those parties are responsible for coordinating their activities
2061 to avoid multiple simultaneous updates. This could be achieved by having
2062 these parties talk to each other and using some sort of locking mechanism, or
2063 by serializing all changes through a single writer.
2064
2065 The consequences of performing uncoordinated writes can vary. Some of the
2066 writers may lose their changes, as somebody else wins the race condition. In
2067 many cases the file will be left in an "unhealthy" state, meaning that there
2068 are not as many redundant shares as we would like (reducing the reliability
2069 of the file against server failures). In the worst case, the file can be left
2070 in such an unhealthy state that no version is recoverable, even the old ones.
2071 It is this small possibility of data loss that prompts us to issue the Prime
2072 Coordination Directive.
2073
2074 Tahoe nodes implement internal serialization to make sure that a single Tahoe
2075 node cannot conflict with itself. For example, it is safe to issue two
2076 directory modification requests to a single tahoe node's web-API server at the
2077 same time, because the Tahoe node will internally delay one of them until
2078 after the other has finished being applied. (This feature was introduced in
2079 Tahoe-1.1; back with Tahoe-1.0 the web client was responsible for serializing
2080 web requests themselves).
2081
2082 For more details, please see the "Consistency vs Availability" and "The Prime
2083 Coordination Directive" sections of mutable.rst_.
2084
2085 .. _mutable.rst: ../specifications/mutable.rst
2086
2087
2088 Access Blacklist
2089 ================
2090
2091 Gateway nodes may find it necessary to prohibit access to certain files. The
2092 web-API has a facility to block access to filecaps by their storage index,
2093 returning a 403 "Forbidden" error instead of the original file.
2094
2095 This blacklist is recorded in $NODEDIR/access.blacklist, and contains one
2096 blocked file per line. Comment lines (starting with ``#``) are ignored. Each
2097 line consists of the storage-index (in the usual base32 format as displayed
2098 by the "More Info" page, or by the "tahoe debug dump-cap" command), followed
2099 by whitespace, followed by a reason string, which will be included in the 403
2100 error message. This could hold a URL to a page that explains why the file is
2101 blocked, for example.
2102
2103 So for example, if you found a need to block access to a file with filecap
2104 ``URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861``,
2105 you could do the following::
2106
2107  tahoe debug dump-cap URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861
2108  -> storage index: whpepioyrnff7orecjolvbudeu
2109  echo "whpepioyrnff7orecjolvbudeu my puppy told me to" >>$NODEDIR/access.blacklist
2110  tahoe restart $NODEDIR
2111  tahoe get URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861
2112  -> error, 403 Access Prohibited: my puppy told me to
2113
2114 The ``access.blacklist`` file will be checked each time a file or directory
2115 is accessed: the file's ``mtime`` is used to decide whether it need to be
2116 reloaded. Therefore no node restart is necessary when creating the initial
2117 blacklist, nor when adding second, third, or additional entries to the list.
2118 When modifying the file, be careful to update it atomically, otherwise a
2119 request may arrive while the file is only halfway written, and the partial
2120 file may be incorrectly parsed.
2121
2122 The blacklist is applied to all access paths (including SFTP, FTP, and CLI
2123 operations), not just the web-API. The blacklist also applies to directories.
2124 If a directory is blacklisted, the gateway will refuse access to both that
2125 directory and any child files/directories underneath it, when accessed via
2126 "DIRCAP/SUBDIR/FILENAME" -style URLs. Users who go directly to the child
2127 file/dir will bypass the blacklist.
2128
2129 The node will log the SI of the file being blocked, and the reason code, into
2130 the ``logs/twistd.log`` file.
2131
2132
2133 .. [1] URLs and HTTP and UTF-8, Oh My
2134
2135  HTTP does not provide a mechanism to specify the character set used to
2136  encode non-ASCII names in URLs (`RFC3986#2.1`_).  We prefer the convention
2137  that the ``filename=`` argument shall be a URL-escaped UTF-8 encoded Unicode
2138  string.  For example, suppose we want to provoke the server into using a
2139  filename of "f i a n c e-acute e" (i.e. f i a n c U+00E9 e). The UTF-8
2140  encoding of this is 0x66 0x69 0x61 0x6e 0x63 0xc3 0xa9 0x65 (or
2141  "fianc\\xC3\\xA9e", as python's ``repr()`` function would show). To encode
2142  this into a URL, the non-printable characters must be escaped with the
2143  urlencode ``%XX`` mechanism, giving us "fianc%C3%A9e". Thus, the first line
2144  of the HTTP request will be "``GET
2145  /uri/CAP...?save=true&filename=fianc%C3%A9e HTTP/1.1``". Not all browsers
2146  provide this: IE7 by default uses the Latin-1 encoding, which is "fianc%E9e"
2147  (although it has a configuration option to send URLs as UTF-8).
2148
2149  The response header will need to indicate a non-ASCII filename. The actual
2150  mechanism to do this is not clear. For ASCII filenames, the response header
2151  would look like::
2152
2153   Content-Disposition: attachment; filename="english.txt"
2154
2155  If Tahoe were to enforce the UTF-8 convention, it would need to decode the
2156  URL argument into a Unicode string, and then encode it back into a sequence
2157  of bytes when creating the response header. One possibility would be to use
2158  unencoded UTF-8. Developers suggest that IE7 might accept this::
2159
2160   #1: Content-Disposition: attachment; filename="fianc\xC3\xA9e"
2161     (note, the last four bytes of that line, not including the newline, are
2162     0xC3 0xA9 0x65 0x22)
2163
2164  `RFC2231#4`_ (dated 1997): suggests that the following might work, and `some
2165  developers have reported`_ that it is supported by Firefox (but not IE7)::
2166
2167   #2: Content-Disposition: attachment; filename*=utf-8''fianc%C3%A9e
2168
2169  My reading of `RFC2616#19.5.1`_ (which defines Content-Disposition) says
2170  that the filename= parameter is defined to be wrapped in quotes (presumably
2171  to allow spaces without breaking the parsing of subsequent parameters),
2172  which would give us::
2173
2174   #3: Content-Disposition: attachment; filename*=utf-8''"fianc%C3%A9e"
2175
2176  However this is contrary to the examples in the email thread listed above.
2177
2178  Developers report that IE7 (when it is configured for UTF-8 URL encoding,
2179  which is not the default in Asian countries), will accept::
2180
2181   #4: Content-Disposition: attachment; filename=fianc%C3%A9e
2182
2183  However, for maximum compatibility, Tahoe simply copies bytes from the URL
2184  into the response header, rather than enforcing the UTF-8 convention. This
2185  means it does not try to decode the filename from the URL argument, nor does
2186  it encode the filename into the response header.
2187
2188 .. _RFC3986#2.1: https://tools.ietf.org/html/rfc3986#section-2.1
2189 .. _RFC2231#4: https://tools.ietf.org/html/rfc2231#section-4
2190 .. _some developers have reported: http://markmail.org/message/dsjyokgl7hv64ig3
2191 .. _RFC2616#19.5.1: https://tools.ietf.org/html/rfc2616#section-19.5.1
2192