summaryrefslogtreecommitdiff
path: root/http/http_request.hpp
AgeCommit message (Collapse)AuthorFilesLines
2022-02-25json_utils: Add support jsonRead Patch/ActionWilly Tu1-1/+1
Added support for readJson for Patch and Action. The only difference is that Patch does not allow empty json input while Action does. Action with empty input will use the default value based on the implementation and return 200 OK response code. readJsonPatch will replace the existing readJson and be used for path requests. It will not allow empty json input and all requested keys are required in the json input. readJsonAction will be used for Action requests where it is possible for all of the properties to be optional and allow empty request. The optional properties are determined by the requested values type. All current Action readJson are replaced with readJsonAction. It does not change the existing behavior since it needs `std::optional`. This will have to be updated later as we define the default behavior. Tested: Added unit tests and readJsonAction allows empty empty json object. No Change to Redfish Tree. Change-Id: Ia5e1f81695c528a20f1dc985aee19c920d8adaea Signed-off-by: Willy Tu <wltu@google.com>
2022-02-04Remove NEW_BOOST_URL macroEd Tanous1-20/+1
Now that the subtree update is done, this define is no longer needed. Tested: Code compiles. Noop. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Idc5d7ef69c009982a2476fadc1d95e3280bfff48
2022-02-02Next round of boost-uri updatesEd Tanous1-0/+19
Boost url has changed some APIs again. This commit updates our URIs to handle it. As part of this work, it also removes some of the debug prints that were put in early on. These aren't really needed these days. This commit invents a temporary #define of NEW_BOOST_URL, so we can get through the subtree update without a hard dependency on this specific version of bmcweb. Ideally boost-url would have some version field, but unfortunately, it is thusfar unversioned, as the long term intent of the author is to be included in boost, and would be versioned there. All the code within the else of the NEW_BOOST_URL flag will be removed once the subtree update is landed. Tested: Added CXXFLAGS:append = " -DNEW_BOOST_URL" to the recipe and checked out on top of the subtree update, and build succeeded. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ie2064e45efbc4331bdc5a5ddf44d877cde5e13cb
2022-01-12Enable cppcoreguidelines-special-member-functions checksEd Tanous1-0/+3
Part of enforcing cpp core guidelines involves explicitly including all constructors required on a non-trivial class. We were missing quite a few. In all cases, the copy/move/and operator= methods are simply deleted. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ie8d6e8bf2bc311fa21a9ae48b0d61ee5c1940999
2021-12-07Delete the copy constructor on the Request objectEd Tanous1-0/+3
This code was in the codebase previously, and at some point got removed to make copies. Considering the previous commits to this one, making copies of the request object is a bad idea, and should be avoided. Therefore, this commit deletes the copy constructor for the Request object, making request copies fail to compile. It should be noted, it does leave the move constructor, which I don't think it's really used, but as a rule isn't an anti-pattern. Tested: Code compiles. No functional change. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ib38ed79a7c60340fb00f922f29265a3c3c7beca8
2021-10-18Deduplicate url parsing codeEd Tanous1-3/+31
In the current model, URLs get parsed twice, once to satisfy the authenticate method, and once again later to satisfy the handle() call. This commit deduplicates the parsing. This is wasteful, and as of the previous commit, unnecessary. Specifically, it moves the actual parsing into the request object, and adds a target() method to explicitly set a url. This deduplicates the code that was in http_connection, and centralizes it in request, where it should really belong. Tested: curl --insecure "https://192.168.7.2/redfish/v1" Returns the redfish v1 resource curl --insecure "https://192.168.7.2/redfish/v1/Systems" Returns 401 unauthorized curl --insecure --user root:0penBmc "https://192.168.7.2/redfish/v1/Systems" returns the SystemsCollection Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ie7ee2d9a9a51bf21c03793b35730e7a0ca82623a
2021-10-05Boost uri updateEd Tanous1-1/+1
Update to the latest version of boost::uri The newest version of boost uri makes some breaking changes that we need to account for. At the same time, we take the opportunity to move to the error code based parse methods that don't rely on exceptions. The biggest changes are: The standalone build is no longer present. A discussion with the boost::url maintainers shows that our best option is to do a simple copy of the headers, and compile boost/url/src.hpp in a separate file. This is intended to allow people to pull the library in "standalone" and not have to rely on the build machinery in boost-url, which we don't really need. Interestingly, this file doesn't have a newline at the end, which clang correctly flags. OpenBMC doesn't really need that warning, as we rely on clang-format to do that, so we add -Wno-newline-eof clang to get the code to compile there. All url parsers are moved to the parse_uri, or parse_relative_uri equivalents. This slightly tightens the requirements around what URLs are accepted, but in no ways that should break anything. (Ie, "/redfish/v1" is no longer accepted for a virtual media endpoint. boost::urls::url_view::params_type has been renamed to query_params_type, and the relevant methods have been updated. Because of the missing standalone mode, we now need to use boost::string_view which doesn't implicitly construct from std::string_view. Some discussion on the boost list shows that this is coming soon, so that cruft can eventually be cleaned up, but for now we need the construction. Tested: Loaded in qemu, and ran some URLs (/redfish/v1 and /redfish/v1/Chassis) to ensure that the url handler functions as intended. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I5843776d4ec01b4d92af2ee3a9cf1ebb1d920ae7
2021-09-09Change ownership of boost::req to crow::reqJohn Edward Broadbent1-4/+4
req is being created later, in the connection life cycle. req was holding many important values when it was passed to authenticate, so the authenticate call had to be refactored to includes all the data req was holding. Also uses of req before handle have been changed to direct calls to boot::parse Tested: Made a request that did not require authentication $ curl -vvvv --insecure "https://192.168.7.2:18080/redfish/v1" Got correct service root Made a unauthenticated request (Chassis) $ curl -c cjar -b cjar -k -H "Content-Type: application/json" -X GET https://192.168.7.2:18080/redfish/v1/Chassis Unauthenticated Made a log-in request $ curl -c cjar -b cjar -k -H "Content-Type: application/json" -X POST https://192.168.7.2:18080/login -d "{\"data\": [ \"root\", \"0penBmc\" ] }" Made (same) Chassis request $ curl -c cjar -b cjar -k -H "Content-Type: application/json" -X GET https://192.168.7.2:18080/redfish/v1/Chassis Tested the websockets using scripts/websocket_test.py Websockets continued to work after this change. Followed the mTLS instructions here https://github.com/openbmc/docs/blob/master/security/TLS-configuration.md mTLS continues to work after this change. Change-Id: I78f78063be0331be00b66349d5d184847add1708 Signed-off-by: John Edward Broadbent <jebr@google.com>
2021-05-12Include what you use in http request and responseEd Tanous1-0/+3
https://jenkins.openbmc.org/job/ci-openbmc/3949/distro=ubuntu,label=docker-builder,target=tiogapass/consoleText This build seems to be failing with an error | ../git/http/http_response.hpp:23:10: error: 'optional' in namespace 'std' does not name a template type | 23 | std::optional<response_type> stringResponse; This should fix it by including the relevant headers. Tested: Code builds. CI error only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ifba15559a73d823d791de1d508e136a3c44e6cd1
2020-11-10Redfish Session : Support ClientOriginIPAddressSunitha Harish1-0/+2
This commit implements the ClientOriginIPAddress property on the session resource. The IP address is persisted across the reboot Tested by: 1. Create session POST https://${bmc}/redfish/v1/SessionService/Sessions -d '{"UserName":<>, "Password":<>}' 2. Check the session gets updated with the ClientOriginIPAddress GET https://${bmc}/redfish/v1/SessionService/Sessions/<id> 3. Redfish validator passed 4. Create session and reboot the BMC to ensure the IP address is persisted 5. Tested the basic auth populates the clientIp at req Signed-off-by: Sunitha Harish <sunharis@in.ibm.com> Change-Id: Iaa60d0657c991bde4bcf6c86819055c71c92e421
2020-10-29Revert "Redfish Session : Support ClientOriginIPAddress"Ed Tanous1-2/+0
This reverts commit e436008377fbcf287be02c9e9e1b59c6627d7673. Reason for revert: This breaks several things. 1. Not all login endpoints are handled, which lead to returning blank ip addresses 2. IP addresses are not persisted. 3. This crashes occasionally on remote_endpoint, and ignores ec. Change-Id: I58c875721cf48bf02db833c9c57a9eead5e249d5
2020-10-23fix include namesEd Tanous1-0/+80
cppcheck isn't smart enough to recognize these are c++ headers, not c headers. Considering we're already inconsistent about our naming, it's easier to just be consistent, and move the last few files to use .hpp instead of .h. Tested: Code builds, no changes. Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: Ic348d695f8527fa4a0ded53f433e1558c319db40