Discussion:
[Mojolicious] How do you generate a "Content-Length" header in a multipart request?
Steve Dondley
2018-09-18 16:50:42 UTC
Permalink
I'm starting a new thread related to the previous one regarding making a
batch api request to Google's API. I keep getting "Bad Reqeust" responses
from Google after making a batch API call (other calls work fine).

Looking at the api documentation for batch api requests
<https://developers.google.com/gmail/api/guides/batch> it says each part of
the multipart request should have a content length. Here is the example
Google supplies:

POST /batch/farm/v1 HTTP/1.1
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length

--batch_foobarbaz
Content-Type: application/http
Content-ID: <item1:***@barnyard.example.com>

GET /farm/v1/animals/pony

--batch_foobarbaz
Content-Type: application/http
Content-ID: <item2:***@barnyard.example.com>

PUT /farm/v1/animals/sheep
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"

{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}

--batch_foobarbaz
Content-Type: application/http
Content-ID: <item3:***@barnyard.example.com>

GET /farm/v1/animals
If-None-Match: "etag/animals"

--batch_foobarbaz--



The requests I'm generating with mojolicious do not have the
"part_content_length." Here's mine:

POST /batch/gmail/v1 HTTP/1.1
Authorization: Bearer A_REAL_TOKEN_GOES_HERE
Host: www.googleapis.com
Accept-Encoding: gzip
Content-Length: 120
User-Agent: Mojolicious (Perl)
Content-Type: multipart/mixed; boundary=nS2CX


--nS2CX
Content-Type: application/http


