Azure / azure-relay-java

Azure Relay Java SDK
MIT License
8 stars 9 forks source link

[HTTP] Multiple headers are not supported #64

Closed mruszews closed 4 years ago

mruszews commented 4 years ago

It's impossible to send a request or response containing multiple headers with the same name.

To replicate the issue add few lines to 'simple-http-demo' (HttpSender.java):

// Sending an HTTP request to the listener
// To send a message body, use POST
conn.setRequestMethod((message == null || message.length() == 0) ? "GET" : "POST");
conn.setRequestProperty("ServiceBusAuthorization", tokenString);

// add 2 headers with the same name
conn.setRequestProperty("Content-Type", "application/json");
conn.addRequestProperty("Content-Type", "application/xml");
dlstucki commented 4 years ago

Will you share the call stack? In this example the HTTP sender doesn't use anything relay specific other than the library to help format the auth header. It's very likely the error is from URLConnection class itself.

URLConnection.addRequestProperty docs state:

This method will not overwrite existing values associated with the same key.

URLConnection.setRequestProperty docs suggest that using comma separated values is the solution here when using Java's URLConnection class:

Sets the general request property. If a property with the key already exists, overwrite its value with the new value. NOTE: HTTP requires all request properties which can legally have multiple instances with the same key to use a comma-separated list syntax which enables multiple properties to be appended into a single property.

Can you try your scenario using comma separated values and not calling addRequestProperty if a value already exists?

mruszews commented 4 years ago

Thanks for a quick response. Indeed coma separated values would work. However we'd like to investigate more double headers scenario.

I agree with your comment about URlConnection. Nonetheless this example doesn't exactly reflect our case. We use HybridConnectionListeners (https://github.com/Azure/azure-relay-java#creating-listeners) for communication.

Stacktrace: ==> java.io.IOException - java.lang.RuntimeException: org.eclipse.jetty.io.EofException at: HybridHttpConnection$ResponseStream.write(HybridHttpConnection.java:381)

Does it make any difference?

dlstucki commented 4 years ago

To clarify, you're setting the response headers in the HybridConnectionListener's requestHandler by calling context.getResponse().getHeaders().put(...) (where context is the RelayedHttpListenerContext) multiple times with the same key? If the keys are the same how does it hold two values for the same header name?

@bainian12345 want to take a look?

mruszews commented 4 years ago

Good point. Seems like we've got an issue on our side. Let us investigate more 1-2 days, before closing this issue.

Thanks!