Commit Graph

90 Commits

Author SHA1 Message Date
Andrew Bettison
3a56355111 Add 'Location' header to HTTP server 301 and 302 responses 2018-03-19 18:07:33 +10:30
Jeremy Lakeman
afa33484ba Always silently ignore incoming data once response has started 2018-01-08 12:24:42 +10:30
Andrew Bettison
cab9a430fb Improve comments and variable names in http_server.cc 2017-10-20 17:29:46 +10:30
Andrew Bettison
261fc43849 Log a clearer diagnostic on HTTP GET with chunked transfer 2017-10-20 17:29:46 +10:30
Andrew Bettison
29ce8994f2 Improve HTTP Content-Type handling
Undo a change from late 2015 that allowed the format=text+binarysig
parameter of the rhizome/manifest MIME content-type to be optional -- it
is easy to provide that parameter via libcurl, and the lbard code has
just been updated to provide it.

Make Content-Type handling consistent throughout the Serval DNA code by
using 'struct mime_content_type' to represent both parsed (request) and
sent (response) Content-Type fields, replacing ad-hoc in-line string
literals.

Fix some TODOs by adding the "serval/sid", "rhizome/bid" and
"rhizome/bundlesecret" MIME types, which remain optional for the time
being to preserve REST API compatibility with clients that do not set
the Content-Type of their 'bundle-author', 'bundle-id' and
'bundle-secret' parameters.
2017-10-20 09:55:21 +10:30
Andrew Bettison
093bdfdcd3 Add FALLTHROUGH macro to silence -Wimplicit-fallthrough in GCC7 2017-09-11 12:43:38 +09:30
Jeremy Lakeman
65bc309999 Allow POST requests with no Content-Length 2017-05-24 16:38:42 +09:30
Jeremy Lakeman
af2d32c25b Add Java API for importing bundles with manifests in zip comments 2017-05-24 13:33:03 +09:30
Jeremy Lakeman
c7de17b552 Fix decoding of multiple chunks in the same buffer 2017-05-23 15:34:07 +09:30
Jeremy Lakeman
2db8c24e15 Use chunked transfer encoding and expect header in Java API 2017-05-23 11:37:26 +09:30
Jeremy Lakeman
c138c94ee5 Fix warnings highlighted by gcc 2017-05-22 16:57:57 +09:30
Jeremy Lakeman
77b603942f Support "Transfer-Encoding: chunked" for POST'ed content 2017-05-22 16:17:17 +09:30
Jeremy Lakeman
87d171cdf7 Reject rhizome import before sending manifest & payload 2017-05-17 14:55:56 +09:30
Jeremy Lakeman
e376c1cb80 Add proper server support for http/1.1 Expect header 2017-05-17 14:24:28 +09:30
Jeremy Lakeman
88d70fc386 Don't assert if a query parameter is empty 2017-03-22 13:04:58 +10:30
Jeremy Lakeman
159188d08c Don't overflow the stack if logging config causes more logging due to using memory diagnostics 2016-10-31 15:23:06 +10:30
Andrew Bettison
6e65a2399f Add missing #include "str.h" 2016-09-21 18:47:49 +09:30
Andrew Bettison
5a77008aa8 Move URI primitives from "str.h" to "uri.h" 2016-09-21 18:47:49 +09:30
Andrew Bettison
5b3d997896 Move Base64 conversions from "str.h" to "base64.h" 2016-09-21 18:47:49 +09:30
Andrew Bettison
cd766cd480 Move numeric conversions from "str.h" to "numeric_str.h" 2016-09-21 18:47:49 +09:30
Jeremy Lakeman
7939a780fb Fix case where eof mime boundary overlaps buffer boundary 2016-04-11 13:10:37 +09:30
Jeremy Lakeman
64eb4f426b Handle stream EOF without entering an infinite poll loop 2016-01-27 16:27:02 +10:30
Andrew Bettison
078bf5eb6b Improve HTTP responses
In 'struct http_response', rename the 'result_code' field to
'status_code' for consistency with the terminology used in the HTTP
specification, and add a 'reason' field, so that the phrase that
appears in the first response line can differ from the standard
"canned" phrases.
2015-12-01 00:51:15 +10:30
Andrew Bettison
419364b5a9 Improve REST HTTP response status codes
List all the HTTP status codes in the REST API tech doc.

Only use 403 Forbidden for requests originating from a disallowed
origin (ie, not localhost).

- Return 400 for missing, unknown, duplicate and out-of-order form
  parts in POST requests.
- Return 415 Unsupported Media Type for unsupported form part
  Content-Disposition and Content-Type (including unsupported
  charset).
- Return 414 Request-URI Too Long for any buffer exhaustion while
  parsing request.
