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

HttpResponseCookies are not written back to the browser #31

Open
henon opened this issue Aug 6, 2016 · 1 comment
Open

HttpResponseCookies are not written back to the browser #31

henon opened this issue Aug 6, 2016 · 1 comment

Comments

@henon
Copy link

henon commented Aug 6, 2016

I searched, there is no mention of the string "Set-Cookie" in the whole code.

@henon
Copy link
Author

henon commented Oct 5, 2016

Here is my working solution in case somebody cares: HttpMessageEncoder's Send method:

     /// <summary>
    ///     Buffer structure used for socket send operations.
    /// </summary>
    /// <param name="buffer">
    ///     Do note that there are not buffer attached to the structure, you have to assign one yourself using
    ///     <see cref="ISocketBuffer.SetBuffer(int,int)" />. This choice was made
    ///     to prevent unnecessary copy operations.
    /// </param>
    public void Send(ISocketBuffer buffer)
    {
        // last send operation did not send all bytes enqueued in the buffer
        // so let's just continue until doing next message
        if (_bytesToSend > 0)
        {
            buffer.SetBuffer(_buffer, _offset, _bytesToSend);
            return;
        }

        // continuing with the message body
        if (_isHeaderSent)
        {
            var bytes = Math.Min(_totalAmountToSend, _buffer.Length);
            _message.Body.Read(_buffer, 0, bytes);
            _bytesToSend = bytes;

            buffer.SetBuffer(_buffer, 0, bytes);
            return;
        }

        _headerWriter.WriteLine(_message.StatusLine);
        foreach (var header in _message.Headers)
        {
            _headerWriter.Write("{0}: {1}\r\n", header.Key, header.Value);
        }
        // mr: added cookies to response
        if (_message is HttpResponse)
        {
            var response = _message as HttpResponse;
            foreach(var cookie in response.Cookies.OfType<HttpResponseCookie>())
                _headerWriter.Write("Set-Cookie: {0}\r\n", cookie.ToString());
        }
        _headerWriter.Write("\r\n");
        _headerWriter.Flush();
        _isHeaderSent = true;
        buffer.UserToken = _message;

        if (_message.Body == null || _message.ContentLength == 0)
        {
            _bytesToSend = (int) _stream.Length;
            _totalAmountToSend = _bytesToSend;
            buffer.SetBuffer(_buffer, 0, (int) _stream.Length);
            return;
        }
        else
        {

        }

        var bytesLeft = _buffer.Length - _stream.Length;
        var bytesToSend = Math.Min(_message.ContentLength, (int) bytesLeft);
        var offset = (int) _stream.Position;
        _message.Body.Read(_buffer, offset, bytesToSend);
        _bytesToSend = (int) _stream.Length + bytesToSend;
        _totalAmountToSend = (int) _stream.Length + _message.ContentLength;
        buffer.SetBuffer(_buffer, 0, _bytesToSend);
    }

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

1 participant