get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/812906/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 812906,
    "url": "http://patchwork.ozlabs.org/api/patches/812906/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170912152153.7729-7-brandon.carpenter@cypherpath.com/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api",
        "name": "QEMU Development",
        "link_name": "qemu-devel",
        "list_id": "qemu-devel.nongnu.org",
        "list_email": "qemu-devel@nongnu.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20170912152153.7729-7-brandon.carpenter@cypherpath.com>",
    "list_archive_url": null,
    "date": "2017-09-12T15:21:52",
    "name": "[v3,6/7] io: Reply to ping frames",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "d2d381faaa9215c2d4953fa8b4ab1df6f7401cfa",
    "submitter": {
        "id": 72031,
        "url": "http://patchwork.ozlabs.org/api/people/72031/?format=api",
        "name": "Brandon Carpenter",
        "email": "brandon.carpenter@cypherpath.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20170912152153.7729-7-brandon.carpenter@cypherpath.com/mbox/",
    "series": [
        {
            "id": 2725,
            "url": "http://patchwork.ozlabs.org/api/series/2725/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2725",
            "date": "2017-09-12T15:21:48",
            "name": "Update websocket code to more fully support the RFC",
            "version": 3,
            "mbox": "http://patchwork.ozlabs.org/series/2725/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/812906/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/812906/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org",
        "Authentication-Results": [
            "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)",
            "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=cypherpath.com header.i=@cypherpath.com\n\theader.b=\"GSd3B8Wg\"; dkim-atps=neutral"
        ],
        "Received": [
            "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xs7rL6zg7z9s7f\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 01:24:34 +1000 (AEST)",
            "from localhost ([::1]:36498 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drn3B-0005xW-0Y\n\tfor incoming@patchwork.ozlabs.org; Tue, 12 Sep 2017 11:24:33 -0400",
            "from eggs.gnu.org ([2001:4830:134:3::10]:40550)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1drn1A-0004pD-NB\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 11:22:30 -0400",
            "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1drn16-00073e-91\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 11:22:28 -0400",
            "from mail-pg0-x234.google.com ([2607:f8b0:400e:c05::234]:33058)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <brandon.carpenter@cypherpath.com>)\n\tid 1drn16-00073F-0E\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 11:22:24 -0400",
            "by mail-pg0-x234.google.com with SMTP id u18so5254648pgo.0\n\tfor <qemu-devel@nongnu.org>; Tue, 12 Sep 2017 08:22:23 -0700 (PDT)",
            "from servo.cypherpath.com (68-113-0-218.static.knwc.wa.charter.com.\n\t[68.113.0.218]) by smtp.gmail.com with ESMTPSA id\n\td18sm12753054pfk.11.2017.09.12.08.22.21\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 12 Sep 2017 08:22:22 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=cypherpath.com; s=google;\n\th=mime-version:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; bh=pr1gcsihuNwMkpDDraJqO+C1j0S5FdnEQNkZQffyli4=;\n\tb=GSd3B8Wgsz6oyhD3UQ8sKo35ALxbE/7uZ2GXnko4NVmb0dpwq+kB5yl6KJiZmvQUwb\n\tkLfV5GDR628YDAOoEMzuVm3Rp4ya//9IYKyyS0sYoIWwF20iFnj4uVb1WX3zpPMPMT/g\n\tcimCb2cFOgQO2/a16BZdqAV7+MKsyL8Vq896A=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id\n\t:in-reply-to:references;\n\tbh=pr1gcsihuNwMkpDDraJqO+C1j0S5FdnEQNkZQffyli4=;\n\tb=hEkiB6bJtcc5z9DeJd3kzD9tOoWp2W9Gq1G+ff/ZbXu8H5Y6sSiWlXv1hFkI3uI38r\n\txSH++abr78M8BRyRo5PH/qpEdgkzg7qehbXc/GT33eoAjNBl+x6qrX7VYhgBeQlGsI8Z\n\tRiK83g6T/akOHa/y/PaFN23zYvWl72PmriwevBhU2JfzBrQ+pnqE2AKt28lYslrVT/mO\n\tMgkdp9G6jv1cE6TlvqlSUlYbzlPL8heroX74qgxU75pAqOi1fcGWrZ0VVGlhfvIKNb15\n\tVErvYOn6voq2w4dUnEq67AGxC4AMr8p71UOF6DIGx+VJeNmTfIvLSMhWeBNvYH8uus8J\n\tmwGQ==",
        "X-Gm-Message-State": "AHPjjUg6uPy1VWLzW5bgSY1dRyYG4o64zud6ciFdB0wZDBLupjv+CZSJ\n\t7PmxTmfxJg4zqQ13fM0rYynWOCYneGUDqSHIEfkL8mD+aRN5ajAw653lIBWszy3prkJvgf40fg8\n\t+b7Nb",
        "MIME-Version": "1.0",
        "X-Google-Smtp-Source": "AOwi7QDbO6CSyhR6PFvDc1y01gmRugBdBSbjCz04ZjhXo6xKQ7MBSlsCdHl+dY1ucbr0UVIspCorrQ==",
        "X-Received": "by 10.84.252.129 with SMTP id y1mr2734489pll.107.1505229742888; \n\tTue, 12 Sep 2017 08:22:22 -0700 (PDT)",
        "From": "Brandon Carpenter <brandon.carpenter@cypherpath.com>",
        "To": "qemu-devel@nongnu.org",
        "Date": "Tue, 12 Sep 2017 08:21:52 -0700",
        "Message-Id": "<20170912152153.7729-7-brandon.carpenter@cypherpath.com>",
        "X-Mailer": "git-send-email 2.14.1",
        "In-Reply-To": "<20170912152153.7729-1-brandon.carpenter@cypherpath.com>",
        "References": "<20170912152153.7729-1-brandon.carpenter@cypherpath.com>",
        "Content-Type": "text/plain; charset=\"US-ASCII\"",
        "X-detected-operating-system": "by eggs.gnu.org: Genre and OS details not\n\trecognized.",
        "X-Received-From": "2607:f8b0:400e:c05::234",
        "Subject": "[Qemu-devel] [PATCH v3 6/7] io: Reply to ping frames",
        "X-BeenThere": "qemu-devel@nongnu.org",
        "X-Mailman-Version": "2.1.21",
        "Precedence": "list",
        "List-Id": "<qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>",
        "List-Post": "<mailto:qemu-devel@nongnu.org>",
        "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>",
        "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Cc": "brandon.carpenter@cypherpath.com",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"
    },
    "content": "Add an immediate ping reply (pong) to the outgoing stream when a ping\nis received. Unsolicited pongs are ignored.\n\nSigned-off-by: Brandon Carpenter <brandon.carpenter@cypherpath.com>\n---\n include/io/channel-websock.h |  1 +\n io/channel-websock.c         | 64 +++++++++++++++++++++++++++++---------------\n 2 files changed, 44 insertions(+), 21 deletions(-)",
    "diff": "diff --git a/include/io/channel-websock.h b/include/io/channel-websock.h\nindex 7c896557c5..ff32d8651b 100644\n--- a/include/io/channel-websock.h\n+++ b/include/io/channel-websock.h\n@@ -60,6 +60,7 @@ struct QIOChannelWebsock {\n     Buffer encoutput;\n     Buffer rawinput;\n     Buffer rawoutput;\n+    Buffer ping_reply;\n     size_t payload_remain;\n     QIOChannelWebsockMask mask;\n     guint io_tag;\ndiff --git a/io/channel-websock.c b/io/channel-websock.c\nindex 50387050d5..a29fee42d5 100644\n--- a/io/channel-websock.c\n+++ b/io/channel-websock.c\n@@ -479,7 +479,8 @@ static gboolean qio_channel_websock_handshake_io(QIOChannel *ioc,\n }\n \n \n-static void qio_channel_websock_encode(QIOChannelWebsock *ioc)\n+static void qio_channel_websock_encode_buffer(Buffer *output,\n+                                              uint8_t opcode, Buffer *buffer)\n {\n     size_t header_size;\n     union {\n@@ -487,33 +488,37 @@ static void qio_channel_websock_encode(QIOChannelWebsock *ioc)\n         QIOChannelWebsockHeader ws;\n     } header;\n \n-    if (!ioc->rawoutput.offset) {\n-        return;\n-    }\n-\n     header.ws.b0 = QIO_CHANNEL_WEBSOCK_HEADER_FIELD_FIN |\n-        (QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME &\n-         QIO_CHANNEL_WEBSOCK_HEADER_FIELD_OPCODE);\n-    if (ioc->rawoutput.offset <\n+        (opcode & QIO_CHANNEL_WEBSOCK_HEADER_FIELD_OPCODE);\n+    if (buffer->offset <\n         QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_THRESHOLD_7_BIT) {\n-        header.ws.b1 = (uint8_t)ioc->rawoutput.offset;\n+        header.ws.b1 = (uint8_t)buffer->offset;\n         header_size = QIO_CHANNEL_WEBSOCK_HEADER_LEN_7_BIT;\n-    } else if (ioc->rawoutput.offset <\n+    } else if (buffer->offset <\n                QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_THRESHOLD_16_BIT) {\n         header.ws.b1 = QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_16_BIT;\n-        header.ws.u.s16.l16 = cpu_to_be16((uint16_t)ioc->rawoutput.offset);\n+        header.ws.u.s16.l16 = cpu_to_be16((uint16_t)buffer->offset);\n         header_size = QIO_CHANNEL_WEBSOCK_HEADER_LEN_16_BIT;\n     } else {\n         header.ws.b1 = QIO_CHANNEL_WEBSOCK_PAYLOAD_LEN_MAGIC_64_BIT;\n-        header.ws.u.s64.l64 = cpu_to_be64(ioc->rawoutput.offset);\n+        header.ws.u.s64.l64 = cpu_to_be64(buffer->offset);\n         header_size = QIO_CHANNEL_WEBSOCK_HEADER_LEN_64_BIT;\n     }\n     header_size -= QIO_CHANNEL_WEBSOCK_HEADER_LEN_MASK;\n \n-    buffer_reserve(&ioc->encoutput, header_size + ioc->rawoutput.offset);\n-    buffer_append(&ioc->encoutput, header.buf, header_size);\n-    buffer_append(&ioc->encoutput, ioc->rawoutput.buffer,\n-                  ioc->rawoutput.offset);\n+    buffer_reserve(output, header_size + buffer->offset);\n+    buffer_append(output, header.buf, header_size);\n+    buffer_append(output, buffer->buffer, buffer->offset);\n+}\n+\n+\n+static void qio_channel_websock_encode(QIOChannelWebsock *ioc)\n+{\n+    if (!ioc->rawoutput.offset) {\n+        return;\n+    }\n+    qio_channel_websock_encode_buffer(&ioc->encoutput,\n+            QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME, &ioc->rawoutput);\n     buffer_reset(&ioc->rawoutput);\n }\n \n@@ -558,7 +563,7 @@ static int qio_channel_websock_decode_header(QIOChannelWebsock *ioc,\n     /* Websocket frame sanity check:\n      * * Fragmentation is only supported for binary frames.\n      * * All frames sent by a client MUST be masked.\n-     * * Only binary encoding is supported.\n+     * * Only binary and ping/pong encoding is supported.\n      */\n     if (!fin) {\n         if (opcode != QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {\n@@ -619,6 +624,11 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,\n          * for purpose of unmasking, except at end of payload\n          */\n         if (ioc->encinput.offset < ioc->payload_remain) {\n+            /* Wait for the entire payload before processing control frames\n+             * because the payload will most likely be echoed back. */\n+            if (ioc->opcode & QIO_CHANNEL_WEBSOCK_CONTROL_OPCODE_MASK) {\n+                return QIO_CHANNEL_ERR_BLOCK;\n+            }\n             payload_len = ioc->encinput.offset - (ioc->encinput.offset % 4);\n         } else {\n             payload_len = ioc->payload_remain;\n@@ -641,13 +651,18 @@ static int qio_channel_websock_decode_payload(QIOChannelWebsock *ioc,\n         }\n     }\n \n-    /* Drop the payload of ping/pong packets */\n     if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_BINARY_FRAME) {\n         if (payload_len) {\n+            /* binary frames are passed on */\n             buffer_reserve(&ioc->rawinput, payload_len);\n             buffer_append(&ioc->rawinput, ioc->encinput.buffer, payload_len);\n         }\n-    }\n+    } else if (ioc->opcode == QIO_CHANNEL_WEBSOCK_OPCODE_PING) {\n+        /* ping frames produce an immediate reply */\n+        buffer_reset(&ioc->ping_reply);\n+        qio_channel_websock_encode_buffer(&ioc->ping_reply,\n+                QIO_CHANNEL_WEBSOCK_OPCODE_PONG, &ioc->encinput);\n+    }   /* pong frames are ignored */\n \n     if (payload_len) {\n         buffer_advance(&ioc->encinput, payload_len);\n@@ -705,6 +720,7 @@ static void qio_channel_websock_finalize(Object *obj)\n     buffer_free(&ioc->encoutput);\n     buffer_free(&ioc->rawinput);\n     buffer_free(&ioc->rawoutput);\n+    buffer_free(&ioc->ping_reply);\n     object_unref(OBJECT(ioc->master));\n     if (ioc->io_tag) {\n         g_source_remove(ioc->io_tag);\n@@ -761,7 +777,13 @@ static ssize_t qio_channel_websock_write_wire(QIOChannelWebsock *ioc,\n {\n     ssize_t ret;\n     ssize_t done = 0;\n-    qio_channel_websock_encode(ioc);\n+\n+    /* ping replies take priority over binary data */\n+    if (!ioc->ping_reply.offset) {\n+        qio_channel_websock_encode(ioc);\n+    } else if (!ioc->encoutput.offset) {\n+        buffer_move_empty(&ioc->encoutput, &ioc->ping_reply);\n+    }\n \n     while (ioc->encoutput.offset > 0) {\n         ret = qio_channel_write(ioc->master,\n@@ -836,7 +858,7 @@ static void qio_channel_websock_set_watch(QIOChannelWebsock *ioc)\n         return;\n     }\n \n-    if (ioc->encoutput.offset) {\n+    if (ioc->encoutput.offset || ioc->ping_reply.offset) {\n         cond |= G_IO_OUT;\n     }\n     if (ioc->encinput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER &&\n",
    "prefixes": [
        "v3",
        "6/7"
    ]
}