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

Simulate an HTTP 304 response #3333

Closed
bim9262 opened this issue Oct 3, 2023 · 4 comments
Closed

Simulate an HTTP 304 response #3333

bim9262 opened this issue Oct 3, 2023 · 4 comments

Comments

@bim9262
Copy link

bim9262 commented Oct 3, 2023

Version
0.14.27

Platform
Linux hostname 6.5.3-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Wed, 13 Sep 2023 08:37:16 +0000 x86_64 GNU/Linux

Description
When a header is included like If-Modified-Since: Tue, 03 Oct 2023 00:39:17 GMT while the modification date is older than the request date some servers still respond with a status code 200.

Example with curl:

$ curl -v -w "%{http_code}" -z "Tue, 03 Oct 2023 00:39:17 GMT" https://bulk.openweathermap.org/sample/current.city.list.min.json.gz
*   Trying 136.243.62.172:443...
* Connected to bulk.openweathermap.org (136.243.62.172) port 443
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: none
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN: server accepted http/1.1
* Server certificate:
*  subject: CN=*.openweathermap.org
*  start date: Jun 30 00:00:00 2023 GMT
*  expire date: Jul 30 23:59:59 2024 GMT
*  subjectAltName: host "bulk.openweathermap.org" matched cert's "*.openweathermap.org"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=Sectigo Limited; CN=Sectigo RSA Domain Validation Secure Server CA
*  SSL certificate verify ok.
* using HTTP/1.1
> GET /sample/current.city.list.min.json.gz HTTP/1.1
> Host: bulk.openweathermap.org
> User-Agent: curl/8.3.0
> Accept: */*
> If-Modified-Since: Tue, 03 Oct 2023 00:39:17 GMT
>
< HTTP/1.1 200 OK
< Server: openresty
< Date: Tue, 03 Oct 2023 04:18:33 GMT
< Content-Type: text/plain
< Content-Length: 1555072
< Last-Modified: Mon, 17 Apr 2017 16:39:38 GMT
< Connection: keep-alive
< ETag: "58f4efca-17ba80"
< Expires: Tue, 03 Oct 2023 04:19:33 GMT
< Cache-Control: max-age=60
< Accept-Ranges: bytes
<
* The requested document is not new enough
* Simulate an HTTP 304 response
* Closing connection
* TLSv1.2 (OUT), TLS alert, close notify (256):
304

Should hyper have the same behavior of simulation the 304?

BTW, this is the login from curl:

  if(data->set.timecondition && !data->state.range) {
    /* A time condition has been set AND no ranges have been requested. This
       seems to be what chapter 13.3.4 of RFC 2616 defines to be the correct
       action for an HTTP/1.1 client */

    if(!Curl_meets_timecondition(data, k->timeofdoc)) {
      *done = TRUE;
      /* We're simulating an HTTP 304 from server so we return
         what should have been returned from the server */
      data->info.httpcode = 304;
      infof(data, "Simulate an HTTP 304 response");
      /* we abort the transfer before it is completed == we ruin the
         reuse ability. Close the connection */
      streamclose(conn, "Simulated 304 handling");
      return CURLE_OK;
    }
  } /* we have a time condition */
@bim9262 bim9262 added the C-bug Category: bug. Something is wrong. This is bad! label Oct 3, 2023
@seanmonstar
Copy link
Member

hyper does less things than curl. I don't think hyper should handle this itself. It's something for a higher level client that provides files and caching support, in my opinion.

@seanmonstar seanmonstar closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2023
@seanmonstar seanmonstar removed the C-bug Category: bug. Something is wrong. This is bad! label Oct 3, 2023
@bim9262
Copy link
Author

bim9262 commented Oct 3, 2023

Would reqwest be a better place for this to be added or should it be done using reqwest-middleware?

@seanmonstar
Copy link
Member

If reqwest had fuller support for files and caching and stuff, then it'd make sense. It doesn't have that, though. I can't speak to reqwest-middleware.

@bim9262
Copy link
Author

bim9262 commented Oct 3, 2023

Thanks @seanmonstar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants