Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetty default headers #1

Open
GentlemanHal opened this issue Apr 30, 2013 · 4 comments
Open

Jetty default headers #1

GentlemanHal opened this issue Apr 30, 2013 · 4 comments

Comments

@GentlemanHal
Copy link

Jetty seems to return a few default headers for every call, for example:

Content-Length: 0,
Server: Jetty(8.1.5.v20120716)

This makes matching on the returned response more annoying as you can't just match on everything returned.

Is it possible to stop Jetty adding any headers?

Or as an alternative, expose the Jetty server string so you can easily include the default headers in your expectations (without needing to hardcode it)?

@ghost ghost assigned tusharm Apr 30, 2013
@tusharm
Copy link
Owner

tusharm commented Apr 30, 2013

Hey, looking into it. Let me get back to you.

@tusharm
Copy link
Owner

tusharm commented May 1, 2013

Hi,

The Content-Length/Server are standard response headers defined by HTTP RFC. Ability to suppress them might result in usages which violate the spec (see http://tools.ietf.org/html/rfc2616#section-4.4 for cases related to Content-Length).

How exactly are you trying to match against the expected response? Could you not just match the specific parts of the response that your test cares about? This would keep the tests less fragile too.

@GentlemanHal
Copy link
Author

Hey,

I don't consider this a bug but more of an enhancement, so feel free to close this issue if you don't think this is a good idea :)

I'm building a http client wrapping library so I'm actually testing the response is correctly transformed into the libraries version. I'd really like to just be able to write my tests something like the following:

val expectedResponse = HttpResponseBuilder(status, body, headers).build
val actualResponse = httpClient.get(foo)

actualResponse should be(expectedResponse)

Having to check just the headers I set is possible and quite easy, it just means the test doesn't read quite as nicely and more importantly it potentially masks errors such as additional headers getting added by the transformation.

Edit: I'm able to work around this by manually setting the Server header (so I don't have to worry about Jetty getting upgraded and breaking all my test), allowing me to write my tests as mentioned above.

The reason I decided to raise this was because, since this is a stubbing library I consider this a similar scenario to something like Mockito stubbing adding in extra items to Lists it returns. I don't think the specs should matter here.

@tusharm
Copy link
Owner

tusharm commented May 1, 2013

I see where you had a problem, sounds sensible. I am closing this but marking it as an enhancement. Thx!

@tusharm tusharm closed this as completed May 1, 2013
@tusharm tusharm reopened this May 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants