cactoos-http icon indicating copy to clipboard operation
cactoos-http copied to clipboard

Auto-detect host wire

Open g4s8 opened this issue 6 years ago • 20 comments

It's not very convenient to write a host two times (first in wire, second in request):

final Wire wire = new HtWire("http://www.google.com");
new HtResponse(
  wire,
  "http://www.google.com", // same string
  "GET / HTTP/1.1"
)

I think a wire should be able to read host value from request Host header:

new HtResponse(
  new HtWire(),
  "http://www.google.com",
  "GET / HTTP/1.1"
)

g4s8 avatar Apr 04 '18 19:04 g4s8

@yegor256/z please, pay attention to this issue

0crat avatar Apr 04 '18 19:04 0crat

@g4s8/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!

0crat avatar Apr 04 '18 19:04 0crat

@g4s8 we can make something like HtAutoHostedWire, which will add Host HTTP header automatically if it is not present in the request. Make sense?

yegor256 avatar Apr 05 '18 05:04 yegor256

@yegor256 would HtAutoHostedWire be part of the public API?

llorllale avatar May 15 '18 13:05 llorllale

@llorllale why not?

yegor256 avatar May 19 '18 14:05 yegor256

@yegor256 ok, agreed, Host may not necessarily match with the physical host that the wire is connected to

Refs:

  • https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23
  • https://stackoverflow.com/a/43156094/1623885

llorllale avatar May 22 '18 14:05 llorllale

@0crat in

llorllale avatar May 22 '18 14:05 llorllale

@0crat in (here)

@llorllale Job #19 is now in scope, role is DEV

0crat avatar May 22 '18 14:05 0crat

Bug was reported, see §29: +15 point(s) just awarded to @g4s8/z

0crat avatar May 22 '18 14:05 0crat

@g4s8 I think the solution for this problem should be reversed: it should be a request that inserts that header, not a Wire. The reason is that a "wire" is supposed to be a dumb pipe - it should not be inspecting the contents being sent through it. So I believe the direction currently being pushed for in #21 points to a better solution.

It is very common for the Host header to have the same value as the URL's host, so I also believe this behavior should be our default.

llorllale avatar Jun 29 '18 19:06 llorllale

@llorllale if I understand correctly, Wire should be created with host param, right? But if not, I agree that it can be reversed.

g4s8 avatar Jun 30 '18 08:06 g4s8

The job #19 assigned to @marceloamadeu/z, here is why; the budget is 30 minutes, see §4; please, read §8 and §9; if the task is not clear, read this and this; there will be no monetary reward for this job

0crat avatar Feb 03 '19 16:02 0crat

The job #19 assigned to @iprogrammerr/z, here is why; the budget is 30 minutes, see §4; please, read §8 and §9; if the task is not clear, read this and this; there will be no monetary reward for this job

0crat avatar Feb 08 '19 14:02 0crat

@llorllale Right now, it could not be reversed. Wire encapsulates host and port. How it coulde be done? Send method has one argument which is a input. I do not think that reading first line and parsing it according to http rules is a good idea.

BinaryIgor avatar Feb 08 '19 21:02 BinaryIgor

@Iprogrammerr I agree

As I said in https://github.com/yegor256/cactoos-http/issues/19#issuecomment-391007559, the Host header can have a completely different value than the wire's target, and it should be supplied by the user. For all we know, the wire's target could even be an IP address.

I agree that it's an inconvenience (btw - the first example in https://github.com/yegor256/cactoos-http/issues/19#issue-311355752 contains an error: the Host field's value should not include the URI scheme, so it's not an exact duplicate of the same string), but with no workable design thus far, I'm taking this one out of scope.

llorllale avatar Feb 09 '19 13:02 llorllale

@0crat refuse

llorllale avatar Feb 09 '19 13:02 llorllale

@0crat refuse (here)

@llorllale The user @iprogrammerr/z resigned from #19, please stop working. Reason for job resignation: Order was cancelled

0crat avatar Feb 09 '19 14:02 0crat

@0crat out

llorllale avatar Feb 09 '19 14:02 llorllale

@0crat out (here)

@llorllale Job gh:yegor256/cactoos-http#19 is not assigned, can't get performer

0crat avatar Feb 09 '19 14:02 0crat

@0crat out (here)

@llorllale The job #19 is now out of scope

0crat avatar Feb 09 '19 14:02 0crat