1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_INTERFACE_H_
6 #define SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_INTERFACE_H_
10 #include "sync/base/sync_export.h"
14 // An interface the embedding application (e.g. Chromium) implements to provide
15 // required HTTP POST functionality to the syncer backend. This interface is
16 // designed for one-time use. You create one, use it, and create another if you
17 // want to make a subsequent POST.
18 class SYNC_EXPORT_PRIVATE HttpPostProviderInterface
{
20 // Add additional headers to the request.
21 virtual void SetExtraRequestHeaders(const char* headers
) = 0;
23 // Set the URL to POST to.
24 virtual void SetURL(const char* url
, int port
) = 0;
26 // Set the type, length and content of the POST payload.
27 // |content_type| is a null-terminated MIME type specifier.
28 // |content| is a data buffer; Do not interpret as a null-terminated string.
29 // |content_length| is the total number of chars in |content|. It is used to
30 // assign/copy |content| data.
31 virtual void SetPostPayload(const char* content_type
,
33 const char* content
) = 0;
35 // Returns true if the URL request succeeded. If the request failed,
36 // error() may be non-zero and hence contain more information.
37 virtual bool MakeSynchronousPost(int* error_code
, int* response_code
) = 0;
39 // Get the length of the content returned in the HTTP response.
40 // This does not count the trailing null-terminating character returned
41 // by GetResponseContent, so it is analogous to calling string.length.
42 virtual int GetResponseContentLength() const = 0;
44 // Get the content returned in the HTTP response.
45 // This is a null terminated string of characters.
46 // Value should be copied.
47 virtual const char* GetResponseContent() const = 0;
49 // Get the value of a header returned in the HTTP response.
50 // If the header is not present, returns the empty string.
51 virtual const std::string
GetResponseHeaderValue(
52 const std::string
& name
) const = 0;
54 // Abandon any pending POST and unblock caller in MakeSynchronousPost.
55 // This must be safe to call from any thread.
56 virtual void Abort() = 0;
59 virtual ~HttpPostProviderInterface() {}
64 #endif // SYNC_INTERNAL_API_PUBLIC_HTTP_POST_PROVIDER_INTERFACE_H_