Skip to content
Snippets Groups Projects
Commit 8d3e5f39 authored by Monty Brandenberg's avatar Monty Brandenberg
Browse files

SH-3241 Validate header correctness, SH-3243 more unit tests

Define expectations for headers for GET, POST, PUT requests.
Document those in the interface, test those with integration tests.
Verify that header overrides work as expected.
parent d238341a
No related branches found
No related tags found
No related merge requests found
...@@ -468,6 +468,8 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) ...@@ -468,6 +468,8 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service)
curl_easy_setopt(mCurlHandle, CURLOPT_POSTFIELDS, static_cast<void *>(NULL)); curl_easy_setopt(mCurlHandle, CURLOPT_POSTFIELDS, static_cast<void *>(NULL));
curl_easy_setopt(mCurlHandle, CURLOPT_POSTFIELDSIZE, data_size); curl_easy_setopt(mCurlHandle, CURLOPT_POSTFIELDSIZE, data_size);
mCurlHeaders = curl_slist_append(mCurlHeaders, "Expect:"); mCurlHeaders = curl_slist_append(mCurlHeaders, "Expect:");
mCurlHeaders = curl_slist_append(mCurlHeaders, "Connection: keep-alive");
mCurlHeaders = curl_slist_append(mCurlHeaders, "Keep-alive: 300");
} }
break; break;
...@@ -482,6 +484,8 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service) ...@@ -482,6 +484,8 @@ HttpStatus HttpOpRequest::prepareRequest(HttpService * service)
curl_easy_setopt(mCurlHandle, CURLOPT_INFILESIZE, data_size); curl_easy_setopt(mCurlHandle, CURLOPT_INFILESIZE, data_size);
curl_easy_setopt(mCurlHandle, CURLOPT_POSTFIELDS, (void *) NULL); curl_easy_setopt(mCurlHandle, CURLOPT_POSTFIELDS, (void *) NULL);
mCurlHeaders = curl_slist_append(mCurlHeaders, "Expect:"); mCurlHeaders = curl_slist_append(mCurlHeaders, "Expect:");
mCurlHeaders = curl_slist_append(mCurlHeaders, "Connection: keep-alive");
mCurlHeaders = curl_slist_append(mCurlHeaders, "Keep-alive: 300");
} }
break; break;
......
...@@ -214,14 +214,46 @@ class HttpRequest ...@@ -214,14 +214,46 @@ class HttpRequest
/// request in other requests (like cancellation) and will be an /// request in other requests (like cancellation) and will be an
/// argument when any HttpHandler object is invoked. /// argument when any HttpHandler object is invoked.
/// ///
/// Headers supplied by default:
/// - Connection: keep-alive
/// - Accept: */*
/// - Accept-Encoding: deflate, gzip
/// - Keep-alive: 300
/// - Host: <stuff>
///
/// Some headers excluded by default:
/// - Pragma:
/// - Cache-control:
/// - Range:
/// - Transfer-Encoding:
/// - Referer:
///
/// @param policy_id Default or user-defined policy class under /// @param policy_id Default or user-defined policy class under
/// which this request is to be serviced. /// which this request is to be serviced.
/// @param priority Standard priority scheme inherited from /// @param priority Standard priority scheme inherited from
/// Indra code base (U32-type scheme). /// Indra code base (U32-type scheme).
/// @param url /// @param url URL with any encoded query parameters to
/// @param options (optional) /// be accessed.
/// @param headers (optional) /// @param options Optional instance of an HttpOptions object
/// @param handler (optional) /// to provide additional controls over the request
/// function for this request only. Any such
/// object then becomes shared-read across threads
/// and no code should modify the HttpOptions
/// instance.
/// @param headers Optional instance of an HttpHeaders object
/// to provide additional and/or overridden
/// headers for the request. As with options,
/// the instance becomes shared-read across threads
/// and no code should modify the HttpHeaders
/// instance.
/// @param handler Optional pointer to an HttpHandler instance
/// whose onCompleted() method will be invoked
/// during calls to update(). This is a non-
/// reference-counted object which would be a
/// problem for shutdown and other edge cases but
/// the pointer is only dereferenced during
/// calls to update().
///
/// @return The handle of the request if successfully /// @return The handle of the request if successfully
/// queued or LLCORE_HTTP_HANDLE_INVALID if the /// queued or LLCORE_HTTP_HANDLE_INVALID if the
/// request could not be queued. In the latter /// request could not be queued. In the latter
...@@ -244,20 +276,29 @@ class HttpRequest ...@@ -244,20 +276,29 @@ class HttpRequest
/// request in other requests (like cancellation) and will be an /// request in other requests (like cancellation) and will be an
/// argument when any HttpHandler object is invoked. /// argument when any HttpHandler object is invoked.
/// ///
/// @param policy_id Default or user-defined policy class under /// Headers supplied by default:
/// which this request is to be serviced. /// - Connection: keep-alive
/// @param priority Standard priority scheme inherited from /// - Accept: */*
/// Indra code base (U32-type scheme). /// - Accept-Encoding: deflate, gzip
/// @param url /// - Keep-alive: 300
/// @param offset /// - Host: <stuff>
/// @param len /// - Range: <stuff> (will be omitted if offset == 0 and len == 0)
/// @param options (optional) ///
/// @param headers (optional) /// Some headers excluded by default:
/// @param handler (optional) /// - Pragma:
/// @return The handle of the request if successfully /// - Cache-control:
/// queued or LLCORE_HTTP_HANDLE_INVALID if the /// - Transfer-Encoding:
/// request could not be queued. In the latter /// - Referer:
/// case, @see getStatus() will return more info. ///
/// @param policy_id @see requestGet()
/// @param priority "
/// @param url "
/// @param offset Offset of first byte into resource to be returned.
/// @param len Count of bytes to be returned
/// @param options @see requestGet()
/// @param headers "
/// @param handler "
/// @return "
/// ///
HttpHandle requestGetByteRange(policy_t policy_id, HttpHandle requestGetByteRange(policy_t policy_id,
priority_t priority, priority_t priority,
...@@ -269,22 +310,37 @@ class HttpRequest ...@@ -269,22 +310,37 @@ class HttpRequest
HttpHandler * handler); HttpHandler * handler);
/// /// Queue a full HTTP POST. Query arguments and body may
/// @param policy_id Default or user-defined policy class under /// be provided. Caller is responsible for escaping and
/// which this request is to be serviced. /// encoding and communicating the content types.
/// @param priority Standard priority scheme inherited from ///
/// Indra code base. /// Headers supplied by default:
/// @param url /// - Connection: keep-alive
/// - Accept: */*
/// - Accept-Encoding: deflate, gzip
/// - Keep-Alive: 300
/// - Host: <stuff>
/// - Content-Length: <digits>
/// - Content-Type: application/x-www-form-urlencoded
///
/// Some headers excluded by default:
/// - Pragma:
/// - Cache-Control:
/// - Transfer-Encoding: ... chunked ...
/// - Referer:
/// - Content-Encoding:
/// - Expect:
///
/// @param policy_id @see requestGet()
/// @param priority "
/// @param url "
/// @param body Byte stream to be sent as the body. No /// @param body Byte stream to be sent as the body. No
/// further encoding or escaping will be done /// further encoding or escaping will be done
/// to the content. /// to the content.
/// @param options (optional) /// @param options @see requestGet()K(optional)
/// @param headers (optional) /// @param headers "
/// @param handler (optional) /// @param handler "
/// @return The handle of the request if successfully /// @return "
/// queued or LLCORE_HTTP_HANDLE_INVALID if the
/// request could not be queued. In the latter
/// case, @see getStatus() will return more info.
/// ///
HttpHandle requestPost(policy_t policy_id, HttpHandle requestPost(policy_t policy_id,
priority_t priority, priority_t priority,
...@@ -295,22 +351,37 @@ class HttpRequest ...@@ -295,22 +351,37 @@ class HttpRequest
HttpHandler * handler); HttpHandler * handler);
/// /// Queue a full HTTP PUT. Query arguments and body may
/// @param policy_id Default or user-defined policy class under /// be provided. Caller is responsible for escaping and
/// which this request is to be serviced. /// encoding and communicating the content types.
/// @param priority Standard priority scheme inherited from ///
/// Indra code base. /// Headers supplied by default:
/// @param url /// - Connection: keep-alive
/// - Accept: */*
/// - Accept-Encoding: deflate, gzip
/// - Keep-Alive: 300
/// - Host: <stuff>
/// - Content-Length: <digits>
///
/// Some headers excluded by default:
/// - Pragma:
/// - Cache-Control:
/// - Transfer-Encoding: ... chunked ...
/// - Referer:
/// - Content-Encoding:
/// - Expect:
/// - Content-Type:
///
/// @param policy_id @see requestGet()
/// @param priority "
/// @param url "
/// @param body Byte stream to be sent as the body. No /// @param body Byte stream to be sent as the body. No
/// further encoding or escaping will be done /// further encoding or escaping will be done
/// to the content. /// to the content.
/// @param options (optional) /// @param options @see requestGet()K(optional)
/// @param headers (optional) /// @param headers "
/// @param handler (optional) /// @param handler "
/// @return The handle of the request if successfully /// @return "
/// queued or LLCORE_HTTP_HANDLE_INVALID if the
/// request could not be queued. In the latter
/// case, @see getStatus() will return more info.
/// ///
HttpHandle requestPut(policy_t policy_id, HttpHandle requestPut(policy_t policy_id,
priority_t priority, priority_t priority,
...@@ -326,11 +397,8 @@ class HttpRequest ...@@ -326,11 +397,8 @@ class HttpRequest
/// immediately processes it and returns the request to the reply /// immediately processes it and returns the request to the reply
/// queue. /// queue.
/// ///
/// @param handler (optional) /// @param handler @see requestGet()
/// @return The handle of the request if successfully /// @return "
/// queued or LLCORE_HTTP_HANDLE_INVALID if the
/// request could not be queued. In the latter
/// case, @see getStatus() will return more info.
/// ///
HttpHandle requestNoOp(HttpHandler * handler); HttpHandle requestNoOp(HttpHandler * handler);
...@@ -345,7 +413,8 @@ class HttpRequest ...@@ -345,7 +413,8 @@ class HttpRequest
/// spend in the call. As hinted at above, this /// spend in the call. As hinted at above, this
/// is partly a function of application code so it's /// is partly a function of application code so it's
/// a soft limit. A '0' value will run without /// a soft limit. A '0' value will run without
/// time limit. /// time limit until everything queued has been
/// delivered.
/// ///
/// @return Standard status code. /// @return Standard status code.
HttpStatus update(long usecs); HttpStatus update(long usecs);
...@@ -365,10 +434,8 @@ class HttpRequest ...@@ -365,10 +434,8 @@ class HttpRequest
/// @param request Handle of previously-issued request to /// @param request Handle of previously-issued request to
/// be changed. /// be changed.
/// @param priority New priority value. /// @param priority New priority value.
/// @param handler (optional) /// @param handler @see requestGet()
/// @return The handle of the request if successfully /// @return "
/// queued or LLCORE_HTTP_HANDLE_INVALID if the
/// request could not be queued.
/// ///
HttpHandle requestSetPriority(HttpHandle request, priority_t priority, HttpHandler * handler); HttpHandle requestSetPriority(HttpHandle request, priority_t priority, HttpHandler * handler);
......
This diff is collapsed.
...@@ -141,6 +141,7 @@ def answer(self, data, withdata=True): ...@@ -141,6 +141,7 @@ def answer(self, data, withdata=True):
def reflect_headers(self): def reflect_headers(self):
for name in self.headers.keys(): for name in self.headers.keys():
# print "Header: %s: %s" % (name, self.headers[name])
self.send_header("X-Reflect-" + name, self.headers[name]) self.send_header("X-Reflect-" + name, self.headers[name])
if not VERBOSE: if not VERBOSE:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment