I would like to add a header to a cppnet-lib basic_response object. However, I am getting compilation errors.
I can add a header to a basic_request as follows which compiles ok:
boost::network::http::basic_request<boost::network::http::tags::http_server> request;
request << header("test", "test");
However, doing the same for a response object as follows receives a compilation error:
boost::network::http::basic_response<boost::network::http::tags::http_server> response;
response << header("test", "test");
Compilation error:
'headers_container_type': the symbol to the left of a '::' must be a type (header.hpp)
'value_type': is not a member of boost::network::http::basic_response<boost::network::http::tags::http_server> (header.hpp)
syntax error: missing ';' before identifier 'value_type' (header.hpp)
This would suggest that this isn't possible on a response object, but following the following page seems to suggest it is. I'm obviously going wrong somewhere!
Documentation: http://cpp-netlib.org/0.8/reference_http_response.html
My environment is:
Visual Studio 2013 (building as Release)
Boost 1.55
cppnet-lib: 0.11.0
Any help would be very much appreciated! Thanks.
First, I think you're using the wrong documentation since you're using version 0.11.0 (I suggest you use 0.11.1, which has a lot of bug fixes on top of 0.11.0). Here's the link you actually want for the 0.11.0 documentation:
http://cpp-netlib.org/0.11.0/reference/http_server.html#response-object
Second, you'd want to add headers directly to the response object's headers member. No need to use functions to do this:
struct my_server {
void operator(server::request const& req, server::response & res) {
// do something with the request and/or response
res.headers.push_back(server::response::header("Name", "value"));
// do more things
}
// ...
};
Related
I've got a very simple driver kit driver. It's almost boiler plate.
I'm getting a build failure when trying to use OSDynamicCast, as per the below
kern_return_t IMPL(MyHIDDriver, NewUserClient) {
IOService* client;
auto ret = Create(this, "MyTest", &client);
*userClient = OSDynamicCast(IOUserClient, client);
return ret;
}
My use of OSDynamicCast is giving me the following issue.
Use of undeclared identifier 'gIOUserClientMetaClass'; did you mean 'gIOUserServerMetaClass'?
Before adding the NewUserClient override, the driver was running fine (I've observed it in the IORegistry).
I'm not sure what I'm missing here in Xcode that would cause this issue. Samples I've referenced, such as this, do exactly what I'm doing with OSDynamicCast.
Is the IOUserClient header #included somewhere in this compilation unit? It sounds like you're simply missing
#include <DriverKit/IOUserClient.h>
Entirely unrelated to the issue you're experiencing, but you may want to initialise the client variable to a nullptr to avoid issues with undefined behaviour in case Create fails:
IOService* client = nullptr;
The documentation does not guarantee that it will be set to this automatically if the call fails, so the subsequent OSDynamicCast would be exposed to undefined behaviour.
I'm using cpprestsdk for a Http client in my code as given below:
std::string MyClass::GetPage(std::string url)
{
web::http::client::http_client httpClient(utility::conversions::to_string_t(url));
pplx::task<web::http::http_response> request = httpClient.request(web::http::methods::GET);
request.then([=](pplx::task<web::http::http_response> task)
{
// TODO: handle exceptions here.
web::http::http_response response = task.get();
return response.extract_string();
});
}
I'm getting this strange set of compiler errors stated in the question header for multiple files. One example reference the error is point to is in http_client.h:
const utf16string &content_type = ::utility::conversions::to_utf16string("text/plain"),
in which there's nothing before the ::utility. This happens in multiple places and it's not my code. This is straight from SDK. I downloaded the API using NuGet package manager. Help please. Thanks.
I am trying to write my own implementation of REST server using C++ REST SDK.
the class used is http_listener.
Almost all of it compiles properly but when i try to buld a URI using class web::http::URI it gives me error, also if pass the URI to http_listener class it giving error.
below us the code that gives error.
void CPPRESTSERVER::Start()
{
//building the URI//
utility::string_t address = "http://";
address.append(m_IP);
address.append(":");
address.append(std::to_string(m_port));
address.append("/");
m_Uri(U(address)); //m_Uri class member of type web::http::uri
//m_CustUri(m_Uri);
//m_CustUri.append_path(m_pathIP);
//m_CustUri.set_port(m_port);
//*******************
m_rstServer(U(m_Uri.to_string())); //m_rstserver class member of type http_listener
m_rstServer.support(web::http::methods::GET, std::bind(&CPPRESTSERVER::handle_GET, this, std::placeholders::_1));
}
i have tried the below
1) m_Uri(U(address)); also as m_Uri(address); but still giving errors.
2) m_rstServer(U(m_Uri.to_string())); also as m_rstServer(m_Uri.to_string()); also as m_rstServer(m_Uri); also as m_rstServer(U(m_Uri));
but still they give errors eventhough they have respective cusntructors of functions accepting argumets of required type
CPPRESTSERVER.cpp:57:21: error: no match for call to ‘(web::uri) (utility::string_t&)’
m_Uri(U(address));
^
CPPRESTSERVER.cpp:62:25: error: no match for call to ‘(web::http::experimental::listener::http_listener) (web::uri&)’
m_rstServer(U(m_Uri.to_string()));
any suggestions?????? i have stuck due these two errors. also i am compiling in ubuntu with C++11 standard.
İn this official tutorial I got the error in title. What should be the reason?
Ptr<Tracker> tracker = Tracker::create( "KCF" );
Here the part of tracking.hpp:
#endcode
of course, you can also add any additional methods of your choice. It should be pointed out,
however, that it is not expected to have a constructor declared, as creation should be done via
the corresponding createTracker() method.
In src/tracker.cpp file add BOILERPLATE_CODE(name,classname) line to the body of
Tracker::create() method you will find there, like :
#code
Ptr<Tracker> Tracker::create( const String& trackerType )
{
BOILERPLATE_CODE("BOOSTING",TrackerBoosting);
BOILERPLATE_CODE("MIL",TrackerMIL);
return Ptr<Tracker>();
}
#endcode
- Finally, you should implement the function with signature :
#code
Ptr<classname> classname::createTracker(const classname::Params ¶meters){
...
}
#endcode
I am using 3.2.0 release.
The code you pasted from tracking.hpp isn't actual code, it's just sample code that's part of the documentation. The only relevant code in the tracking header file is:
#include <opencv2/tracking/tracker.hpp>
#include <opencv2/tracking/tldDataset.hpp>
Thus, to see what you're actually importing you need to look at the tracking/tracker.hpp file (here).
If you do that, you'll see that there's no static create method in the Tracker class declaration. The method was actually removed in this commit. So, basically, you're right: the tutorial wasn't updated after the method was removed. You should report your issue to the opencv team.
That being said, to make the tutorial work you'll probably need to replace the line that's not compiling with:
Ptr<TrackerKCF> tracker = TrackerKCF::create();
That should do the trick.
I am trying to write an LLVM backend, when I am trying to build it, I get the following error message:
AbcGenRegisterInfo.inc: In static member function 'static const llvm::AbcFrameLowering* llvm::AbcGenRegisterInfo::getFrameLowering(const llvm::MachineFunction&)':
AbcGenRegisterInfo.inc:322:43: error: invalid static_cast from type 'const llvm::TargetFrameLowering*' to type 'const llvm::AbcFrameLowering*'
MF.getSubtarget().getFrameLowering());
^
Here is my AbcRegisterInfo.td (I copied it from here):
class AbcReg<string n> : Register<n> {
let namespace = "Abc";
}
def DUMMY_REG : AbcReg<"R0">;
def RegI64 : RegisterClass<"Abc", [i64], 64, (add DUMMY_REG)>;
I also overrided AbcSubtarget::getFrameLowering() method:
class AbcSubTarget : public AbcGenSubtargetInfo {
AbcFrameLowering *frameLowering;
// more fields and methods
const AbcFrameLowering *getFrameLowering() const override {
return frameLowering;
}
};
but the error message did not change.
I don't understand what to do - I can't just edit AbcGenRegisterInfo.inc, because it will be re-generated every time I will build LLVM, and I don't understand what's wrong in my TableGen files.
I also tried to remove AbcGenRegisterInfo.inc file from my build directory before compiling, but it had no effect.
Does AbcFrameLowering inherit from TargetFrameLowering? It looks like the static cast is complaining because the types are unrelated.
Also make sure the header with the definition of AbcFrameLowering is included before the .inc file is included otherwise the static cast will fail as well.
I have the same exact error, and while I cannot answer your question in full, I believe I can address one part of the issue. You said
I also tried to remove AbcGenRegisterInfo.inc file from my build directory before compiling, but it had no effect.
Unless you mean that AbcGenRegisterInfo.inc was regenerated (and therefore deleting it had no effect), the fact that its absence has no effect should be due to the fact that TableGen has the .inc.tmp file to rely on as a backup. I noticed that when I make with VERBOSE=1, there is a statement that suggests tablegen uses the .tmp files in this way.
Again, not a specific answer to your main question, but just to hopefully help address that issue when trying to debug.