Welcome to the "trac"-ing site of http-access2!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

Ticket #29 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

"\n" should be "CRLF" in create_query_multipart_str method

Reported by: bsdmad@gmail.com Assigned to: nahi
Priority: high Milestone: 2.0.7
Component: core Version: 2.0
Keywords: Cc:

Description

With ver. 2.0.6, we can POST multipart data. It's very convenient.But "\n" is used as line end in create_query_multipart_srt method and it should be "CRLF" which you have defined as "\r\n".

And I have added support of some files for mime_type method and some modification. Following are patch for lib/http.rb

*** http.rb.orig	2006-01-16 13:47:12.000000000 +0900
--- http.rb	2006-01-16 14:08:17.000000000 +0900
***************
*** 474,488 ****
              param_str = params.to_a.collect { |k, v|
                "#{k}=\"#{v}\""
              }.join("; ")
!             "--#{boundary}\n" +
!               %{Content-Disposition: form-data; name="#{attr.to_s}"; #{param_str}\n} +
!               "Content-Type: #{mime_type(value.path)}\n\n#{value.read}\n"
            else
!             "--#{boundary}\n" +
!               %{Content-Disposition: form-data; name="#{attr.to_s}"\n} +
!               "\n#{value.to_s}\n"
            end
!         }.join('') + "--#{boundary}--\n"
        else
          query.to_s
        end
--- 474,488 ----
              param_str = params.to_a.collect { |k, v|
                "#{k}=\"#{v}\""
              }.join("; ")
!             "--#{boundary}" + CRLF +
!               %{Content-Disposition: form-data; name="#{attr.to_s}"; #{param_str}} + CRLF +
!               "Content-Type: #{mime_type(value.path)}" + CRLF + CRLF + "#{value.read}" + CRLF
            else
!             "--#{boundary}" + CRLF +
!               %{Content-Disposition: form-data; name="#{attr.to_s}"} + CRLF +
!               CRLF + "#{value.to_s}" + CRLF
            end
!         }.join('') + "--#{boundary}--" + CRLF
        else
          query.to_s
        end
***************
*** 507,518 ****
  
      def mime_type(path)
        case path
!       when /.(htm|html)$/
          'text/html'
!       when /.doc$/
          'application/msword'
        else
!         'text/plain'
        end
      end
    end
--- 507,526 ----
  
      def mime_type(path)
        case path
!       when /\.txt$/i
!         'text/plain'
!       when /\.(htm|html)$/i
          'text/html'
!       when /\.doc$/i
          'application/msword'
+       when /\.png/i
+         'image/png'
+       when /\.gif$/i
+         'image/gif'
+       when /\.jp[e]*g$/i
+         'image/jpeg'
        else
!         'application/unknown'
        end
      end
    end

Change History

05/29/06 05:06:48 changed by kkkkoaaa

  • summary changed from "\n" should be "CRLF" in create_query_multipart_str method to "\n" should be "CRLF" in create_query_multipart_str method.

Keep a good job up! http://quick-adult-links.com

06/07/06 16:07:37 changed by matt@thekerns.net

I second this patch. The "\n" instead of CRLF results in disastrous results with cgi.rb from stdlib. The result of posting a multipart form with http-access2 to a CGI.rb script is "bad content body". Changing the "\n" in create_query_multipart_str(query, boundary) allows cgi.rb to process the POST.

06/07/06 16:14:32 changed by matt@thekerns.net

FYI CRLF is defined as the line ending according to RFC 1867 section 5.9.

07/17/06 13:06:58 changed by nahi

  • priority changed from normal to high.
  • milestone changed from undefined to 2.0.7.

07/17/06 13:22:50 changed by nahi

  • status changed from new to closed.
  • resolution set to fixed.

(In [118]) use CRLF for multipart form posting (used \n). fixes #29, #116.