te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>Can I track if requests belong to the same keep-alive connection as previous requests, with Go's nethttp? - Stack Overfl
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Can I track if requests belong to the same keep-alive connection as previous requests, with Go's nethttp? - Stack Overfl

programmeradmin4浏览0评论

While writing a web service accessed by web browsers, a co-maintainer suggested that we allow users to choose to log in to one session without using cookies. (Using hidden HTML forms is something else that we've considered but I'm not very keen on the idea. JavaScript is not acceptable.)

Using the Go standard library's HTTP server or perhaps other mechanics, while setting Connection: keep-alive, is it possible to identify which network connection an incoming request originated from?

  • Storing a pointer to http.Request.TLS (a tls.ConnectionState) won't work because its memory could be freed and the address could be reused, making it possible to hijack sessions.
  • I don't see useful values in http.Request.

It's definitely possible to implement this by accepting requests as a plain TCP/TLS/etc connection, store some information, and construct the http.Requests myself; but that seems like quite a pain.

While writing a web service accessed by web browsers, a co-maintainer suggested that we allow users to choose to log in to one session without using cookies. (Using hidden HTML forms is something else that we've considered but I'm not very keen on the idea. JavaScript is not acceptable.)

Using the Go standard library's HTTP server or perhaps other mechanics, while setting Connection: keep-alive, is it possible to identify which network connection an incoming request originated from?

  • Storing a pointer to http.Request.TLS (a tls.ConnectionState) won't work because its memory could be freed and the address could be reused, making it possible to hijack sessions.
  • I don't see useful values in http.Request.

It's definitely possible to implement this by accepting requests as a plain TCP/TLS/etc connection, store some information, and construct the http.Requests myself; but that seems like quite a pain.

Share Improve this question asked 2 days ago Runxi YuRunxi Yu 3432 silver badges9 bronze badges 12
  • Does your API client is sending any traking information? There is no continuity in HTTP requests, so you can't track them without additional tracking information (e.g. headers) – Justinas Commented 2 days ago
  • 1 Shared proxies exist. Just because two requests arrive on the same TCP connection does not mean they originate from the same user/device/browser. – Peter Commented 2 days ago
  • 1 Note that the runtime does not free and reuse memory when the application has an active reference to the memory. – Thundercat Commented 2 days ago
  • 1 @RunxiYu Your application's reference to the memory prevents the GC from reclaiming and reusing the memory. Close on a TLS connection does not directly free memory. Your reason for not storing a pointer is invalid. – Thundercat Commented 2 days ago
  • 1 @RunxiYu, "storing a pointer to" is a reference which will prevent GC. If you store a pointer to the TLS object it cannot be collected, meaning the concern of "the address could be reused, making it possible to hijack sessions" is not possible. – Mr_Pink Commented 2 days ago
 |  Show 7 more comments

1 Answer 1

Reset to default 1

I don't think that the idea behind the question even works, which means that it will also not work with net/http, no matter what features it offers. The rationale for my doubt:

  • A browser opens multiple HTTP/1 connections even with HTTP keep-alive in order to send requests in parallel (HTTP/1 keep-alive can only to multiple requests after the other).
  • A TLS session can span multiple TCP connections, but only if both sides support session resumptions.

This means you cannot really replace a HTTP session with "same TCP connection" or "same TLS session". Additionally even with HTTP keep-alive an idle TCP connection is closed after a while, loosing the "session".

All of this is independent from the library or programming language used.

Thus, use HTTP cookies to keep a session at the HTTP level. That what they were invented for in the first place. All the bad reputation is only because "maintaining a session" can also be misued for tracking users etc. But this is also true with other session mechanisms.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论