---
name: "Protocol::WebSocket::Response"
section: "3pm"
platform: "linux"
package: "libprotocol-websocket-perl"
version: "0.26-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Protocol::WebSocket::Response"
---

# Protocol::WebSocket::Response(3pm)

WebSocket Response

## NAME

Protocol::WebSocket::Response - WebSocket Response

## SYNOPSIS

```
    # Constructor
    $res = Protocol::WebSocket::Response->new(
        host          => 'example.com',
        resource_name => '/demo',
        origin        => 'file://',
        number1       => 777_007_543,
        number2       => 114_997_259,
        challenge     => "\x47\x30\x22\x2D\x5A\x3F\x47\x58"
    );
    $res->to_string; # HTTP/1.1 101 WebSocket Protocol Handshake
                     # Upgrade: WebSocket
                     # Connection: Upgrade
                     # Sec-WebSocket-Origin: file://
                     # Sec-WebSocket-Location: ws://example.com/demo
                     #
                     # 0st3Rl&q-2ZU^weu
    # Parser
    $res = Protocol::WebSocket::Response->new;
    $res->parse("HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a");
    $res->parse("Upgrade: WebSocket\x0d\x0a");
    $res->parse("Connection: Upgrade\x0d\x0a");
    $res->parse("Sec-WebSocket-Origin: file://\x0d\x0a");
    $res->parse("Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a");
    $res->parse("\x0d\x0a");
    $res->parse("0st3Rl&q-2ZU^weu");
```

## DESCRIPTION

Construct or parse a WebSocket response.

## ATTRIBUTES

### "host"

### "location"

### "origin"

### "resource\_name"

### "secure"

## METHODS

### "new"

Create a new Protocol::WebSocket::Response instance.

### "parse"

```
    $res->parse($buffer);
```

Parse a WebSocket response. Incoming buffer is modified.

### "to\_string"

Construct a WebSocket response.

### "cookie"

### "cookies"

### "key"

### "key1"

```
    $self->key1;
```

Set or get `"Sec-WebSocket-Key1"` field.

### "key2"

```
    $self->key2;
```

Set or get `"Sec-WebSocket-Key2"` field.

### "number1"

```
    $self->number1;
    $self->number1(123456);
```

Set or extract from `"Sec-WebSocket-Key1"` generated `"number"` value.

### "number2"

```
    $self->number2;
    $self->number2(123456);
```

Set or extract from `"Sec-WebSocket-Key2"` generated `"number"` value.

### "status"

```
    $self->status;
```

Get response status (101).

### "body"

```
    $self->body;
```

Get response body.

### "headers"

```
    my $arrayref = $self->headers;
```

Get response headers.
