summaryrefslogtreecommitdiffstats
path: root/bdep/http-service.hxx
blob: 247fe941bc475fd0503348aab1b96dfac7d13361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// file      : bdep/http-service.hxx -*- C++ -*-
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BDEP_HTTP_SERVICE_HXX
#define BDEP_HTTP_SERVICE_HXX

#include <libbutl/manifest-parser.mxx>

#include <bdep/types.hxx>
#include <bdep/utility.hxx>

#include <bdep/common-options.hxx>

namespace bdep
{
  namespace http_service
  {
    // If type is file, then the value is a path to be uploaded.
    //
    struct parameter
    {
      enum {text, file} type;
      string name;
      string value;
    };
    using parameters = vector<parameter>;

    struct result
    {
      string           message;
      optional<string> reference;

      // Does not include status, message, or reference.
      //
      vector<butl::manifest_name_value> body;
    };

    // Submit text parameters and/or upload files to an HTTP service via the
    // POST method. Use the multipart/form-data content type if any files are
    // uploaded and application/x-www-form-urlencoded otherwise.
    //
    // On success, return the response manifest message and reference (if
    // present, see below) and the rest of the manifest values, if any. Issue
    // diagnostics and fail if anything goes wrong or the response manifest
    // status value is not 200 (success).
    //
    // Note that the HTTP service is expected to respond with the result
    // manifest that starts with the 'status' (HTTP status code) and 'message'
    // (diagnostics message) values optionally followed by 'reference' and
    // then other manifest values. If the status is not 200 and reference is
    // present, then it is included in the diagnostics.
    //
    result
    post (const common_options& o, const url&, const parameters&);
  }
}

#endif // BDEP_HTTP_SERVICE_HXX