Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 106f718be537217d8c47a2b7b4d156d9596d5c86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package org.eclipse.jetty.websocket;

import java.io.IOException;
import java.util.Map;

public class FragmentExtension extends AbstractExtension
{
    private int _maxLength=-1;
    private int _minFragments=1;
    
    public FragmentExtension()
    {
        super("fragment");
    }

    @Override
    public boolean init(Map<String, String> parameters)
    {
        if(super.init(parameters))
        {
            _maxLength=getInitParameter("maxLength",_maxLength);
            _minFragments=getInitParameter("minFragments",_minFragments);
            return true;
        }
        return false;
    }

    @Override
    public void addFrame(byte flags, byte opcode, byte[] content, int offset, int length) throws IOException
    {
        if (getConnection().isControl(opcode))
        {
            super.addFrame(flags,opcode,content,offset,length);
            return;
        }
        
        int fragments=1;
        
        while (_maxLength>0 && length>_maxLength)
        {
            fragments++;
            super.addFrame((byte)(flags&~getConnection().finMask()),opcode,content,offset,_maxLength);
            length-=_maxLength;
            offset+=_maxLength;
            opcode=getConnection().continuationOpcode();
        }
        
        while (fragments<_minFragments)
        {
            int frag=length/2;
            fragments++;
            super.addFrame((byte)(flags&0x7),opcode,content,offset,frag);
            length-=frag;
            offset+=frag;
            opcode=getConnection().continuationOpcode();
        }

        super.addFrame((byte)(flags|getConnection().finMask()),opcode,content,offset,length);
    }
    
    
}

Back to the top