Rest-client converting underscores to hyphens in user headers


John Collins <john@...>
 

Hi all,

I have a Ruby REST client application that is using your gem (which is
great btw). My client has to pass some HTTP headers in the request like so:

HEADER_KEY: value

But when I use these with your gem they get converted to:

Header-Key: value

The case switch is not an issue as HTTP headers are case insensitive
anyway, but converting the underscore to a hyphen is breaking my
client/server contract.

Digging into your code, it looks like the following line of the
make_headers method in the request.rb file is doing the conversion:

target_key = key.to_s.gsub(/_/, '-').capitalize

My understanding is that an underscore is a valid character to have in a
HTTP header, according to the specification. Can I ask what the
motivation was in including this code? I can monkey-patch the gem code
from my app to override this, but I'd rather not.

Thanks,

John.


"François Beausoleil <francois@...>
 

Hello John,

This is to support the use case of having Symbol as keys:

RestClient.post("url", :content_type => "text/plain")

:content_type becomes "Content-Type"

It might be a good idea to only convert Symbols, as opposed to Strings.

Thoughts?
Bye!
François

Le 2010-04-29 à 11:52, John Collins a écrit :

Hi all,

I have a Ruby REST client application that is using your gem (which is
great btw). My client has to pass some HTTP headers in the request like so:

HEADER_KEY: value

But when I use these with your gem they get converted to:

Header-Key: value

The case switch is not an issue as HTTP headers are case insensitive
anyway, but converting the underscore to a hyphen is breaking my
client/server contract.

Digging into your code, it looks like the following line of the
make_headers method in the request.rb file is doing the conversion:

target_key = key.to_s.gsub(/_/, '-').capitalize

My understanding is that an underscore is a valid character to have in a
HTTP header, according to the specification. Can I ask what the
motivation was in including this code? I can monkey-patch the gem code
from my app to override this, but I'd rather not.

Thanks,

John.


John Collins <john@...>
 

Hi François,

Just to confirm, I am passing a string rather than a symbol so your proposal not to convert strings would work for me.

Thanks,

John.

François Beausoleil wrote at 29/04/2010 16:55:

Hello John,

This is to support the use case of having Symbol as keys:

RestClient.post("url", :content_type => "text/plain")

:content_type becomes "Content-Type"

It might be a good idea to only convert Symbols, as opposed to Strings.

Thoughts?
Bye!
François

Le 2010-04-29 à 11:52, John Collins a écrit :

  
Hi all,

I have a Ruby REST client application that is using your gem (which is 
great btw).  My client has to pass some HTTP headers in the request like so:

HEADER_KEY: value

But when I use these with your gem they get converted to:

Header-Key: value

The case switch is not an issue as HTTP headers are case insensitive 
anyway, but converting the underscore to a hyphen is breaking my 
client/server contract.

Digging into your code, it looks like the following line of the 
make_headers method in the request.rb file is doing the conversion:

target_key = key.to_s.gsub(/_/, '-').capitalize

My understanding is that an underscore is a valid character to have in a 
HTTP header, according to the specification.  Can I ask what the 
motivation was in including this code?  I can monkey-patch the gem code 
from my app to override this, but I'd rather not.

Thanks,

John.
    
  


Archiloque <code@...>
 

This week end I'll ship the 1.5.0 version and fix the code the way François suggested it.

Cheers

A.

Le 29 avr. 2010 à 18:06, John Collins a écrit :

Hi François,

Just to confirm, I am passing a string rather than a symbol so your proposal not to convert strings would work for me.

Thanks,

John.

François Beausoleil wrote at 29/04/2010 16:55:

Hello John,

This is to support the use case of having Symbol as keys:

RestClient.post("url", :content_type => "text/plain")

:content_type becomes "Content-Type"

It might be a good idea to only convert Symbols, as opposed to Strings.

Thoughts?
Bye!
François

Le 2010-04-29 à 11:52, John Collins a écrit :


Hi all,

I have a Ruby REST client application that is using your gem (which is
great btw). My client has to pass some HTTP headers in the request like so:

HEADER_KEY: value

But when I use these with your gem they get converted to:

Header-Key: value

The case switch is not an issue as HTTP headers are case insensitive
anyway, but converting the underscore to a hyphen is breaking my
client/server contract.

Digging into your code, it looks like the following line of the
make_headers method in the request.rb file is doing the conversion:

target_key = key.to_s.gsub(/_/, '-').capitalize

My understanding is that an underscore is a valid character to have in a
HTTP header, according to the specification. Can I ask what the
motivation was in including this code? I can monkey-patch the gem code
from my app to override this, but I'd rather not.

Thanks,

John.


John Collins <john@...>
 

Great news, I look forward to upgrading and testing this once it is available!

Thanks,

John.

Archiloque wrote at 29/04/2010 21:36:

This week end I'll ship the 1.5.0 version and fix the code the way François suggested it.

Cheers

A.


Le 29 avr. 2010 à 18:06, John Collins a écrit :

  
Hi François,

Just to confirm, I am passing a string rather than a symbol so your proposal not to convert strings would work for me.

Thanks,

John.

François Beausoleil wrote at 29/04/2010 16:55:
    
Hello John,

This is to support the use case of having Symbol as keys:

RestClient.post("url", :content_type => "text/plain")

:content_type becomes "Content-Type"

It might be a good idea to only convert Symbols, as opposed to Strings.

Thoughts?
Bye!
François

Le 2010-04-29 à 11:52, John Collins a écrit :

  
      
Hi all,

I have a Ruby REST client application that is using your gem (which is 
great btw).  My client has to pass some HTTP headers in the request like so:

HEADER_KEY: value

But when I use these with your gem they get converted to:

Header-Key: value

The case switch is not an issue as HTTP headers are case insensitive 
anyway, but converting the underscore to a hyphen is breaking my 
client/server contract.

Digging into your code, it looks like the following line of the 
make_headers method in the request.rb file is doing the conversion:

target_key = key.to_s.gsub(/_/, '-').capitalize

My understanding is that an underscore is a valid character to have in a 
HTTP header, according to the specification.  Can I ask what the 
motivation was in including this code?  I can monkey-patch the gem code 
from my app to override this, but I'd rather not.

Thanks,

John.
    
        
  
      
  


Archiloque <code@...>
 

I've commited the fix on master, could you validate it ?


Regards

A.

Le 29 avr. 2010 à 18:06, John Collins a écrit :

Hi François,

Just to confirm, I am passing a string rather than a symbol so your proposal not to convert strings would work for me.

Thanks,

John.

François Beausoleil wrote at 29/04/2010 16:55:

Hello John,

This is to support the use case of having Symbol as keys:

RestClient.post("url", :content_type => "text/plain")

:content_type becomes "Content-Type"

It might be a good idea to only convert Symbols, as opposed to Strings.

Thoughts?
Bye!
François

Le 2010-04-29 à 11:52, John Collins a écrit :


Hi all,

I have a Ruby REST client application that is using your gem (which is
great btw). My client has to pass some HTTP headers in the request like so:

HEADER_KEY: value

But when I use these with your gem they get converted to:

Header-Key: value

The case switch is not an issue as HTTP headers are case insensitive
anyway, but converting the underscore to a hyphen is breaking my
client/server contract.

Digging into your code, it looks like the following line of the
make_headers method in the request.rb file is doing the conversion:

target_key = key.to_s.gsub(/_/, '-').capitalize

My understanding is that an underscore is a valid character to have in a
HTTP header, according to the specification. Can I ask what the
motivation was in including this code? I can monkey-patch the gem code
from my app to override this, but I'd rather not.

Thanks,

John.