Page 1 of 1
Length of HTTP request
Posted: Fri Mar 04, 2022 8:49 pm
by Joerg Hamacher
Hi,
I'd like to know if there is a maximum length for a HTTP-request-body.
I use the Request using #XPRIM_HttpRequest.Content.AddString method in a loop like this (using a NVarChar text field of length 65535.
Define_Com Class(#XPRIM_HttpRequest) Name(#HTTP_Request)
Begin_Loop
....
#HTTP_Request.Content.AddString Value(#TEXT65535)
End_Loop
How many AddString operations are possible before "destroying" the request?
Best regards,
Joerg
Re: Length of HTTP request
Posted: Sat Mar 05, 2022 9:21 am
by Dino
Hi Joerg
I can see the request.body.log that you see in the #XPRIM_OSUtil trace is limited to 64K, so even one time of that loop with a string filled completely in their 65535 characters, wont show up correctly there. now, that is just the trace log. I don't think there is a limitation for the writer, because a program like this can write whatever amount of json code:
Code: Select all
Begin_Com Role(*EXTENDS #PRIM_SRVM)
Define_Com Class(#XPRIM_HttpRequest) Name(#Request) Scope(*Application)
Define_Com Class(#XPRIM_JsonWriter) Name(#Writer)
Define Field(#TEXT65535) Type(*String) Length(65535)
Define_Com Class(#prim_ioc.FileStream) Name(#OutputStream) FileAccess(Write) FileMode(CreateNew) FileShare(Write)
Define_Com Class(#prim_ioc.StreamWriter) Name(#StreamWriter) Stream(#OutputStream)
Srvroutine Name(returnsjson)
#OutputStream.Path := 'aaa100.json'
#Writer.SetOutputToFile Path(#OutputStream.Path)
#Request.Clear
#Writer.BeginObject
Begin_Loop Using(#STD_NUM) To(100)
#TEXT65535 := #STD_NUM.AsString.Repeat( 65535 )
#Writer.WriteString Name('text') Value(#TEXT65535)
End_Loop
#Writer.EndObject
Endroutine
End_Com
I can run up to 100,000 times without problem generating a super long json file. I stopped at 100,000 because i will need more disk and because it won't make sense for a communication, you most likely will have a http timeout long before.
I was able to open the 10,000 with the notepad++

Re: Length of HTTP request
Posted: Sat Mar 05, 2022 10:12 am
by Dino
Ok, following on this:
- I just created a table STRTABLE with 4 fields STRID, plus STRLONG1-3 type STRING (65535).
- then created a server module STRTABLERES to publish it as a restful service for my object MANYSTR
- Then created a sample web page and a server module to perform a maintenance doing a PUT in that table to store the information:
Below is the code that i used for the server module and I can see that the request.body.log exceed the 64k with no problem,
even in the #OSUtil trace so the http request can have more than 64kb. I didn't test the limit but I dont think is restricted to 65535.
this is the code I used for the PUT:
Code: Select all
#Url.SetScheme( 'http' )
#Url.SetHost( 'localhost:8080' )
#Url.SetPath( ("/" + #partition + "/STRTABLERES/MANYSTRs/" + #STRID) )
#JsonObject.InsertString Key("STRID") String(#STRID)
#JsonObject.InsertString Key("STRLONG1") String(#STRLONG1)
#JsonObject.InsertString Key("STRLONG2") String(#STRLONG2)
#JsonObject.InsertString Key("STRLONG3") String(#STRLONG3)
#Req.Content.AddJsonObject( #JsonObject )
* Execute the request (POST verb)
#Req.DoPut Url(#Url)

Re: Length of HTTP request
Posted: Sat Mar 05, 2022 10:35 am
by Dino
ok, last computer fun before to start the weekend....
modified the call in the server module adding the loop and fictitious fields that the service don't need:
Code: Select all
#JsonObject.InsertString Key("STRID") String(#STRID)
#JsonObject.InsertString Key("STRLONG1") String(#STRLONG1)
#JsonObject.InsertString Key("STRLONG2") String(#STRLONG2)
#JsonObject.InsertString Key("STRLONG3") String(#STRLONG3)
Begin_Loop Using(#STD_NUM) To(1000)
#JsonObject.InsertString Key("STRLONG_EXTRA" + #STD_NUM.AsString) String(#STRLONG3)
End_Loop
#JsonObject.InsertString Key("STRLONGZZZZ") String('ZZZ')
it generated a request.body of 64MB without problem, characters inside are correct till the last byte.
have a great weekend!