Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » HttpRequest, Content-ID header in Part method
HttpRequest, Content-ID header in Part method [message #44560] Tue, 31 March 2015 10:51 Go to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Hi,

I am looking for a way to add attachments to json-rpc/json-wsp.
The problem is that I need Content-ID header (example) in every attachment.

Mirek, can you add this header to the Part method?

removed.

[Updated on: Thu, 02 April 2015 10:25]

Report message to a moderator

Re: HttpRequest, Content-ID header in Part method [message #44563 is a reply to message #44560] Tue, 31 March 2015 18:16 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

May be add Callback for place any custom headers?
Or additional parameter with string with all headers....


I solved same task by rewriting Core Method.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: HttpRequest, Content-ID header in Part method [message #44564 is a reply to message #44563] Tue, 31 March 2015 21:29 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Hi Sergey,

You are right. Probably we need more generic Part method with headers defined by a user. Maybe something like this:

HttpRequest& HttpRequest::Part(const Vector<String>& header, const String& data,
                               const char *content_type)
{
	if(IsNull(multipart)) {
		POST();
		multipart = AsString(Uuid::Create());
		if (content_type && *content_type)
			ContentType(String(content_type) + "; boundary=" + multipart);
		else ContentType("multipart/form-data; boundary=" + multipart);
	}
	postdata << "--" << multipart << "\r\n";
	for (int i = 0; i < header.GetCount(); i++){
		postdata << header[i] << "\r\n";
	}

	postdata << "\r\n" << data << "\r\n";
	return *this;
}

[Updated on: Thu, 02 April 2015 10:23]

Report message to a moderator

Re: HttpRequest, Content-ID header in Part method [message #44578 is a reply to message #44564] Sat, 04 April 2015 09:42 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Zbych wrote on Tue, 31 March 2015 21:29
Hi Sergey,

You are right. Probably we need more generic Part method with headers defined by a user. Maybe something like this:

HttpRequest& HttpRequest::Part(const Vector<String>& header, const String& data,
                               const char *content_type)
{
	if(IsNull(multipart)) {
		POST();
		multipart = AsString(Uuid::Create());
		if (content_type && *content_type)
			ContentType(String(content_type) + "; boundary=" + multipart);
		else ContentType("multipart/form-data; boundary=" + multipart);
	}
	postdata << "--" << multipart << "\r\n";
	for (int i = 0; i < header.GetCount(); i++){
		postdata << header[i] << "\r\n";
	}

	postdata << "\r\n" << data << "\r\n";
	return *this;
}



I agree that this is missing. However, I would rather add "headers" last parameter as either const String& or const char *, which would simple would be put to postdata before the actual data. That way is more alike to Headers method. Do you agree?

Mirek
Re: HttpRequest, Content-ID header in Part method [message #44579 is a reply to message #44578] Sun, 05 April 2015 08:00 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

It will be 'Hack'. It's not transparent for newbies. But good as workaround.

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: HttpRequest, Content-ID header in Part method [message #44586 is a reply to message #44578] Tue, 07 April 2015 11:02 Go to previous message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
mirek wrote on Sat, 04 April 2015 09:42
I would rather add "headers" last parameter as either const String& or const char *, which would simple would be put to postdata before the actual data. That way is more alike to Headers method. Do you agree?

Mirek


I don't think it is a good solution. Beside headers in each attachment, I would like to be able to modify content-type header, which is hard-coded in Part function:

ContentType("multipart/form-data; boundary=" + multipart);


It would be better to have another "low level" Part function (Part0 or PartLL) with content-type and attachment headers configurable.
And of course "old" Part function should use this new "low level" Part.

[Updated on: Tue, 07 April 2015 16:19]

Report message to a moderator

Previous Topic: How to add statistics feature on SkyLark aplication?
Next Topic: [Bug] Httprequest - consecutive requests contain parts of previous requests
Goto Forum:
  


Current Time: Thu Mar 28 22:12:52 CET 2024

Total time taken to generate the page: 0.01310 seconds