HTTP element QUERY_STRING is longer than the (1024 * 10) allowed length (was 13692)


#1

I am getting below error while passing huge query string in AJAX.I am using Puma Server.How to fix this issue in puma server?

HTTP parse error, malformed request ():<Puma::HttpParserError: HTTP element 
 QUERY_STRING is longer than the (1024 * 10) allowed length (was 13692)>

Is there any other app server available for Concurrency and support long URI?

Thanks,
Raja


#2

It’s not a good idea to send that long query with GET request. Even if you are able to change puma settings to allow that you still shouldn’t do it. Every browser and server (nginx etc) has its own limit and you will not pass it. POST request don’t have this limitation so you should use it.


#3

Thanks.I tried post also.I am getting same error.Routes also do I need to make change post instead of get.


#4

If you get exactly the same error with POST request then you still trying to pass data through QUERY string rather than really send it as POST payload. Could you please paste code of this AJAX you send?


#5

Yes sure.Below the code I am using.

if (Device1) {
  parameter_name = $('#parameters_object').val();
  var getParams=parameter_name.split(',');
  paramLen=getParams.length;
  alert(paramLen);
  if (paramLen > 200){

  }

  //m is a selected mac address length count
  for (var i = 0; i < m; i++) {

    (function () {

      var macAdd = values[i];
      $.ajax({
          method: "POST",
          url: "get_object",
          dataType: "json",
          data: {
            parameter: getParams,
            mac: macAdd,
            protocol: protocol,
            serialnumber: serialnumber,
          },

          success: function (result) {
            console.log(result);

          }
        },

        statusCode: {
        404: function () {
          console.log("Call failed");
        }
      }
    });

  })();

}

#6

Hm, it looks ok. Please, have a look on that problematic request in chrome (or other browser you use) dev tool. You should see exactly how browser send request (chosen method, request url, payload etc). Maybe that request is not send by the code you pasted here. Anyway, error clearly indicated that the problem is that query string (it’s the part after ‘?’ in url) is too long.


#7

Yes.I will pass around 300 parameters with comma separated.that is the reason I am getting this error.But Webrix server it is working fine.Since Webrix is slow and not supporting Concurrency,we have moved to puma.


#8

My answer remains. Move those query string parameters to data parameters of your POST request. Even if did work with webrick it possibly could not work with some browsers. Please, read https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers.


#9

Ok Thanks.How to move from query string to data parameters? If I changed as form data instead of json,will it work?


#10

It should work as json as well as form data. Your code looks good already. TBH I don’t know what the problem is. Maybe you could prepare working example of your problem? Try to isolate entire code (html, js + simple app running on puma) and create github repo which I can clone and try to run? Without having reproducible example I can’t help.


#11

Thanks for your time.I have tried with POST request.I am getting below error.

ActionDispatch::ParamsParser::ParseError (822: unexpected token at params).

Do i need make changes in rails controller?


#12

Oh, now I noticed you didn’t specify contentType header in your request (dataType sets expected response from browser, it has nothing to do with how you send data). Also you have to convert your data (javascript object) to json format.

$.ajax({
  url: "/my_url"
  method: "POST",
  contentType: "application/json",
  data: JSON.stringify({ foo: "bar" })
})

You can also try as a normal form data (x-www-form-urlencoded content type)

$.ajax({
  url: "/my_url"
  method: "POST",
  data: "foo=bar"
})

#13

Thanks lot.It is working now.


#14

I am able to post request with insert huge data into db.But I am getting below error if i am trying to POST in webservice call.
“Curl::Err::ConnectionFailedError”

I am passing parameters as below in rails

@macAddress= params[‘mac’]
@model=params[‘parameter’]


#15

My Controller code below

def get_object
  result_hash=Hash.new
  result_hash["pa"]=false
  result = ''
  begin

    if params['protocol']['pa'] == "true"
        result_hash["pa"]=true
      client=ClientCall.new
      @macAddress= params['mac']

     @model=params['parameter']
      if @model.to_s.first ==","
        @model = @model[1..-1]
      end

      total_params = 1

      if @dataModel.include? (",")
        paramArray = @model.split(/\s*,\s*/)
        p "After Conversion"
        p paramArray

        total_params = paramArray.length
      end

     if total_params==1

            if @macAddress.nil?
              redirect_to root_path
            elsif @model.nil?
              redirect_to root_path
            end
            response=client.get_call(@macAddress, @dataModel)
            redis_client=Redis.new
            access_token=redis_client["Pa:SATToken"]

            response_time = client.response_time

            p "RESPONSE_TIME = #{response_time}"

            p "Encoding = #{response.body.encoding}"


            response.body.force_encoding('ISO-8859-1').encode("UTF-8")

            p response.body

            if access_token.nil?
              sat_client=SatClient.new
              response = sat_client.get_sat_token
              body=JSON.parse(response.body)
              if response.code == "200"
                access_token=body["access_token"]
                p "Storing Token in Redis"
                redis_client=Redis.new
                redis_client["Pa:SATToken"]=access_token
                return access_token
              else
                p "SAT endpoint returned #{response.code}"
                p "#{response.body}"
                raise "Retrieving SAT Token call failed"
              end
            end

            result_hash["response"]={"status": response.code,"parameter_name": @model.to_s, "body": response.body ,"accesstoken": access_token, "response_time": response_time.to_s};

      else

        result_hash["response"]={"status": "520", "body": "" };

        end

#16

As error says you have problem with making connection. I can only guess it’s somewhere in ClientCall or SatClient class.


#18

Thanks.