GET /gmail/v1/users/***@gmail.com/messages/165eb111fcf21503
--nS2CX--



My question is, does Mojolicious provide a way to automatically generate a
content length header for these parts? If not, which parts of the message
get counted toward this length and how do I calculate it (assuming UTF-8)?
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Илья Рассадин
2018-09-18 16:55:01 UTC
Permalink
Hi!

Please, provide a code example (with any paste service, like
gist.github.com), so we can see how you  create request object and give
you advice.
Post by Steve Dondley
I'm starting a new thread related to the previous one regarding making
a batch api request to Google's API. I keep getting "Bad Reqeust"
responses from Google after making a batch API call (other calls work
fine).
Looking at the api documentation for batch api requests
<https://developers.google.com/gmail/api/guides/batch> it says each
part of the multipart request should have a content length. Here is
POST /batch/farm/v1 HTTP/1.1
Authorization: Beareryour_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length:total_content_length
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals/pony
--batch_foobarbaz
Content-Type: application/http
PUT /farm/v1/animals/sheep
Content-Type: application/json
Content-Length:part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals
If-None-Match: "etag/animals"
--batch_foobarbaz--
The requests I'm generating with mojolicious do not have the
|
POST /batch/gmail/v1 HTTP/1.1
Authorization:BearerA_REAL_TOKEN_GOES_HERE
Host:www.googleapis.com
Accept-Encoding:gzip
Content-Length:120
User-Agent:Mojolicious(Perl)
Content-Type:multipart/mixed;boundary=nS2CX
--nS2CX
Content-Type:application/http
--nS2CX--
|
My question is, does Mojolicious provide a way to automatically
generate a content length header for these parts? If not, which parts
of the message get counted toward this length and how do I calculate
it (assuming UTF-8)?
--
You received this message because you are subscribed to the Google
Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Steve Dondley
2018-09-18 17:00:06 UTC
Permalink
My code is on another
thread: https://groups.google.com/forum/#!topic/mojolicious/36fqlY31icg

For now, I'm just trying to figure out how to accurately generate the
"content-length" for each part of the mulitpart HTTP request.
Post by Илья Рассадин
Hi!
Please, provide a code example (with any paste service, like
gist.github.com), so we can see how you create request object and give
you advice.
I'm starting a new thread related to the previous one regarding making a
batch api request to Google's API. I keep getting "Bad Reqeust" responses
from Google after making a batch API call (other calls work fine).
Looking at the api documentation for batch api requests
<https://developers.google.com/gmail/api/guides/batch> it says each part
of the multipart request should have a content length. Here is the example
POST /batch/farm/v1 HTTP/1.1
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals/pony
--batch_foobarbaz
Content-Type: application/http
PUT /farm/v1/animals/sheep
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals
If-None-Match: "etag/animals"
--batch_foobarbaz--
The requests I'm generating with mojolicious do not have the
POST /batch/gmail/v1 HTTP/1.1
Authorization: Bearer A_REAL_TOKEN_GOES_HERE
Host: www.googleapis.com
Accept-Encoding: gzip
Content-Length: 120
User-Agent: Mojolicious (Perl)
Content-Type: multipart/mixed; boundary=nS2CX
--nS2CX
Content-Type: application/http
--nS2CX--
My question is, does Mojolicious provide a way to automatically generate a
content length header for these parts? If not, which parts of the message
get counted toward this length and how do I calculate it (assuming UTF-8)?
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Steve Dondley
2018-09-18 17:05:36 UTC
Permalink
You can also see my code here: https://perlmonks.org/?node_id=1222593
Post by Илья Рассадин
Hi!
Please, provide a code example (with any paste service, like
gist.github.com), so we can see how you create request object and give
you advice.
I'm starting a new thread related to the previous one regarding making a
batch api request to Google's API. I keep getting "Bad Reqeust" responses
from Google after making a batch API call (other calls work fine).
Looking at the api documentation for batch api requests
<https://developers.google.com/gmail/api/guides/batch> it says each part
of the multipart request should have a content length. Here is the example
POST /batch/farm/v1 HTTP/1.1
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals/pony
--batch_foobarbaz
Content-Type: application/http
PUT /farm/v1/animals/sheep
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals
If-None-Match: "etag/animals"
--batch_foobarbaz--
The requests I'm generating with mojolicious do not have the
POST /batch/gmail/v1 HTTP/1.1
Authorization: Bearer A_REAL_TOKEN_GOES_HERE
Host: www.googleapis.com
Accept-Encoding: gzip
Content-Length: 120
User-Agent: Mojolicious (Perl)
Content-Type: multipart/mixed; boundary=nS2CX
--nS2CX
Content-Type: application/http
--nS2CX--
My question is, does Mojolicious provide a way to automatically generate a
content length header for these parts? If not, which parts of the message
get counted toward this length and how do I calculate it (assuming UTF-8)?
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Dan Book
2018-09-18 17:06:10 UTC
Permalink
These "parts" are essentially embedded HTTP requests; the lines under each
listed GET/PUT/etc are headers for that embedded request. Here is the
structure of their example annotated:

POST /batch/farm/v1 HTTP/1.1 # actual request and headers
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
# rest is actual request content
--batch_foobarbaz # first multipart segment
Content-Type: application/http # multipart segment headers
Content-ID: <item1:***@barnyard.example.com>

GET /farm/v1/animals/pony # multipart segment *content*

--batch_foobarbaz # second multipart segment
Content-Type: application/http # multipart segment headers
Content-ID: <item2:***@barnyard.example.com>

PUT /farm/v1/animals/sheep # multipart segment *content*
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"

{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}

--batch_foobarbaz # third multipart segment
Content-Type: application/http # multipart segment headers
Content-ID: <item3:***@barnyard.example.com>

GET /farm/v1/animals # multipart segment *content*
If-None-Match: "etag/animals"

--batch_foobarbaz--

As noted the part where the part_content_length is is inside the content
for one of the multipart segments. Mojolicious doesn't have anything to
deal with the content of multipart segments of this type, so you need to
construct them yourself, but you could maybe leverage Mojolicious's
existing ability to construct such HTTP requests.

my $embedded_tx = $ua->build_tx(PUT => '/farm/v1/animals/sheep',
{'If-Match' => 'etag/sheep'}, json => $sheep_data);
...
my $multipart_tx = $ua->post('/batch/farm/v1' => $headers => multipart => [
{content => $embedded_tx->req->to_string, 'Content-Type' =>
'application/http'},
...
]);

Hope that helps,
-Dan
Post by Steve Dondley
I'm starting a new thread related to the previous one regarding making a
batch api request to Google's API. I keep getting "Bad Reqeust" responses
from Google after making a batch API call (other calls work fine).
Looking at the api documentation for batch api requests
<https://developers.google.com/gmail/api/guides/batch> it says each part
of the multipart request should have a content length. Here is the example
POST /batch/farm/v1 HTTP/1.1
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals/pony
--batch_foobarbaz
Content-Type: application/http
PUT /farm/v1/animals/sheep
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals
If-None-Match: "etag/animals"
--batch_foobarbaz--
The requests I'm generating with mojolicious do not have the
POST /batch/gmail/v1 HTTP/1.1
Authorization: Bearer A_REAL_TOKEN_GOES_HERE
Host: www.googleapis.com
Accept-Encoding: gzip
Content-Length: 120
User-Agent: Mojolicious (Perl)
Content-Type: multipart/mixed; boundary=nS2CX
--nS2CX
Content-Type: application/http
--nS2CX--
My question is, does Mojolicious provide a way to automatically generate a
content length header for these parts? If not, which parts of the message
get counted toward this length and how do I calculate it (assuming UTF-8)?
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Steve Dondley
2018-09-18 17:28:03 UTC
Permalink
Thanks. It doesn't look like adding the content-length helped. Still
getting 400 errors. And I just noticed that in Google's example there is no
content-length header for a GET request. Don't know what else to try now.
Post by Dan Book
These "parts" are essentially embedded HTTP requests; the lines under each
listed GET/PUT/etc are headers for that embedded request. Here is the
POST /batch/farm/v1 HTTP/1.1 # actual request and headers
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
# rest is actual request content
--batch_foobarbaz # first multipart segment
Content-Type: application/http # multipart segment headers
GET /farm/v1/animals/pony # multipart segment *content*
--batch_foobarbaz # second multipart segment
Content-Type: application/http # multipart segment headers
PUT /farm/v1/animals/sheep # multipart segment *content*
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz # third multipart segment
Content-Type: application/http # multipart segment headers
GET /farm/v1/animals # multipart segment *content*
If-None-Match: "etag/animals"
--batch_foobarbaz--
As noted the part where the part_content_length is is inside the content
for one of the multipart segments. Mojolicious doesn't have anything to
deal with the content of multipart segments of this type, so you need to
construct them yourself, but you could maybe leverage Mojolicious's
existing ability to construct such HTTP requests.
my $embedded_tx = $ua->build_tx(PUT => '/farm/v1/animals/sheep',
{'If-Match' => 'etag/sheep'}, json => $sheep_data);
...
my $multipart_tx = $ua->post('/batch/farm/v1' => $headers => multipart => [
{content => $embedded_tx->req->to_string, 'Content-Type' =>
'application/http'},
...
]);
Hope that helps,
-Dan
Post by Steve Dondley
I'm starting a new thread related to the previous one regarding making a
batch api request to Google's API. I keep getting "Bad Reqeust" responses
from Google after making a batch API call (other calls work fine).
Looking at the api documentation for batch api requests
<https://developers.google.com/gmail/api/guides/batch> it says each part
of the multipart request should have a content length. Here is the example
POST /batch/farm/v1 HTTP/1.1
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals/pony
--batch_foobarbaz
Content-Type: application/http
PUT /farm/v1/animals/sheep
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals
If-None-Match: "etag/animals"
--batch_foobarbaz--
The requests I'm generating with mojolicious do not have the
POST /batch/gmail/v1 HTTP/1.1
Authorization: Bearer A_REAL_TOKEN_GOES_HERE
Host: www.googleapis.com
Accept-Encoding: gzip
Content-Length: 120
User-Agent: Mojolicious (Perl)
Content-Type: multipart/mixed; boundary=nS2CX
--nS2CX
Content-Type: application/http
--nS2CX--
My question is, does Mojolicious provide a way to automatically generate
a content length header for these parts? If not, which parts of the message
get counted toward this length and how do I calculate it (assuming UTF-8)?
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2018-09-18 17:39:21 UTC
Permalink
Looks to me like it's just normal HTTP requests wrapped in a multipart HTTP
request.

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Dan Book
2018-09-18 17:47:54 UTC
Permalink
I think you missed something in my post. You should not need to add any
content length headers yourself.

-Dan
Post by Steve Dondley
Thanks. It doesn't look like adding the content-length helped. Still
getting 400 errors. And I just noticed that in Google's example there is no
content-length header for a GET request. Don't know what else to try now.
Post by Dan Book
These "parts" are essentially embedded HTTP requests; the lines under
each listed GET/PUT/etc are headers for that embedded request. Here is the
POST /batch/farm/v1 HTTP/1.1 # actual request and headers
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
# rest is actual request content
--batch_foobarbaz # first multipart segment
Content-Type: application/http # multipart segment headers
GET /farm/v1/animals/pony # multipart segment *content*
--batch_foobarbaz # second multipart segment
Content-Type: application/http # multipart segment headers
PUT /farm/v1/animals/sheep # multipart segment *content*
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz # third multipart segment
Content-Type: application/http # multipart segment headers
GET /farm/v1/animals # multipart segment *content*
If-None-Match: "etag/animals"
--batch_foobarbaz--
As noted the part where the part_content_length is is inside the content
for one of the multipart segments. Mojolicious doesn't have anything to
deal with the content of multipart segments of this type, so you need to
construct them yourself, but you could maybe leverage Mojolicious's
existing ability to construct such HTTP requests.
my $embedded_tx = $ua->build_tx(PUT => '/farm/v1/animals/sheep',
{'If-Match' => 'etag/sheep'}, json => $sheep_data);
...
my $multipart_tx = $ua->post('/batch/farm/v1' => $headers => multipart => [
{content => $embedded_tx->req->to_string, 'Content-Type' =>
'application/http'},
...
]);
Hope that helps,
-Dan
Post by Steve Dondley
I'm starting a new thread related to the previous one regarding making a
batch api request to Google's API. I keep getting "Bad Reqeust" responses
from Google after making a batch API call (other calls work fine).
Looking at the api documentation for batch api requests
<https://developers.google.com/gmail/api/guides/batch> it says each
part of the multipart request should have a content length. Here is the
POST /batch/farm/v1 HTTP/1.1
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals/pony
--batch_foobarbaz
Content-Type: application/http
PUT /farm/v1/animals/sheep
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals
If-None-Match: "etag/animals"
--batch_foobarbaz--
The requests I'm generating with mojolicious do not have the
POST /batch/gmail/v1 HTTP/1.1
Authorization: Bearer A_REAL_TOKEN_GOES_HERE
Host: www.googleapis.com
Accept-Encoding: gzip
Content-Length: 120
User-Agent: Mojolicious (Perl)
Content-Type: multipart/mixed; boundary=nS2CX
--nS2CX
Content-Type: application/http
--nS2CX--
My question is, does Mojolicious provide a way to automatically generate
a content length header for these parts? If not, which parts of the message
get counted toward this length and how do I calculate it (assuming UTF-8)?
--
You received this message because you are subscribed to the Google
Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Steve Dondley
2018-09-18 18:47:13 UTC
Permalink
I figure it out! So, I needed to throw in a blank line (\r\n) at the end of
the GET request inside of the POST request.

Now the question is, is this a mojolicious bug or not? Is the content
inside of a multipart post request required to have a blank line after it?
Post by Dan Book
I think you missed something in my post. You should not need to add any
content length headers yourself.
-Dan
Post by Steve Dondley
Thanks. It doesn't look like adding the content-length helped. Still
getting 400 errors. And I just noticed that in Google's example there is no
content-length header for a GET request. Don't know what else to try now.
Post by Dan Book
These "parts" are essentially embedded HTTP requests; the lines under
each listed GET/PUT/etc are headers for that embedded request. Here is the
POST /batch/farm/v1 HTTP/1.1 # actual request and headers
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
# rest is actual request content
--batch_foobarbaz # first multipart segment
Content-Type: application/http # multipart segment headers
GET /farm/v1/animals/pony # multipart segment *content*
--batch_foobarbaz # second multipart segment
Content-Type: application/http # multipart segment headers
PUT /farm/v1/animals/sheep # multipart segment *content*
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz # third multipart segment
Content-Type: application/http # multipart segment headers
GET /farm/v1/animals # multipart segment *content*
If-None-Match: "etag/animals"
--batch_foobarbaz--
As noted the part where the part_content_length is is inside the content
for one of the multipart segments. Mojolicious doesn't have anything to
deal with the content of multipart segments of this type, so you need to
construct them yourself, but you could maybe leverage Mojolicious's
existing ability to construct such HTTP requests.
my $embedded_tx = $ua->build_tx(PUT => '/farm/v1/animals/sheep',
{'If-Match' => 'etag/sheep'}, json => $sheep_data);
...
my $multipart_tx = $ua->post('/batch/farm/v1' => $headers => multipart => [
{content => $embedded_tx->req->to_string, 'Content-Type' =>
'application/http'},
...
]);
Hope that helps,
-Dan
Post by Steve Dondley
I'm starting a new thread related to the previous one regarding making
a batch api request to Google's API. I keep getting "Bad Reqeust" responses
from Google after making a batch API call (other calls work fine).
Looking at the api documentation for batch api requests
<https://developers.google.com/gmail/api/guides/batch> it says each
part of the multipart request should have a content length. Here is the
POST /batch/farm/v1 HTTP/1.1
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals/pony
--batch_foobarbaz
Content-Type: application/http
PUT /farm/v1/animals/sheep
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"
{
"animalName": "sheep",
"animalAge": "5"
"peltColor": "green",
}
--batch_foobarbaz
Content-Type: application/http
GET /farm/v1/animals
If-None-Match: "etag/animals"
--batch_foobarbaz--
The requests I'm generating with mojolicious do not have the
POST /batch/gmail/v1 HTTP/1.1
Authorization: Bearer A_REAL_TOKEN_GOES_HERE
Host: www.googleapis.com
Accept-Encoding: gzip
Content-Length: 120
User-Agent: Mojolicious (Perl)
Content-Type: multipart/mixed; boundary=nS2CX
--nS2CX
Content-Type: application/http
--nS2CX--
My question is, does Mojolicious provide a way to automatically
generate a content length header for these parts? If not, which parts of
the message get counted toward this length and how do I calculate it
(assuming UTF-8)?
--
You received this message because you are subscribed to the Google
Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2018-09-18 18:52:59 UTC
Permalink
Post by Steve Dondley
Now the question is, is this a mojolicious bug or not? Is the content
inside of a multipart post request required to have a blank line after it?
We don't have bugs this obvious. You appear to be misunderstanding what's
happening there. Those multipart parts appear to be properly formatted HTTP
requests.

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Steve Dondley
2018-09-18 19:25:56 UTC
Permalink
This wouldn't qualify as an "obvious" bug if the RFC stipulated that all
parts of type "application/type" had to have a blank line before the
boundary. I have no idea if it does or doesn't, of course. But that would
be something very hard to know and be "non-obvious."

At any rate, Google seems to require the extra blank line. Either they have
deviated from the RFC or team Mojolicious has. Google isn't known for
overlooking obvious bugs either.
Post by Steve Dondley
Now the question is, is this a mojolicious bug or not? Is the content
Post by Steve Dondley
inside of a multipart post request required to have a blank line after it?
We don't have bugs this obvious. You appear to be misunderstanding what's
happening there. Those multipart parts appear to be properly formatted HTTP
requests.
--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Loading...