- Return 419 Authentication Timeout for missing crypto secret.
2015-11-02 12:26:40 +10:30
Andrew Bettison
4564e955e3 Improve HTTP Origin response headers
Re-introduce "Origin: null" handling, because actually it is in the
spec.
2015-11-02 11:58:24 +10:30
Andrew Bettison
cee5241951 Make HTTP server return 405 if not POST or GET 2015-11-02 11:58:24 +10:30
Andrew Bettison
d9af2ffda4 Improve HTTP server diagnostics
Always log errors before responding with 500 Server Error.  Support more
status code "reason phrases".
2015-11-02 11:58:24 +10:30
Jeremy Lakeman
0c275e67ef Clean up compilation warnings 2015-10-19 13:45:57 +10:30
Andrew Bettison
e770998372 Fix empty-string tests on char[]
Caused compiler errors, thanks to Jonas Höchst for reporting.
2015-10-01 07:05:17 +09:30
Andrew Bettison
404cc1476d Improve HTTP Origin header parsing
Parses the separate parts of the URI: scheme, hostname, port.
No longer supports "Origin: null", because that is not in the
spec.
2015-10-01 07:05:17 +09:30
Andrew Bettison
f73cd77185 Change arg of ctype functions from char to int
Consistent with functions defined in <ctype>; now all can be used
as a predicate function with the type int (*)(int).
2015-10-01 07:05:17 +09:30
Andrew Bettison
6123503c15 Improve Rhizome HTTP status codes
Also improve some reason phrases and test them
2015-09-21 18:43:24 +09:30
Andrew Bettison
0e783c6b73 Fix malformed HTTP output of JSON fields 2015-08-31 19:16:30 +09:30
Andrew Bettison
71c7a4f870 strbuf_json_atom() supports JSON objects and arrays 2015-08-31 19:16:30 +09:30
Andrew Bettison
ce7a6ba988 HTTP server: parse query parameters 2015-08-24 22:41:53 +09:30
Andrew Bettison
52106b5026 Move DEBUGF() from "log.h" to "debug.h"
Include "debug.h" in lots of places (not all)
New macro IDEBUGF() for indirect debug flag, used in HTTP server
2015-07-13 18:24:04 +09:30
Andrew Bettison
7d9a5faa4e Move if(config.debug.xxx) tests into DEBUGF()
Original DEBUG() and DEBUGF() macros renamed to _DEBUG() and _DEBUGF()
New DEBUG() and DEBUGF() macros, first argument is flagname
New DEBUGF2(foo, bar, ...) macro does if(config.debug.foo||config.debug.bar) test
Replace almost all config.debug.xxx references to IF_DEBUG(xxx)
2015-07-13 16:00:05 +09:30
Andrew Bettison
9f15c4770c Add [httpd/N] context to HTTP server logging 2015-06-29 15:39:19 +09:30
Andrew Bettison
51f21f3183 Fix http server pause: could stop polling too early
A paused http server should only stop polling on output once all
existing buffered output has been sent
2015-06-02 02:23:06 +09:30
Andrew Bettison
0ec2e54827 HTTP server debug: log content of HTTP responses 2015-02-23 15:56:30 +10:30
Andrew Bettison
6bf4cf0735 Add performance timing to http server functions 2014-11-17 14:10:00 +10:30
Andrew Bettison
e05d70b1a5 Fix wild assertion in HTTP server
In the _reserve() function, an assertion compared pointers which it assumed
both pointed within the heap, or in fact within the same buffer.  However, if
one pointer pointed into the stack, then the assertion would incorrectly fail
if the stack were located below the heap in address space.  That never happens
in a normal Linux process, but _can_ happen in a thread, since thread stacks
may be allocated on the heap.

Solution was to re-order the steps in which _reserve() overwrites the buffer,
making the assertion irrelevant.
2014-09-11 16:11:23 +09:30
Jeremy Lakeman
31cf3a67b5 Allow lcal http servers to perform cross site scripting of restful APIs 2014-07-28 12:54:57 +09:30
Andrew Bettison
606f087dd5 Merge latest Rhizome Java API into development 2014-07-11 12:29:24 +09:30
Andrew Bettison
04b2a20e54 Rhizome Java API: improved form-data headers
Change manifest Content-Type from rhizome-manifest/text to
rhizome/manifest; format="text+binarysig"

Add "Content-Transfer-Encoding" form-part headers to Java API
sent form parts, although not currently checked by Rhizome
RESTful interface
2014-07-10 21:12:40 +09:30
Andrew Bettison
3715c5bf0b Rhizome Java API: negative fetch tests 2014-07-10 06:30:50 +09:30
Andrew Bettison
cf43635789 Improve Rhizome HTTP RESTful interface
Add RHIZOME_BUNDLE_STATUS_READONLY enum value

Tighten up switch statements on bundle and payload status enums (no
default labels)

Rename some recently added enum entries

Return bundle status and payload status in HTTP responses

Add test for failing to decrypt a foreign encrypted bundle payload,
fix bug that caused an assertion failure

Add tests for fetching a non-existent manifest and fetching bundles
whose payload blob is not in the store
2014-07-10 06:29:51 +09:30
Andrew Bettison
1ac67de0e9 Fix bug in HTTP server's form-data parsing
Did not handle a non-empty preamble properly
2014-07-10 06:29:09 +09:30
Jeremy Lakeman
51540a3017 Implement read and write pointer using memcpy, might fix #78 2014-07-07 16:28:20 +09:30
Andrew Bettison
7736a4ceb1 New HTTP RESTful requests: MeshMS read message(s) 2014-06-24 12:11:58 +09:30