PageRenderTime 18ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/http_server/client/AWSHttpEchoClientRequestBuilder.cpp

http://github.com/jtblatt/duderino
C++ | 53 lines | 32 code | 16 blank | 5 comment | 17 complexity | 46ca31964263fc369cc742f39e844167 MD5 | raw file
 1/* Copyright (c) 2009 Yahoo! Inc.  All rights reserved.
 2 * The copyrights embodied in the content of this file are licensed by Yahoo! Inc.
 3 * under the BSD (revised) open source license.
 4 */
 5
 6#ifndef AWS_HTTP_ECHO_CLIENT_REQUEST_BUILDER_H
 7#include <AWSHttpEchoClientRequestBuilder.h>
 8#endif
 9
10ESFError AWSHttpEchoClientRequestBuilder(const char *host, int port, const char *absPath, const char *method, const char *contentType,
11        AWSHttpClientTransaction *transaction) {
12    if (0 == host || 0 == absPath || 0 == method || 0 == transaction) {
13        return ESF_NULL_POINTER;
14    }
15
16    if (0 > port || 65536 <= port) {
17        return ESF_INVALID_ARGUMENT;
18    }
19
20    AWSHttpRequest *request = transaction->getRequest();
21    AWSHttpRequestUri *requestUri = request->getRequestUri();
22
23    requestUri->setType(AWSHttpRequestUri::AWS_URI_HTTP);
24
25    requestUri->setAbsPath((const unsigned char *) absPath);
26
27    request->setMethod((const unsigned char *) method);
28
29    ESFError error = request->addHeader(transaction->getAllocator(), (const unsigned char *) "Host", (const unsigned char *) "%s:%d", host, port);
30
31    if (ESF_SUCCESS != error) {
32        return error;
33    }
34
35    if (contentType) {
36        error = request->addHeader((const unsigned char *) "Content-Type", (const unsigned char *) contentType, transaction->getAllocator());
37
38        if (ESF_SUCCESS != error) {
39            return error;
40        }
41    }
42
43    error = request->addHeader((const unsigned char *) "Transfer-Encoding", (const unsigned char *) "chunked", transaction->getAllocator());
44
45    if (ESF_SUCCESS != error) {
46        return error;
47    }
48
49    // Body is hardcoded in AWSHttpEchoClientHandler.cpp
50
51    return ESF_SUCCESS;
52}
53