196
197
same for a given request method. Only new request methods introduced in
197
198
Bazaar 0.91 and later use streamed bodies.
205
For some discussion of the requirements that led to this new protocol
206
version, see bug #\ 83935_.
208
.. _83935: https://bugs.launchpad.net/bzr/+bug/83935
210
Version three has bencoding of most protocol structures, to make parsing
213
The request and response protocol is::
215
REQUEST_V3 := "bzr request 3" NEWLINE HEADERS REQUEST_ARGS BODY_V3
216
RESPONSE_V3 := "bzr response 3" NEWLINE RESPONSE_STATUS_V3 HEADERS
217
RESPONSE_ARGS BODY_V3
218
RESPONSE_STATUS_V3 := SUCCESS_STATUS | ERROR_STATUS
219
SUCCESS_STATUS := "S"
221
HEADERS := bencoded_dictionary
223
Each request and response will have “headers”, a dictionary of key-value pairs.
224
The keys must be strings, not any other type of value.
226
Currently, the only defined header is “Software version”. Both the client and
227
the server should include a “Software version” header, with a value of a
228
free-form string such as “bzrlib 1.2”, to aid debugging and logging. Clients
229
and servers **should not** vary behaviour based on this string.
231
The argument encoding is::
233
REQUEST_ARGS := bencoded_sequence
234
RESPONSE_ARGS := bencoded_sequence
236
Arguments in this protocol version are bencoded, and the entire argument
237
structure is length-prefixed. As a result, unlike previous protocol versions,
238
arguments in this version are 8-bit clean.
240
For requests, the first item in the encoded sequence must be a string of
241
the request's verb, e.g. ``Branch.last_revision_info``. (And so requests must
242
always have at least one item in their REQUEST_ARGS sequence.)
244
For error responses (where the RESPONSE_STATUS_V3 is ERROR_STATUS), the
245
situation is analagous to requests. The first item in the encoded sequence must
246
be a string of the error name. The other arguments supply details about the
247
error, and their number and types will depend on the type of error (as
248
identified by the error name).
250
One possible error name is ``UnknownRequestVerb``, which means the server does
251
not recognise the verb used by the client's request.
253
The body encoding is::
255
BODY_V3 := NO_BODY | LENGTH_PREFIXED_BODY | STREAMED_BODY_V2
257
LENGTH_PREFIXED_BODY := "p" LENGTH_PREFIX BODY_BYTES
258
LENGTH_PREFIX := 32-bit unsigned integer in network byte order
259
STREAMED_BODY_V2 := "s" CHUNKS_V2 TERMINATOR_V2
261
CHUNKS_V2 := "c" CHUNK_V2 [CHUNKS_V2]
262
CHUNK_V2 := LENGTH_PREFIX CHUNK_CONTENT
264
TERMINATOR_V2 := SUCCESS_TERMINATOR_V2 | ERROR_TERMINATOR_V2
265
SUCCESS_TERMINATOR_V2 := SUCCESS_STATUS
266
ERROR_TERMINATOR_V2 := ERROR_STATUS bencoded_sequence
268
Version 3 messages always explicitly declare if a body is included. Clients
269
and servers are no longer expected to know which request verbs and responses
270
will have bodies attached. If present, bodies may be a single length-prefixed
271
string (like in protocol 1) or a stream of chunks (like in protocol 2).
273
If a streamed body is finished with an error, that error will be encoded
274
identically to RESPONSE_ARGS.