aboutsummaryrefslogtreecommitdiffstats
path: root/fastlib
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2019-01-15 10:40:09 +0000
committerHåvard Pettersen <havardpe@oath.com>2019-01-15 10:40:09 +0000
commit93fcb53d2e078569026d364ae11406a3976fdfce (patch)
tree46331f42daf5ae9af24ff4e0cac54116f64845e5 /fastlib
parentac9c1759ea31012fb3d5b95102a69434a07ffb16 (diff)
remove fastlib webserver
Diffstat (limited to 'fastlib')
-rw-r--r--fastlib/CMakeLists.txt2
-rw-r--r--fastlib/src/vespa/fastlib/net/.gitignore13
-rw-r--r--fastlib/src/vespa/fastlib/net/CMakeLists.txt11
-rw-r--r--fastlib/src/vespa/fastlib/net/httpchunkedinputstream.cpp214
-rw-r--r--fastlib/src/vespa/fastlib/net/httpchunkedinputstream.h29
-rw-r--r--fastlib/src/vespa/fastlib/net/httpchunkedoutputstream.cpp151
-rw-r--r--fastlib/src/vespa/fastlib/net/httpchunkedoutputstream.h29
-rw-r--r--fastlib/src/vespa/fastlib/net/httpheaderparser.cpp155
-rw-r--r--fastlib/src/vespa/fastlib/net/httpheaderparser.h26
-rw-r--r--fastlib/src/vespa/fastlib/net/httpserver.cpp1197
-rw-r--r--fastlib/src/vespa/fastlib/net/httpserver.h338
-rw-r--r--fastlib/src/vespa/fastlib/net/resolver/.gitignore16
-rw-r--r--fastlib/src/vespa/fastlib/net/resolver/tests/.gitignore15
-rw-r--r--fastlib/src/vespa/fastlib/net/socket.cpp64
-rw-r--r--fastlib/src/vespa/fastlib/net/socket.h57
-rw-r--r--fastlib/src/vespa/fastlib/net/tests/.gitignore19
-rw-r--r--fastlib/src/vespa/fastlib/net/tests/CMakeLists.txt8
-rw-r--r--fastlib/src/vespa/fastlib/net/tests/headers.txt13
-rw-r--r--fastlib/src/vespa/fastlib/net/tests/httpheaderparsertest.cpp54
-rw-r--r--fastlib/src/vespa/fastlib/net/transport/.gitignore13
-rw-r--r--fastlib/src/vespa/fastlib/net/transport/tests/.gitignore31
-rw-r--r--fastlib/src/vespa/fastlib/net/url.cpp55
-rw-r--r--fastlib/src/vespa/fastlib/net/url.h18
-rw-r--r--fastlib/src/vespa/packages/CMakeLists.txt1
24 files changed, 0 insertions, 2529 deletions
diff --git a/fastlib/CMakeLists.txt b/fastlib/CMakeLists.txt
index 1d1ff42106b..58d3708e9e1 100644
--- a/fastlib/CMakeLists.txt
+++ b/fastlib/CMakeLists.txt
@@ -7,8 +7,6 @@ vespa_define_module(
LIBS
src/vespa/fastlib/io
src/vespa/fastlib/io/tests
- src/vespa/fastlib/net
- src/vespa/fastlib/net/tests
src/vespa/fastlib/testsuite
src/vespa/fastlib/text
src/vespa/fastlib/text/apps
diff --git a/fastlib/src/vespa/fastlib/net/.gitignore b/fastlib/src/vespa/fastlib/net/.gitignore
deleted file mode 100644
index aa9c3f19188..00000000000
--- a/fastlib/src/vespa/fastlib/net/.gitignore
+++ /dev/null
@@ -1,13 +0,0 @@
-*.So
-*.a
-*.ilk
-*.lib
-*.o
-*.obj
-*.pdb
-.cvsignore
-.depend
-.pure
-Debug
-Makefile
-SunWS_cache
diff --git a/fastlib/src/vespa/fastlib/net/CMakeLists.txt b/fastlib/src/vespa/fastlib/net/CMakeLists.txt
deleted file mode 100644
index 78d24473dd6..00000000000
--- a/fastlib/src/vespa/fastlib/net/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_library(fastlib_net OBJECT
- SOURCES
- httpserver.cpp
- url.cpp
- socket.cpp
- httpheaderparser.cpp
- httpchunkedinputstream.cpp
- httpchunkedoutputstream.cpp
- DEPENDS
-)
diff --git a/fastlib/src/vespa/fastlib/net/httpchunkedinputstream.cpp b/fastlib/src/vespa/fastlib/net/httpchunkedinputstream.cpp
deleted file mode 100644
index 899a5a3ab83..00000000000
--- a/fastlib/src/vespa/fastlib/net/httpchunkedinputstream.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/*
- * HTTP chunked input stream.
- *
- * Author: Markus Bjartveit Krüger
- */
-
-#include "httpchunkedinputstream.h"
-#include <cstring>
-#include <cstdlib>
-
-Fast_HTTPChunkedInputStream::Fast_HTTPChunkedInputStream(Fast_InputStream &in)
- : Fast_FilterInputStream(in), _chunkSize(0), _inChunk(false),
- _isClosed(false)
-{
-}
-
-
-
-
-Fast_HTTPChunkedInputStream::~Fast_HTTPChunkedInputStream(void)
-{
-}
-
-
-
-
-bool Fast_HTTPChunkedInputStream::ReadChunkHeader(void)
-{
- char chunkHeader[100];
- char *pos = chunkHeader;
-
- // Read chunk size into chunkHeader.
- for (;;)
- {
- if (Fast_FilterInputStream::Read(pos, 1) != 1)
- {
- return false;
- }
- if (*pos == ';' || *pos == '\n')
- {
- break;
- }
- pos++;
- if (static_cast<size_t>(pos - chunkHeader) > sizeof(chunkHeader))
- {
- return false;
- }
- }
-
- _chunkSize = strtoul(chunkHeader, NULL, 16);
-
- // Finish reading eventual extensions.
- char c = *pos;
- while (c != '\n')
- {
- if (Fast_FilterInputStream::Read(&c, 1) != 1)
- {
- return false;
- }
- }
-
- // If this was the last chunk, read optional trailer and final CRLF.
- if (_chunkSize == 0)
- {
- for (;;) {
- if (Fast_FilterInputStream::Read(&c, 1) != 1)
- {
- return false;
- }
- if (c == '\r')
- {
- if (Fast_FilterInputStream::Read(&c, 1) != 1)
- {
- return false;
- }
- }
- if (c == '\n')
- {
- // Empty line, end of last chunk.
- break;
- }
-
- // In trailing header; read rest of line.
- do
- {
- if (Fast_FilterInputStream::Read(&c, 1) != 1)
- {
- return false;
- }
- } while (c != '\n');
- }
- _inChunk = false;
- _isClosed = true;
- }
- else
- {
- _inChunk = true;
- }
-
- return true;
-}
-
-
-
-
-ssize_t Fast_HTTPChunkedInputStream::Available(void)
-{
- if (_isClosed || !_inChunk)
- {
- return 0;
- }
-
- ssize_t slaveAvailable = Fast_FilterInputStream::Available();
- if (slaveAvailable < 0)
- {
- return slaveAvailable;
- }
- else
- {
- return (static_cast<size_t>(slaveAvailable) < _chunkSize)
- ? slaveAvailable : _chunkSize;
- }
-}
-
-
-
-
-bool Fast_HTTPChunkedInputStream::Close(void)
-{
- _isClosed = true;
- return true;
-}
-
-
-
-
-ssize_t Fast_HTTPChunkedInputStream::Read(void *targetBuffer, size_t length)
-{
- if (_isClosed)
- {
- return 0;
- }
-
- if (!_inChunk)
- {
- // Read new header chunk, check if end of chunked entity is reached.
- if (!ReadChunkHeader())
- {
- _isClosed = true;
- return -1;
- }
- else if (_isClosed)
- {
- return 0;
- }
- }
-
- size_t blockLength = (length < _chunkSize) ? length : _chunkSize;
- ssize_t numBytesRead = _in->Read(targetBuffer, blockLength);
- if (numBytesRead > 0)
- {
- _chunkSize -= numBytesRead;
- }
- else
- {
- _isClosed = true;
- _inChunk = false;
- return (numBytesRead < 0) ? numBytesRead : -1;
- }
-
- if (_chunkSize == 0)
- {
- // End of chunk reached. Mark this, and read CRLF following
- // chunk.
-
- _inChunk = false;
-
- bool ok;
- char c;
- ok = _in->Read(&c, 1) == 1;
- if (ok && c == '\r')
- {
- ok = _in->Read(&c, 1) == 1;
- }
- ok = ok && c == '\n';
- if (!ok)
- {
- _isClosed = true;
- return -1;
- }
- }
-
- return numBytesRead;
-}
-
-
-
-
-ssize_t Fast_HTTPChunkedInputStream::Skip(size_t skipNBytes)
-{
- if (_isClosed)
- {
- return -1;
- }
- else if (!_inChunk)
- {
- return 0;
- }
- else
- {
- return _in->Skip((skipNBytes < _chunkSize) ? skipNBytes : _chunkSize);
- }
-}
diff --git a/fastlib/src/vespa/fastlib/net/httpchunkedinputstream.h b/fastlib/src/vespa/fastlib/net/httpchunkedinputstream.h
deleted file mode 100644
index a6448419744..00000000000
--- a/fastlib/src/vespa/fastlib/net/httpchunkedinputstream.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vespa/fastlib/io/filterinputstream.h>
-
-class Fast_HTTPChunkedInputStream : public Fast_FilterInputStream
-{
-private:
- // Prevent use of:
- Fast_HTTPChunkedInputStream(const Fast_HTTPChunkedInputStream &);
- Fast_HTTPChunkedInputStream & operator=(const Fast_HTTPChunkedInputStream &);
-protected:
- size_t _chunkSize;
- bool _inChunk;
- bool _isClosed;
-
- bool ReadChunkHeader(void);
-public:
- Fast_HTTPChunkedInputStream(Fast_InputStream &in);
- ~Fast_HTTPChunkedInputStream();
-
-
- // Methods
- ssize_t Available() override;
- bool Close() override;
- ssize_t Read(void *targetBuffer, size_t length) override;
- ssize_t Skip(size_t skipNBytes) override;
-};
diff --git a/fastlib/src/vespa/fastlib/net/httpchunkedoutputstream.cpp b/fastlib/src/vespa/fastlib/net/httpchunkedoutputstream.cpp
deleted file mode 100644
index 67bcee98bd6..00000000000
--- a/fastlib/src/vespa/fastlib/net/httpchunkedoutputstream.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/*
- * HTTP chunked output stream.
- *
- * Author: Markus Bjartveit Krüger
- */
-
-#include "httpchunkedoutputstream.h"
-#include <cassert>
-#include <cstdio>
-#include <cstring>
-
-Fast_HTTPChunkedOutputStream::Fast_HTTPChunkedOutputStream(Fast_OutputStream &out,
- size_t chunkSize)
- : Fast_FilterOutputStream(out),
- _chunkSize(chunkSize),
- _buffer(NULL),
- _bufferUsed(0),
- _writeHasFailed(false)
-{
- _buffer = new char[_chunkSize+2]; // Leave room for CRLF at end of chunk
- assert(_buffer != NULL);
-}
-
-
-
-Fast_HTTPChunkedOutputStream::~Fast_HTTPChunkedOutputStream(void)
-{
- delete [] _buffer;
-}
-
-
-
-bool Fast_HTTPChunkedOutputStream::WriteChunk(void)
-{
- // Don't write an empty block, as this will end the entity.
- if (_bufferUsed == 0)
- {
- return true;
- }
-
- if (_writeHasFailed)
- return false;
-
- char chunkHeader[100];
- char *from;
- size_t bytesLeft;
- ssize_t bytesWritten;
- bytesLeft = sprintf(chunkHeader, "%x\r\n",
- static_cast<unsigned int>(_bufferUsed));
- from = chunkHeader;
- while (bytesLeft > 0)
- {
- bytesWritten = Fast_FilterOutputStream::Write(from, bytesLeft);
- if (bytesWritten < 0)
- {
- _writeHasFailed = true;
- return false;
- }
- else
- {
- from += bytesWritten;
- bytesLeft -= bytesWritten;
- }
- }
-
- _buffer[_bufferUsed++] = '\r';
- _buffer[_bufferUsed++] = '\n';
- bytesLeft = _bufferUsed;
- from = _buffer;
- while (bytesLeft > 0)
- {
- bytesWritten = Fast_FilterOutputStream::Write(from, bytesLeft);
- if (bytesWritten < 0)
- {
- _bufferUsed -= 2;
- _writeHasFailed = true;
- return false;
- }
- else
- {
- from += bytesWritten;
- bytesLeft -= bytesWritten;
- }
- }
- _bufferUsed = 0;
- return true;
-}
-
-
-
-bool Fast_HTTPChunkedOutputStream::Close(void)
-{
- WriteChunk();
- char chunkHeader[] = { '0', '\r', '\n', '\r', '\n' };
- char *from = chunkHeader;
- size_t bytesLeft = sizeof(chunkHeader);
- ssize_t bytesWritten;
- while (bytesLeft > 0)
- {
- bytesWritten = Fast_FilterOutputStream::Write(from, bytesLeft);
- if (bytesWritten < 0)
- {
- break;
- }
- else
- {
- from += bytesWritten;
- bytesLeft -= bytesWritten;
- }
- }
-
- return (bytesLeft == 0);
-}
-
-
-
-ssize_t
-Fast_HTTPChunkedOutputStream::Write(const void *sourceBuffer, size_t length)
-{
- const char *from = static_cast<const char*>(sourceBuffer);
- size_t numBytesWritten = length;
- while (length > 0)
- {
- size_t bufferRemain = _chunkSize - _bufferUsed;
- if (bufferRemain > 0) {
- size_t blockLength = (length < bufferRemain) ? length : bufferRemain;
- memcpy(_buffer + _bufferUsed, from, blockLength);
- _bufferUsed += blockLength;
- from += blockLength;
- length -= blockLength;
- }
- if (length > 0)
- {
- if (!WriteChunk())
- {
- return -1;
- }
- }
- }
- return numBytesWritten;
-}
-
-
-
-void
-Fast_HTTPChunkedOutputStream::Flush(void)
-{
- WriteChunk();
- Fast_FilterOutputStream::Flush();
-}
diff --git a/fastlib/src/vespa/fastlib/net/httpchunkedoutputstream.h b/fastlib/src/vespa/fastlib/net/httpchunkedoutputstream.h
deleted file mode 100644
index dfd58aa2612..00000000000
--- a/fastlib/src/vespa/fastlib/net/httpchunkedoutputstream.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vespa/fastlib/io/filteroutputstream.h>
-
-class Fast_HTTPChunkedOutputStream : public Fast_FilterOutputStream
-{
-private:
- // Prevent use of:
- Fast_HTTPChunkedOutputStream(const Fast_HTTPChunkedOutputStream &);
- Fast_HTTPChunkedOutputStream & operator=(const Fast_HTTPChunkedOutputStream &);
-protected:
- size_t _chunkSize;
- char *_buffer;
- size_t _bufferUsed;
- bool _writeHasFailed;
-
- bool WriteChunk(void);
-public:
- Fast_HTTPChunkedOutputStream(Fast_OutputStream &out, size_t chunkSize = 1024);
- ~Fast_HTTPChunkedOutputStream();
-
-
- // Methods
- bool Close() override;
- ssize_t Write(const void *sourceBuffer, size_t length) override;
- void Flush() override;
-};
diff --git a/fastlib/src/vespa/fastlib/net/httpheaderparser.cpp b/fastlib/src/vespa/fastlib/net/httpheaderparser.cpp
deleted file mode 100644
index 1ef6e105ef1..00000000000
--- a/fastlib/src/vespa/fastlib/net/httpheaderparser.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "httpheaderparser.h"
-#include <vespa/fastlib/io/bufferedinputstream.h>
-#include <cstdio>
-#include <cstring>
-
-Fast_HTTPHeaderParser::Fast_HTTPHeaderParser(Fast_BufferedInputStream &in)
- : _pushBack(0),
- _isPushBacked(false),
- _bufferSize(16384),
- _lineBuffer(new char[_bufferSize]),
- _input(&in)
-{
-}
-
-Fast_HTTPHeaderParser::~Fast_HTTPHeaderParser(void)
-{
- delete [] _lineBuffer;
-}
-
-bool
-Fast_HTTPHeaderParser::ReadRequestLine(const char *&method, const char *&url, int &versionMajor, int &versionMinor)
-{
- // Read a single line from input. Repeat if line is blank, to cope
- // with buggy HTTP/1.1 clients that print extra empty lines at the
- // end of requests.
-
- do {
- size_t idx = 0;
- ssize_t readLen = _input->ReadBufferFullUntil(_lineBuffer, _bufferSize, '\n');
- if (readLen <= 0) {
- return false;
- }
- idx = readLen-1;
-
- if (idx == 0 || _lineBuffer[idx] != '\n') {
- return false;
- }
- _lineBuffer[idx--] = '\0';
- if (_lineBuffer[idx] == '\r') {
- _lineBuffer[idx] = '\0';
- }
- } while (_lineBuffer[0] == '\0');
-
- // Parse request line.
-
- char *p = _lineBuffer;
- const char *version = "";
-
- method = p;
- p = strchr(p, ' ');
- if (p != NULL) {
- *p++ = '\0';
- url = p;
- p = strchr(p, ' ');
- if (p != NULL) {
- *p++ = '\0';
- version = p;
- }
- }
-
- if (sscanf(version, "HTTP/%d.%d", &versionMajor, &versionMinor) != 2) {
- versionMajor = versionMinor = -1;
- return false;
- }
-
- return true;
-}
-
-bool
-Fast_HTTPHeaderParser::ReadHeader(const char *&name, const char *&value)
-{
- size_t idx = 0;
-
- name = NULL;
- value = NULL;
-
- if (_isPushBacked) {
- idx = 0;
- _lineBuffer[idx] = _pushBack;
- _isPushBacked = false;
- idx++;
- }
-
- constexpr size_t ROOM_FOR_PUSH_BACK = 1u;
- while ((idx + ROOM_FOR_PUSH_BACK) < _bufferSize) {
- ssize_t readLen = _input->ReadBufferFullUntil(&_lineBuffer[idx], _bufferSize - idx - ROOM_FOR_PUSH_BACK, '\n');
- if (readLen <= 0) {
- return false;
- }
- idx += readLen - 1;
- // Empty line == end of headers.
- // handle case with \r\n as \n
- if (idx == 0 || (_lineBuffer[0] == '\r' && idx == 1)) {
- idx = 0;
- break;
- }
-
- // Ignore double return 0xD, 0xA)
- if (idx >= 1) {
- if (_lineBuffer[idx - 1] == '\r') {
- idx--;
- _lineBuffer[idx] = '\n';
- }
- }
-
- // Check if header continues on next line.
- if (_input->Read(&_pushBack, 1) != 1) {
- break;
- }
- if (_pushBack == ' ' || _pushBack == '\t') {
- // Header does continue on next line.
- // Replace newline with horizontal whitespace.
- _lineBuffer[idx] = _pushBack;
- idx++;
- } else {
- _isPushBacked = true;
- // break out of while loop
- break;
- }
- }
-
- if (idx != 0) {
- _lineBuffer[idx] = '\0';
- char *p = _lineBuffer;
- name = p;
-
- // Find end of header name.
- while (*p != ':' && *p != '\0') {
- p++;
- }
-
- // If end of header name is not end of header, parse header value.
- if (*p != '\0') {
- // Terminate header name.
- *p++ = '\0';
-
- // Skip leading whitespace before header value.
- while (*p == ' ' || *p == '\t') {
- p++;
- }
- value = p;
- // Strip trailing whitespace.
- p += strlen(p);
- while (p > value && (*(p-1) == ' ' || *(p-1) == '\t')) {
- p--;
- }
- *p = '\0';
- } // End of header parsing (idx != 0).
-
- }
-
- return (idx != 0);
-}
diff --git a/fastlib/src/vespa/fastlib/net/httpheaderparser.h b/fastlib/src/vespa/fastlib/net/httpheaderparser.h
deleted file mode 100644
index f7146f3618b..00000000000
--- a/fastlib/src/vespa/fastlib/net/httpheaderparser.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <cstddef>
-
-class Fast_BufferedInputStream;
-
-class Fast_HTTPHeaderParser
-{
-public:
- Fast_HTTPHeaderParser(const Fast_HTTPHeaderParser &) = delete;
- Fast_HTTPHeaderParser & operator = (const Fast_HTTPHeaderParser &) = delete;
- Fast_HTTPHeaderParser(Fast_BufferedInputStream &in);
- ~Fast_HTTPHeaderParser();
-
- // Methods
- bool ReadRequestLine(const char *&method, const char *&url, int &versionMajor, int &versionMinor);
- bool ReadHeader(const char *&name, const char *&value);
-private:
- char _pushBack;
- bool _isPushBacked;
- const size_t _bufferSize;
- char *_lineBuffer;
- Fast_BufferedInputStream *_input;
-};
diff --git a/fastlib/src/vespa/fastlib/net/httpserver.cpp b/fastlib/src/vespa/fastlib/net/httpserver.cpp
deleted file mode 100644
index 0d1b75ec7fe..00000000000
--- a/fastlib/src/vespa/fastlib/net/httpserver.cpp
+++ /dev/null
@@ -1,1197 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "url.h"
-#include "httpchunkedinputstream.h"
-#include "httpchunkedoutputstream.h"
-#include "httpheaderparser.h"
-#include "httpserver.h"
-#include <vespa/fastlib/io/bufferedinputstream.h>
-#include <vespa/fastlib/io/bufferedoutputstream.h>
-#include <vespa/fastlib/util/base64.h>
-#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/fastos/file.h>
-#include <cassert>
-
-/**
- * Helper class for hiding the details of HTTP entity encodings and
- * persistent connections from Fast_HTTPServer subclasses that read
- * client request entities. (Headers have already been read by the
- * time this filter is used, and are therefore not handled here.)
- *
- * The filter decodes chunked transfer encoding if used, and returns
- * end of stream at the end of the entity to prevent subclasses from
- * reading past the end (and into the next request on a persistent
- * connection).
- */
-
-class Fast_HTTPPersistentInputFilter : public Fast_FilterInputStream
-{
-private:
- // Prevent use of:
- Fast_HTTPPersistentInputFilter(const Fast_HTTPPersistentInputFilter &);
- Fast_HTTPPersistentInputFilter & operator=(const Fast_HTTPPersistentInputFilter &);
-protected:
- Fast_HTTPChunkedInputStream *_chunkedInput;
-
- bool _useChunkedInput;
- size_t _remainingBytes;
-
-public:
- Fast_HTTPPersistentInputFilter(Fast_InputStream &in)
- : Fast_FilterInputStream(in),
- _chunkedInput(NULL),
- _useChunkedInput(false),
- _remainingBytes(0)
- { }
-
- ~Fast_HTTPPersistentInputFilter() {
- delete _chunkedInput;
- }
-
- // Methods
- ssize_t Available() override;
- bool Close() override;
- ssize_t Read(void *sourceBuffer, size_t length) override;
- ssize_t Skip(size_t skipNBytes) override;
-
- void SetEntityLength(size_t entityLength);
- void SetChunkedEncoding();
-};
-
-
-ssize_t Fast_HTTPPersistentInputFilter::Available()
-{
- if (_useChunkedInput) {
- return _chunkedInput->Available();
- } else {
- ssize_t slaveAvailable = _in->Available();
- if (slaveAvailable < 0) {
- return slaveAvailable;
- } else {
- return ((static_cast<size_t>(slaveAvailable) < _remainingBytes))
- ? slaveAvailable : _remainingBytes;
- }
- }
-}
-
-
-
-bool Fast_HTTPPersistentInputFilter::Close()
-{
- // Do nothing.
- return true;
-}
-
-
-
-ssize_t Fast_HTTPPersistentInputFilter::Read(void *targetBuffer, size_t length)
-{
- if (_useChunkedInput) {
- return _chunkedInput->Read(targetBuffer, length);
- } else {
- if (_remainingBytes == 0) {
- return 0;
- } else {
- ssize_t numBytesRead;
- numBytesRead = _in->Read(targetBuffer, (length < _remainingBytes)
- ? length : _remainingBytes);
- if (numBytesRead > 0) {
- _remainingBytes -= numBytesRead;
- } else {
- _remainingBytes = 0;
- }
- return numBytesRead;
- }
- }
-}
-
-
-
-ssize_t Fast_HTTPPersistentInputFilter::Skip(size_t skipNBytes)
-{
- if (_useChunkedInput) {
- return _chunkedInput->Skip(skipNBytes);
- } else {
- return _in->Skip((skipNBytes < _remainingBytes) ? skipNBytes : _remainingBytes);
- }
-}
-
-
-
-
-void Fast_HTTPPersistentInputFilter::SetEntityLength(size_t entityLength)
-{
- _useChunkedInput = false;
- _remainingBytes = entityLength;
-}
-
-
-
-void Fast_HTTPPersistentInputFilter::SetChunkedEncoding()
-{
- _useChunkedInput = true;
- // TODO: If input stream interface is expanded to enable resetting
- // streams, we can reuse a single chunked input stream instance
- // instead of allocating a new each time.
- delete _chunkedInput;
- _chunkedInput = new Fast_HTTPChunkedInputStream(*_in);
-}
-
-
-
-/**
- * Helper class for converting an entire HTTP server response into a
- * form suitable for persistent connections.
- *
- * The filter strips away headers that would interfere with a
- * persistent connections, adds neccessary headers, and encodes the
- * entity body into the chunked transfer encoding unless the
- * Content-Length header was given in the unfiltered response.
- */
-
-class Fast_HTTPPersistentOutputFilter : public Fast_FilterOutputStream
-{
-private:
- // Prevent use of:
- Fast_HTTPPersistentOutputFilter(const Fast_HTTPPersistentOutputFilter &);
- Fast_HTTPPersistentOutputFilter & operator=(const Fast_HTTPPersistentOutputFilter &);
-protected:
- Fast_HTTPChunkedOutputStream *_chunkedOutput;
- Fast_OutputStream *_entityOutput;
-
- bool _inHeaderRegion; // Currently writing headers?
- bool _cleanHeader; // Can current header be written directly?
- bool _useChunkedOutput;
- char _line[1024];
- size_t _linePos;
-
- bool FlushHeader(void);
-public:
- Fast_HTTPPersistentOutputFilter(Fast_OutputStream &out) :
- Fast_FilterOutputStream(out),
- _chunkedOutput(NULL), _entityOutput(NULL),
- _inHeaderRegion(true), _cleanHeader(false), _useChunkedOutput(true),
- _linePos(0)
- { }
-
- ~Fast_HTTPPersistentOutputFilter() {
- delete _chunkedOutput;
- }
-
- // Methods
- bool Close() override;
- ssize_t Write(const void *sourceBuffer, size_t length) override;
- void Flush() override;
-};
-
-
-
-bool Fast_HTTPPersistentOutputFilter::FlushHeader()
-{
- assert(_inHeaderRegion);
- size_t i = 0;
- while (i < _linePos) {
- ssize_t numBytesWritten = Fast_FilterOutputStream::Write(_line, _linePos - i);
- if (numBytesWritten >= 0) {
- i += numBytesWritten;
- } else {
- return false;
- }
- }
- _linePos = 0;
- return true;
-}
-
-
-
-bool Fast_HTTPPersistentOutputFilter::Close()
-{
- bool retVal = true;
- if (_inHeaderRegion) {
- FlushHeader();
- } else if (_useChunkedOutput) {
- retVal = _chunkedOutput->Close();
- delete _chunkedOutput;
- _chunkedOutput = NULL;
- } else {
- // Do nothing. In particular, do not close _entityOutput, as that
- // would close the slave stream.
- }
- Fast_FilterOutputStream::Flush();
- _inHeaderRegion = true;
- _useChunkedOutput = true;
- return retVal;
-}
-
-
-
-ssize_t Fast_HTTPPersistentOutputFilter::Write(const void *sourceBuffer, size_t length)
-{
- if (length == 0) {
- return 0;
- }
-
- ssize_t numBytesWritten = 0;
- const char *from = static_cast<const char*>(sourceBuffer);
-
- while (_inHeaderRegion && length > 0) {
- // Read a line at a time from the source buffer and check for
- // problematic headers and the end of the header region.
-
- bool endOfHeader = false;
-
- while (length > 0 && _linePos < sizeof(_line)) {
- _line[_linePos++] = *from++;
- length--;
- numBytesWritten++;
- if (_line[_linePos-1] == '\n') {
- endOfHeader = true;
- break;
- }
- }
-
- // We can safely flush if the header is known to be unproblematic
- // or is at least as long as the line buffer (the headers we are
- // scared of are never that long).
- if (_cleanHeader || _linePos == sizeof(_line)) {
- _cleanHeader = !endOfHeader;
- FlushHeader();
- } else if (endOfHeader) {
- // Check for suspicious headers and end of header region.
- if (_linePos == 1 || (_linePos == 2 && _line[0] == '\r')) {
- // Empty line, end of headers reached.
- if (_useChunkedOutput) {
- //Add chunking header.
- strcpy(_line, "Transfer-Encoding: chunked\r\n\r\n");
- _linePos = strlen(_line);
- }
- FlushHeader();
- sourceBuffer = from;
- _inHeaderRegion = false;
- } else {
- // Terminate header line.
- // (We know that _linepos < sizeof(_line), so this is safe.)
- _line[_linePos] = '\0';
-
- size_t headerLength = strcspn(_line, " \t\r\n:");
- if (headerLength == 10 && strncasecmp(_line, "connection", 10) == 0) {
- // Don't copy this header, just reset line buffer
- _linePos = 0;
- } else if (headerLength == 14 && strncasecmp(_line, "content-length", 14) == 0) {
- _useChunkedOutput = false;
- FlushHeader();
- } else if (strcasecmp(_line, "Transfer-Encoding: 8bit\n") == 0) {
- // Backward compatibility hack: older versions of
- // Fast_HTTPServer set this invalid header, and there might
- // exist subclasses that still do. Just discard it.
- _linePos = 0;
-
- } else {
- FlushHeader();
- }
- }
- }
-
- if (!_inHeaderRegion) {
- // End of header region was found, set up entity output stream.
- if (_useChunkedOutput) {
- // Free old (if it exists)
- if (_chunkedOutput != NULL)
- delete _chunkedOutput;
-
- _chunkedOutput = new Fast_HTTPChunkedOutputStream(*_out);
- assert(_chunkedOutput != NULL);
- _entityOutput = _chunkedOutput;
- } else {
- _entityOutput = _out;
- }
- }
- }
-
- if (length > 0) {
- ssize_t slaveWritten = _entityOutput->Write(sourceBuffer, length);
- if (slaveWritten >= 0) {
- numBytesWritten += slaveWritten;
- } else {
- numBytesWritten = slaveWritten;
- }
- }
-
- return numBytesWritten;
-}
-
-
-
-void Fast_HTTPPersistentOutputFilter::Flush(void)
-{
- if (_inHeaderRegion) {
- FlushHeader();
- Fast_FilterOutputStream::Flush();
- } else {
- _entityOutput->Flush();
- }
-}
-
-Fast_HTTPServer::Fast_HTTPServer(int portNumber,
- const char* strictBindHostName,
- int backlog, bool decode,
- int stackSize, int maxThreads,
- int clientReadTimeout /* = -1 no timeout */)
- : _connections(10),
- _connectionLock(),
- _connectionCond(),
- _threadPool(NULL),
- _acceptThread(NULL),
- _isRunning(false),
- _isListening(false),
- _stopSignalled(false),
- _runningMutex(),
- _maxThreads(maxThreads),
- _baseDir(),
- _allowUpRelativePath(false),
- _serverSocket(portNumber, backlog,
- &_serverSocketFactory,
- strictBindHostName),
- _decode(decode),
- _keepAlive(true),
- _serverSocketFactory(clientReadTimeout),
- _inBufSize(FASTLIB_HTTPSERVER_INBUFSIZE),
- _outBufSize(FASTLIB_HTTPSERVER_OUTBUFSIZE)
-{
- _threadPool = new FastOS_ThreadPool(stackSize, maxThreads);
-}
-
-
-int Fast_HTTPServer::Start(void)
-{
- int retCode = FASTLIB_SUCCESS;
-
- {
- std::lock_guard<std::mutex> runningGuard(_runningMutex);
- if (!_isRunning) {
- // Try listening
- retCode = Listen();
-
- // Start worker thread
- if (retCode == FASTLIB_SUCCESS) {
- _acceptThread = static_cast<FastOS_Thread *>(_threadPool->NewThread(this));
- if (_acceptThread == NULL) {
- retCode = FASTLIB_HTTPSERVER_NEWTHREADFAILED;
- }
- }
- } else {
- retCode = FASTLIB_HTTPSERVER_ALREADYSTARTED;
- }
- }
-
- return retCode;
-}
-
-
-void
-Fast_HTTPServer::Stop(void) {
- {
- std::lock_guard<std::mutex> runningGuard(_runningMutex);
- _stopSignalled = true;
- if (_acceptThread) {
- _acceptThread->SetBreakFlag();
- }
- }
- if (_acceptThread) {
- _acceptThread->Join();
- }
-}
-
-
-
-bool Fast_HTTPServer::StopSignalled(void)
-{
- bool retVal;
- std::lock_guard<std::mutex> runningGuard(_runningMutex);
- retVal = _stopSignalled;
- return retVal;
-}
-
-
-
-Fast_HTTPServer::~Fast_HTTPServer(void)
-{
- Stop();
-
- {
- std::unique_lock<std::mutex> connectionGuard(_connectionLock);
-
- for (Fast_BagIterator<Fast_HTTPConnection*> i(_connections); !i.End(); i.Next())
- i.GetCurrent()->Interrupt();
-
- while (_connections.NumberOfElements() > 0) {
- _connectionCond.wait(connectionGuard);
- }
- }
- delete _threadPool;
-}
-
-
-
-int Fast_HTTPServer::Listen(void)
-{
- int retCode = FASTLIB_SUCCESS;
-
- if(!_isListening) {
- if (_serverSocket.Listen()) {
- _isListening = true;
- } else {
- std::string errorMsg = FastOS_Socket::getErrorString(FastOS_Socket::GetLastError());
- retCode = FASTLIB_HTTPSERVER_BADLISTEN;
- }
- }
-
- return retCode;
-}
-
-
-
-void Fast_HTTPServer::Run(FastOS_ThreadInterface *thisThread, void *params)
-{
- (void) thisThread;
- (void) params;
- Fast_Socket *mySocket;
-
- {
- std::lock_guard<std::mutex> runningGuard(_runningMutex);
- _isRunning = true;
- _stopSignalled = false;
- }
-
- if (Listen() == FASTLIB_SUCCESS) {
- FastOS_SocketEvent socketEvent;
- if (_serverSocket.SetSocketEvent(&socketEvent)) {
- _serverSocket.EnableReadEvent(true);
- while (!thisThread->GetBreakFlag()) {
- bool waitError;
- if (!socketEvent.Wait(waitError, 500)) {
- if (waitError) {
-// fprintf(stderr, "HTTPServer: ERROR: Wait on server socket failed.\n");
- }
- continue;
- }
-
- // If number of threads is limited, ensure that the limit is
- // not breached. Starvation is impossible, since threads are
- // only allocated here.
- if (_maxThreads != 0) {
- while (_threadPool->GetNumActiveThreads() == _maxThreads) {
- FastOS_Thread::Sleep(50);
- }
- }
-
- mySocket = static_cast<Fast_Socket *>(_serverSocket.Accept());
-
- if (mySocket != NULL) {
- mySocket->SetNoDelay(true);
- Fast_HTTPConnection *connectionHandler =
- new Fast_HTTPConnection(mySocket, // Takes ownership
- _decode,
- _inBufSize,
- _outBufSize);
-
- if (_keepAlive == false) {
- connectionHandler->SetKeepAlive(false);
- }
-
- auto* thread = _threadPool->NewThread(connectionHandler, this);
- if (thread == nullptr) {
- // Thread pool has been shut down; cannot service request.
- delete connectionHandler;
- }
- } else {
- FastOS_Thread::Sleep(1000);
- // fprintf(stderr, "HTTPServer: ERROR: Accept did not return a valid socket. Terminating\n");
- }
- }
- _serverSocket.EnableReadEvent(false);
- } else {
-// fprintf(stderr, "HTTPServer: ERROR: Unable to set socket event handler.\n");
- }
- _serverSocket.SetSocketEvent(NULL);
- }
-
- std::lock_guard<std::mutex> runningGuard(_runningMutex);
- _isRunning = false;
-}
-
-void Fast_HTTPConnection::Run(FastOS_ThreadInterface *thisThread, void *params)
-{
- (void) thisThread;
- vespalib::string fLine, contentType;
- vespalib::string url, host;
-
- enum request_type { HTTPSERVER_UNSUPPORTEDREQUEST,
- HTTPSERVER_GETREQUEST,
- HTTPSERVER_POSTREQUEST,
- HTTPSERVER_PUTREQUEST,
- HTTPSERVER_DELETEREQUEST
- } requestType = HTTPSERVER_UNSUPPORTEDREQUEST;
-
-
- _server = static_cast<Fast_HTTPServer *>(params);
- _server->AddConnection(this);
-
- Fast_InputStream *originalInput = _input;
- Fast_HTTPPersistentInputFilter *persistentInput = NULL;
- Fast_OutputStream *originalOutput = _output;
- Fast_HTTPPersistentOutputFilter *persistentOutput = NULL;
-
- Fast_HTTPHeaderParser headerParser(static_cast<Fast_BufferedInputStream &>(*_input));
-
- do {
-
- bool printContinue = false; // RFC2616, 8.2.3
- bool chunkedInput = false;
- int contentLength = 0;
-
- // Get request line.
-
- const char *requestCStr, *urlCStr;
- int versionMajor, versionMinor;
-
- if (! headerParser.ReadRequestLine(requestCStr, urlCStr, versionMajor, versionMinor))
- break;
-
- if (strcmp(requestCStr, "POST") == 0) {
- requestType = HTTPSERVER_POSTREQUEST;
- } else if (strcmp(requestCStr, "GET") == 0) {
- requestType = HTTPSERVER_GETREQUEST;
- } else if (strcmp(requestCStr, "PUT") == 0) {
- requestType = HTTPSERVER_PUTREQUEST;
- } else if (strcmp(requestCStr, "DELETE") == 0) {
- requestType = HTTPSERVER_DELETEREQUEST;
- } else {
- requestType = HTTPSERVER_UNSUPPORTEDREQUEST;
- }
-
- if (_decode) {
- vespalib::string encodedURL(urlCStr);
- int bufferLength = encodedURL.length()+10;
- char *decodedURL = new char[bufferLength];
- Fast_URL urlCodec;
- urlCodec.decode(encodedURL.c_str(), decodedURL, bufferLength);
- urlCodec.DecodeQueryString(decodedURL);
- url = decodedURL;
- delete [] decodedURL;
- } else {
- url = urlCStr;
- }
-
- if (versionMajor != 1) {
- requestType = HTTPSERVER_UNSUPPORTEDREQUEST;
- }
- if (versionMinor < 1) {
- _keepAlive = false; // No keepAlive for HTTP/1.0 and HTTP/0.9
- }
- _versionMajor = versionMajor;
- _versionMinor = versionMinor;
- _httpVersion = vespalib::make_string("HTTP/%d.%d", _versionMajor, _versionMinor);
-
- const char *headerName, *headerValue;
- while(headerParser.ReadHeader(headerName, headerValue)) {
- if (strcasecmp(headerName, "content-length") == 0) {
- contentLength = atoi(headerValue);
- //printf("Found content length: %i\n", contentLength);
- }
-
- if (strcasecmp(headerName, "content-type") == 0) {
- contentType = headerValue;
- }
-
- if (strcasecmp(headerName, "connection") == 0) {
- if (strcasecmp(headerValue, "close") == 0) {
- _keepAlive = false;
- }
- }
-
- if (strcasecmp(headerName, "host") == 0) {
- host = headerValue;
- }
-
- if (strcasecmp(headerName, "cookie") == 0) {
- _cookies = headerValue;
- }
-
- if (strcasecmp(headerName, "expect") == 0) {
- if (strcasecmp(headerValue, "100-continue") == 0) {
- printContinue = true;
- } else {
- // TODO: Return reponse code 417 instead of 505.
- requestType = HTTPSERVER_UNSUPPORTEDREQUEST;
- }
- }
-
- if (strcasecmp(headerName, "transfer-encoding") == 0) {
- if (strcasecmp(headerValue, "chunked") == 0) {
- chunkedInput = true;
- } else {
- // Only chunked is supported so far.
- requestType = HTTPSERVER_UNSUPPORTEDREQUEST;
- }
- }
-
- if (strcasecmp(headerName, "authorization") == 0) {
- if (strncasecmp(headerValue, "basic",5) == 0) {
- char *auth = new char[strlen(headerValue)-4];
- int len = Fast_Base64::Decode(headerValue+5,strlen(headerValue)-5,auth);
- if(len>=0) auth[len]=0;
- char *pass=strchr(auth,':');
- if(pass!=NULL){
- *pass++=0;
- _auth_user=auth;
- _auth_pass=pass;
- }
- delete[] auth;
- }
- }
- }
-
-
- if (_keepAlive) {
- // Set up filters for persistent input and output.
-
- if (persistentInput == NULL) {
- persistentInput = new Fast_HTTPPersistentInputFilter(*originalInput);
- assert(persistentInput != NULL);
- }
- if (chunkedInput) {
- // If chunked input is specified in headers, ignore content-length
- // and use chunked encoding, according to RFC.
- persistentInput->SetChunkedEncoding();
- } else {
- // Works as intended if content length == 0 (i.e. no entity body).
- persistentInput->SetEntityLength(contentLength);
- }
- _input = persistentInput;
-
- if (persistentOutput == NULL) {
- persistentOutput = new Fast_HTTPPersistentOutputFilter(*originalOutput);
- assert(persistentOutput != NULL);
- }
- _output = persistentOutput;
- } else {
- _input = originalInput;
- _output = originalOutput;
- }
-
- if (printContinue) {
- Output(_httpVersion.c_str());
- Output(" 100 Continue\r\n");
- }
-
-
- switch(requestType) {
- case HTTPSERVER_GETREQUEST:
- {
- _server->onGetRequest(url, host, *this);
- break;
- }
-
- case HTTPSERVER_POSTREQUEST:
- {
- _server->OnPostRequest(url, host, contentType, contentLength,
- *this, *_input, *_output);
- break;
- }
-
- case HTTPSERVER_PUTREQUEST:
- {
- _server->OnPutRequest(url, host, contentType, contentLength,
- *this, *_input, *_output);
- break;
- }
-
- case HTTPSERVER_DELETEREQUEST:
- {
- _server->OnDeleteRequest(url, host, *this);
- break;
- }
-
- case HTTPSERVER_UNSUPPORTEDREQUEST:
- default:
- {
- _server->OnUnsupportedRequest(url, host, *this);
- _keepAlive = false;
- break;
- }
- }
-
- // Ensure all of request entity body is read if connection is
- // persistent.
- if (_keepAlive) {
- ssize_t numBytesRead;
- char buffer[1024];
- while ((numBytesRead = _input->Read(buffer, sizeof(buffer))) > 0) {
- // Keep reading
- }
- _keepAlive = (numBytesRead == 0);
- _input = originalInput;
- }
-
- _output->Flush();
- _output->Close();
-
- } while (_keepAlive && !_server->StopSignalled());
-
- // Close connection
- _socket->Close();
-
- _input = originalInput; // To be deleted by destructor
- delete persistentInput;
-
- _output = originalOutput; // To be deleted by destructor
- delete persistentOutput;
-
- delete this;
-}
-
-
-
-void Fast_HTTPServer::onGetRequest(const string & tmpurl, const string & host, Fast_HTTPConnection& conn)
-{
- // Trim leading / if it exists
- string url(tmpurl);
- if (url.length()>0) {
- if (url[0]=='/') {
- url = url.substr(1);
- }
- }
-
- if (IsFileRequest(url)) {
- HandleFileRequest(url, conn);
- } else {
- // Output html content header
- conn.Output(conn.GetHTTPVersion().c_str());
- conn.Output(" 200 OK\r\n");
- conn.Output("Server: FAST-HTTP-Server/1.0 (Fast Generic HTTP server)\r\n");
- if (conn.GetKeepAlive() == false)
- conn.Output("Connection: close\r\n");
- conn.Output("Content-Type: text/html\r\n\r\n");
-
- // Output user specific body
- OnWriteBody(url, host, conn);
- }
-}
-
-
-
-void Fast_HTTPServer::OnPostRequest(const string & url,
- const string & host,
- const string & contentType,
- int contentLength,
- Fast_HTTPConnection& conn,
- Fast_InputStream& inputStream,
- Fast_OutputStream& outputStream)
-{
-
- // Ignore all parameters
- (void) url;
- (void) host;
- (void) contentType;
- (void) contentLength;
- (void) inputStream;
- (void) outputStream;
- (void) contentLength;
-
- // Output html content header
- conn.Output(conn.GetHTTPVersion().c_str());
- conn.Output(" 200 OK\r\n");
- conn.Output("Server: FAST-HTTP-Server/1.0 (Fast Generic HTTP server)\r\n");
- if (conn.GetKeepAlive() == false)
- conn.Output("Connection: close\r\n");
- conn.Output("Content-Type: text/html\r\n\r\n");
-
- // Body output example
- conn.Output("<html> \r\n");
- conn.Output("<head> \r\n");
- conn.Output("<title>Test title</title> \r\n");
- conn.Output("</head> \r\n");
- conn.Output("<body> \r\n");
- conn.Output("<p>Implement the virtual function 'OnPostRequest()' to change this page!</p>\r\n");
- conn.Output("</body> \r\n");
- conn.Output("</html> \r\n\r\n");
-
-}
-
-
-
-void Fast_HTTPServer::OnPutRequest(const string & url,
- const string & host,
- const string & contentType,
- int contentLength,
- Fast_HTTPConnection& conn,
- Fast_InputStream& inputStream,
- Fast_OutputStream& outputStream)
-{
-
- // Ignore parameters not passed on to OnUnsupportedRequest()
- (void) contentType;
- (void) contentLength;
- (void) inputStream;
- (void) outputStream;
- (void) contentLength;
-
- OnUnsupportedRequest(url, host, conn);
-}
-
-
-
-void Fast_HTTPServer::OnDeleteRequest(const string & url, const string & host, Fast_HTTPConnection& conn)
-{
- OnUnsupportedRequest(url, host, conn);
-}
-
-
-
-void Fast_HTTPServer::OnUnsupportedRequest(const string & url, const string & host, Fast_HTTPConnection& conn)
-{
- (void) url;
- (void) host;
-
- conn.Output(conn.GetHTTPVersion().c_str());
- conn.Output(" 501 Not Implemented\r\n\r\n");
-}
-
-
-
-void Fast_HTTPServer::OnWriteBody(const string & url, const string & host, Fast_HTTPConnection& conn)
-{
- (void) url;
- (void) host;
-
- // Body output example
- conn.Output("<html> \r\n");
- conn.Output("<head> \r\n");
- conn.Output("<title>Test title</title> \r\n");
- conn.Output("</head> \r\n");
- conn.Output("<body> \r\n");
- conn.Output("<p>Implement the virtual function 'OnWriteBody()' to change this page!</p>\r\n");
- conn.Output("</body> \r\n");
- conn.Output("</html> \r\n\r\n");
-}
-
-
-void Fast_HTTPConnection::OutputData(const void *data, size_t len)
-{
- const char *dataPosition = static_cast<const char *>(data);
-
- while (len > 0) {
- ssize_t numBytesWritten = _output->Write(dataPosition, len);
- if (numBytesWritten >= 0) {
- dataPosition += numBytesWritten;
- len -= numBytesWritten;
- } else {
- break;
- }
- }
-}
-
-void Fast_HTTPConnection::Output(const char *text)
-{
- size_t length = strlen(text);
-
- while (length > 0) {
- ssize_t numBytesWritten = _output->Write(text, length);
- if (numBytesWritten >= 0) {
- text += numBytesWritten;
- length -= numBytesWritten;
- } else {
- break;
- }
- }
-}
-
-
-
-bool Fast_HTTPServer::IsFileRequest(const string & url)
-{
- bool retVal = false;
-
- // Check if the request is for a file (stupid test now)
- if (url.length() > 4) {
- if (url[url.length()-4]=='.') retVal = true;
-
- if (url.length() > 5) {
- if (url[url.length()-5]=='.') retVal = true;
-
- if (url.length() > 6) {
- if (url[url.length()-6]=='.') retVal = true;
- }
- }
- }
-
- return retVal;
-}
-
-
-
-void Fast_HTTPServer::PushHtml(const string & url, Fast_HTTPConnection& conn)
-{
- // Add base dir to relative path and file name
- string fileName = _baseDir + url;
-
- FastOS_File file;
-
- if (file.OpenReadOnly(fileName.c_str())) {
- conn.OutputFile(&file);
- } else {
- OutputNotFound(conn, &url, false);
- }
-
- file.Close();
-}
-
-
-
-void Fast_HTTPServer::HandleFileRequest(const string & url, Fast_HTTPConnection& conn)
-{
- string status403;
- vespalib::string upRelative(FastOS_File::GetPathSeparator());
- upRelative += "..";
- upRelative += FastOS_File::GetPathSeparator();
- vespalib::string upRelative2("/../");
-
- bool isUpRelative =
- _allowUpRelativePath == false &&
- (vespalib::contains(url, upRelative) ||
- vespalib::contains(url, upRelative2) ||
- vespalib::starts_with(url, "../") ||
- vespalib::starts_with(url, "..\\"));
-
- // Security policy:
- // Do not allow file requests if _baseDir is not set.
- // Do not allow UpRelative paths if not explicitly enabled with
- // SetAllowUpRelativePath(true);
- if (_baseDir.length() == 0 || isUpRelative ) {
- conn.Output(conn.GetHTTPVersion().c_str());
- conn.Output(" 403 FORBIDDEN\r\n");
- conn.Output("Server: FAST-HTTP-Server/1.0 (Fast Generic HTTP server)\r\n");
- conn.Output("Content-Type: text/html\r\n");
- conn.Output("Connection: close\r\n");
-
- status403.append("<html> \r\n");
- status403.append("<head> \r\n");
- status403.append("<title>Error 403</title> \r\n");
- status403.append("</head> \r\n");
- status403.append("<body> \r\n");
- status403.append("<h2>HTTP Error 403</h2>\r\n");
- status403.append("<p><strong>403 Forbidden</strong></p>\r\n");
- status403.append("</body></html>\r\n\r\n");
-
- conn.Output(vespalib::make_string("Content-Length: %ld\r\n\r\n", status403.length()).c_str());
- conn.Output(status403.c_str());
- return;
- }
-
- // Add base dir to relative path and file name
- string fileName = _baseDir + url;
-
- FastOS_File file;
-
- if (file.OpenReadOnly(fileName.c_str())) {
- bool contentTypeKnown = false;
-
- conn.Output(conn.GetHTTPVersion().c_str());
- conn.Output(" 200 OK\r\n");
- conn.Output("Server: FAST-HTTP-Server/1.0 (Fast Generic HTTP server)\r\n");
- conn.Output("Content-Length: ");
- conn.Output(vespalib::make_string("%ld", file.GetSize()).c_str());
- conn.Output("\r\n");
-
- if (conn.GetKeepAlive() == false)
- conn.Output("Connection: close\r\n");
-
- if (ends_with(url, ".gif")) {
- conn.Output("Content-Type: image/gif\r\n");
- contentTypeKnown = true;
- }
-
- if (ends_with(url, ".html") || ends_with(url, ".htm")) {
- conn.Output("Content-Type: text/html\r\n");
- contentTypeKnown = true;
- }
-
- if (ends_with(url, ".jpeg") || ends_with(url, ".jpg")) {
- conn.Output("Content-Type: image/jpeg\r\n");
- contentTypeKnown = true;
- }
-
- if (!contentTypeKnown) {
- conn.Output("Content-Type: application/octet-stream\r\n");
- }
-
- conn.Output("\r\n");
- conn.OutputFile(&file);
-
- } else {
- OutputNotFound(conn, &url);
- }
-
- file.Close();
-}
-
-
-
-void Fast_HTTPServer::SetBaseDir(const char *baseDir)
-{
- std::lock_guard<std::mutex> runningGuard(_runningMutex);
- if (!_isRunning) {
- _baseDir = baseDir;
-
- if (_baseDir.length() > 0) {
- // Add '/' if it was not supplied
- if (_baseDir[_baseDir.length()-1] != '/') {
- _baseDir.append("/");
- }
- }
- } else {
- fprintf(stderr, "HTTPServer: Tried to set base dir after the server had been started. Request denied.\r\n");
- }
-}
-
-void
-Fast_HTTPServer::SetAllowUpRelativePath(bool allowUpRelativePath) {
- _allowUpRelativePath = allowUpRelativePath;
-}
-
-bool
-Fast_HTTPServer::GetAllowUpRelativePath() {
- return _allowUpRelativePath;
-}
-
-
-Fast_HTTPConnection::Fast_HTTPConnection(Fast_Socket *sock,
- bool decode,
- size_t inBufSize,
- size_t outBufSize)
- : _decode(decode),
- _socket(sock),
- _input(NULL),
- _output(NULL),
- _server(NULL),
- _chunkedInput(false),
- _chunkedOutput(false),
- _keepAlive(true), // Per default, keepalive is true for HTTP/1.1
- _auth_user(),
- _auth_pass(),
- _versionMajor(1), // Default HTTP version is 1.1
- _versionMinor(1),
- _httpVersion(),
- _cookies()
-{
- _input = new Fast_BufferedInputStream(*_socket, inBufSize);
- _output = new Fast_BufferedOutputStream(*_socket, outBufSize);
-
- _httpVersion = vespalib::make_string("HTTP/%d.%d", _versionMajor, _versionMinor);
-}
-
-
-
-Fast_HTTPConnection::~Fast_HTTPConnection(void)
-{
- if (_server) {
- _server->RemoveConnection(this);
- }
-
- delete _input;
- delete _output;
- delete _socket;
-}
-
-
-
-void Fast_HTTPConnection::OutputFile(FastOS_FileInterface *file)
-{
- const int bufferSize = 2048;
- char buffer[bufferSize];
- int bytesRead;
-
- file->SetPosition (0); // Try to read from start of file
-
- while ((bytesRead=file->Read(buffer, 2048)) > 0) {
- ssize_t bytesLeft = bytesRead;
- char * bufferPos = buffer;
-
- while (bytesLeft > 0) {
- ssize_t numBytesWritten = _output->Write(bufferPos, bytesLeft);
- if (numBytesWritten >= 0) {
- bufferPos += numBytesWritten;
- bytesLeft -= numBytesWritten;
- } else {
- return;
- }
- }
- }
-}
-
-
-
-void Fast_HTTPServer::OutputNotFound(Fast_HTTPConnection& conn,
- const string *url /* = NULL */,
- bool addHeaders /* = true */)
-{
- string status404;
-
- if (addHeaders) {
- conn.Output(conn.GetHTTPVersion().c_str());
- conn.Output(" 404 Not Found\r\n");
- conn.Output("Server: FAST-HTTP-Server/1.0 (Fast Generic HTTP server)\r\n");
- conn.Output("Content-Type: text/html\r\n");
-
- status404.append("<html> \r\n");
- status404.append("<head> \r\n");
- status404.append("<title>Error 404</title> \r\n");
- status404.append("<meta name=\"robots\" content=\"noindex\">\r\n");
- status404.append("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">\r\n");
- status404.append("</head> \r\n");
- status404.append("<body> \r\n");
-
- status404.append("<h2>HTTP Error 404</h2>\r\n");
- status404.append("<p><strong>404 Not Found</strong></p>\r\n");
-
- }
-
- if (url == NULL)
- status404.append("<p>The Web server cannot find the file or script you asked for.</p>\r\n");
- else
- status404.append(vespalib::make_string("<p>The Web server cannot find %s.</p>\r\n", url->c_str()));
-
- status404.append("<p>Please check the URL to ensure that the path is correct.</p>\r\n");
- status404.append("<p>Contact the server's administrator if this problem persists.</p>\r\n");
-
- if (addHeaders) {
- status404.append("</body> \r\n");
- status404.append("</html> \r\n\r\n");
-
- conn.Output(vespalib::make_string("Content-Length: %ld\r\n\r\n", status404.length()).c_str());
- }
-
- conn.Output(status404.c_str());
-}
-
-void
-Fast_HTTPServer::AddConnection(Fast_HTTPConnection* connection)
-{
- std::lock_guard<std::mutex> connectionGuard(_connectionLock);
- _connections.Insert(connection);
-}
-
-void
-Fast_HTTPServer::RemoveConnection(Fast_HTTPConnection* connection)
-{
- std::lock_guard<std::mutex> connectionGuard(_connectionLock);
- _connections.RemoveElement(connection);
- _connectionCond.notify_one();
- }
-
-void
-Fast_HTTPConnection::Interrupt()
-{
- _socket->Interrupt();
-}
diff --git a/fastlib/src/vespa/fastlib/net/httpserver.h b/fastlib/src/vespa/fastlib/net/httpserver.h
deleted file mode 100644
index 54803fe86d4..00000000000
--- a/fastlib/src/vespa/fastlib/net/httpserver.h
+++ /dev/null
@@ -1,338 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/*
- * Generic http server and connection classes
- *
- * Author: Stein Hardy Danielsen
- */
-
-
-#pragma once
-
-#include <vespa/fastlib/io/inputstream.h>
-#include <vespa/fastlib/io/outputstream.h>
-#include <vespa/fastlib/net/socket.h>
-#include <vespa/fastlib/util/bag.h>
-#include <vespa/vespalib/stllike/string.h>
-#include <vespa/fastos/thread.h>
-#include <vespa/fastos/serversocket.h>
-#include <mutex>
-#include <condition_variable>
-
-class FastOS_FileInterface;
-class Fast_HTTPServer;
-
-#define FASTLIB_SUCCESS (0)
-#define FASTLIB_FAILURE (1)
-
-/*
- * Generic HTTP connection class
- */
-
-// Error codes
-#define FASTLIB_HTTPSERVER_NEWTHREADFAILED (2)
-#define FASTLIB_HTTPSERVER_BADLISTEN (3)
-#define FASTLIB_HTTPSERVER_ALREADYSTARTED (4)
-
-// Default buffer sizes for HTTPConnection streams
-#define FASTLIB_HTTPSERVER_INBUFSIZE 32768
-#define FASTLIB_HTTPSERVER_OUTBUFSIZE 32768
-
-
-class Fast_HTTPConnection : public FastOS_Runnable
-{
-private:
- Fast_HTTPConnection(const Fast_HTTPConnection&);
- Fast_HTTPConnection& operator=(const Fast_HTTPConnection&);
-
-protected:
-
- bool _decode; // Decode incoming URLs?
- Fast_Socket *_socket;
- Fast_InputStream *_input;
- Fast_OutputStream *_output;
- Fast_HTTPServer *_server;
- bool _chunkedInput;
- bool _chunkedOutput;
- bool _keepAlive;
-
- vespalib::string _auth_user;
- vespalib::string _auth_pass;
-
- uint32_t _versionMajor;
- uint32_t _versionMinor;
- vespalib::string _httpVersion;
- vespalib::string _cookies;
-
-public:
-
- Fast_HTTPConnection(Fast_Socket *sock,
- bool decode = true,
- size_t inBufSize = 32768,
- size_t outbufSize = 32768);
-
- virtual ~Fast_HTTPConnection(void);
-
- void Run (FastOS_ThreadInterface *thisThread, void *params) override;
- void Output(const char *outputString);
- void OutputData(const void *data, size_t len);
- void OutputFile(FastOS_FileInterface *file);
-
- const Fast_InputStream *GetInputStream() const {return _input;}
- Fast_InputStream *GetInputStream() {return _input;}
-
- const Fast_OutputStream *GetOutputStream() const {return _output;}
- Fast_OutputStream *GetOutputStream() {return _output;}
-
- void Interrupt();
- unsigned short GetPort() const {return _socket == 0 ? 0 : _socket->GetPort();}
-
- const vespalib::string & AuthUser() { return _auth_user; }
- const vespalib::string & AuthPass() { return _auth_pass; }
-
- const vespalib::string & GetHTTPVersion() { return _httpVersion; }
- void SetKeepAlive(bool keepAlive = true) { _keepAlive = keepAlive; }
- bool GetKeepAlive() { return _keepAlive; }
-
- const vespalib::string & GetCookies() { return _cookies; }
-
-};
-
-
-
-class Fast_HTTPServerSocketFactory : public FastOS_SocketFactory
-{
-private:
- int _readTimeout; // Timeout value for reads.
-
-public:
-
- Fast_HTTPServerSocketFactory(int readTimeout = -1 /* no timeout */)
- : _readTimeout(readTimeout) {}
-
- /**
- * Create a streaming socket object
- */
- FastOS_SocketInterface *CreateSocket() override {
- return new Fast_Socket(_readTimeout);
- }
-};
-
-
-
-/*
- * Generic HTTP server class
- */
-class Fast_HTTPServer : public FastOS_Runnable
-{
-private:
- Fast_HTTPServer(const Fast_HTTPServer&);
- Fast_HTTPServer& operator=(const Fast_HTTPServer&);
-
- Fast_Bag<Fast_HTTPConnection*> _connections;
- std::mutex _connectionLock;
- std::condition_variable _connectionCond;
-
-protected:
- typedef vespalib::string string;
-
- /** Threadpool to use for new connections */
- FastOS_ThreadPool *_threadPool;
-
- /** Helper variables for backward compatibility. */
- FastOS_Thread *_acceptThread;
-
- /** Tells if the server is running */
- bool _isRunning;
- bool _isListening;
- bool _stopSignalled;
- std::mutex _runningMutex;
-
- /** Max number of concurrent threads */
- int _maxThreads;
-
- /** Base directory for web server content files */
- vespalib::string _baseDir;
-
- /** Flag indicating whether up (..) relative paths are
- * allowed for file requests */
- bool _allowUpRelativePath;
-
- /** Socket listening on desired port for incoming http connections */
- FastOS_ServerSocket _serverSocket;
-
- /** Decode incoming URLs? */
- bool _decode;
-
- /** Flag to allow keepAlive connections?, default true */
- bool _keepAlive;
-
- /** Socket factory for creating streamable Fast_Sockets */
- Fast_HTTPServerSocketFactory _serverSocketFactory;
-
- /** Buffer sizes for HTTPConnection objects */
- size_t _inBufSize;
- size_t _outBufSize;
-
- bool IsFileRequest(const string & url);
- void HandleFileRequest(const string & url, Fast_HTTPConnection& conn);
- void PushHtml(const string & url, Fast_HTTPConnection& conn);
- void OutputNotFound(Fast_HTTPConnection& connection,
- const string *url = NULL,
- bool addHeaders = true);
- int Listen(void);
-
-
-public:
- Fast_HTTPServer(int portNumber,
- const char* strictBindHostName = NULL, int backlog = 10,
- bool decode = true,
- int stackSize=128*1024, int maxThreads=0,
- int readTimeout = -1 /* No Timeout */);
-
- virtual ~Fast_HTTPServer(void);
-
- int getListenPort() { return _serverSocket.GetLocalPort(); }
-
- size_t GetInBufSize() { return _inBufSize; }
- size_t GetOutBufSize() { return _outBufSize; }
- void SetInBufSize(size_t inBufSize) { _inBufSize = inBufSize; }
- void SetOutBufSize(size_t outBufSize) { _outBufSize = outBufSize; }
-
- void SetBaseDir(const char *baseDir);
- void SetAllowUpRelativePath(bool allowUpRelativePath = true);
- bool GetAllowUpRelativePath();
-
- /** Method for turning off keepalive connections, or back on again.
- * Default value is true after the contructor is called.
- * @param keepAlive flag to allow HTTP/1.1 keep alive connections
- * */
- void SetKeepAlive(bool keepAlive = true) { _keepAlive = keepAlive; }
- bool GetKeepAlive() { return _keepAlive; }
-
- void Run (FastOS_ThreadInterface *thisThread, void *params) override;
-
- virtual int Start(void);
- virtual void Stop(void);
- virtual bool StopSignalled(void);
-
- /**
- * Callback for GET requests. Use it to send back your own set of headers,
- * and body parts.
- * @param url string that contains the URL given as parameter
- * to the GET request
- * @param host string that contains the HTTP/1.1 header "Host:" used
- * as part of the GET request.
- * @param connection Fast_HTTPConnection reference.
- * Call connection.Output() to output data back to
- * the client.
- */
- virtual void onGetRequest(const string & url,
- const string & host,
- Fast_HTTPConnection& connection);
-
- /**
- * Callback for writing the body part of a request. If you only
- * overload OnWriteBody(), the default OnGetRequest() will be called first
- * and will write a standard set of headers, then OnWriteBody will
- * be called to write out the rest of the reply.
- * @param url string that contains the URL given as parameter
- * to the GET request
- * @param host string that contains the HTTP/1.1 header "Host:" used
- * as part of the GET request.
- * @param connection A reference to the Fast_HTTPConnection.
- * Call connection.Output() to output data back to
- * the client.
- */
- virtual void OnWriteBody (const string & url,
- const string & host,
- Fast_HTTPConnection& connection);
-
- /**
- * Callback for receiving all data from a POST request, and writing
- * back a reply.
- * @param url string that contains the URL given as parameter
- * to the POST request. This is used to indicate what
- * 'script' should be used to process the data.
- * @param host string that contains the HTTP/1.1 header "Host:" used
- * as part of the POST request.
- * @param contentType string containing the Content-Type: header as
- * given by the HTTP client
- * @param contentLength int value containing the Content-Length: header
- * as given by the HTTP client
- * @param conn A reference to the Fast_HTTPConnection.
- * Call connection.Output() to output data back to
- * the client.
- * @param inputStream Use this Fast_InputStream to read the POST data
- * @param outputStream Use this Fast_OutputStream to output data back
- * to the client.
- */
- virtual void OnPostRequest( const string & url,
- const string & host,
- const string & contentType,
- int contentLength,
- Fast_HTTPConnection& conn,
- Fast_InputStream& inputStream,
- Fast_OutputStream& outputStream);
-
- /**
- * Callback for receiving all data from a PUT request, and writing
- * back a reply.
- * @param url string that contains the URL given as parameter
- * to the PUT request. This URL is used to indicate where the
- * data should be placed.
- * @param host string that contains the HTTP/1.1 header "Host:" used
- * as part of the PUT request.
- * @param contentType string containing the Content-Type: header as
- * given by the HTTP client
- * @param contentLength int value containing the Content-Length: header
- * as given by the HTTP client
- * @param conn A reference to the Fast_HTTPConnection.
- * Call connection.Output() to output data back to
- * the client.
- * @param inputStream Use this Fast_InputStream to read the PUT data
- * @param outputStream Use this Fast_OutputStream to output data back
- * to the client.
- */
- virtual void OnPutRequest( const string & url,
- const string & host,
- const string & contentType,
- int contentLength,
- Fast_HTTPConnection& conn,
- Fast_InputStream& inputStream,
- Fast_OutputStream& outputStream);
-
- /**
- * Callback for receiving all headers for a DELETE request, and writing
- * back a reply.
- * @param url string that contains the URL given as parameter
- * to the DELETE request. This URL should be deleted from
- * the system in one way or another.
- * @param host string that contains the HTTP/1.1 header "Host:" used
- * as part of the PUT request.
- * @param connection A reference to the Fast_HTTPConnection.
- * Call connection.Output() to output data back to
- * the client.
- */
- virtual void OnDeleteRequest(const string & url,
- const string & host,
- Fast_HTTPConnection& connection);
-
- /**
- * Callback for unknown requests.
- * @param url string that contains the URL given as parameter
- * to the DELETE request. This URL should be deleted from
- * the system in one way or another.
- * @param host string that contains the HTTP/1.1 header "Host:" used
- * as part of the PUT request.
- * @param connection A reference to the Fast_HTTPConnection.
- * Call connection.Output() to output data back to
- * the client.
- */
- virtual void OnUnsupportedRequest(const string & url,
- const string & host,
- Fast_HTTPConnection& connection);
-
- void AddConnection(Fast_HTTPConnection* connection);
- void RemoveConnection(Fast_HTTPConnection* connection);
-
-};
diff --git a/fastlib/src/vespa/fastlib/net/resolver/.gitignore b/fastlib/src/vespa/fastlib/net/resolver/.gitignore
deleted file mode 100644
index f2f82e4465f..00000000000
--- a/fastlib/src/vespa/fastlib/net/resolver/.gitignore
+++ /dev/null
@@ -1,16 +0,0 @@
-*.So
-*.a
-*.ilk
-*.lib
-*.o
-*.obj
-*.pdb
-.cvsignore
-.depend
-.pure
-Debug
-Makefile
-SunWS_cache
-hostlist
-resolvertest
-resolvertest.exe
diff --git a/fastlib/src/vespa/fastlib/net/resolver/tests/.gitignore b/fastlib/src/vespa/fastlib/net/resolver/tests/.gitignore
deleted file mode 100644
index c1c732aedcb..00000000000
--- a/fastlib/src/vespa/fastlib/net/resolver/tests/.gitignore
+++ /dev/null
@@ -1,15 +0,0 @@
-*.a
-*.ilk
-*.lib
-*.o
-*.obj
-*.pdb
-.cvsignore
-.depend
-.pure
-Debug
-Makefile
-SunWS_cache
-hostlist
-resolvertest
-resolvertest.exe
diff --git a/fastlib/src/vespa/fastlib/net/socket.cpp b/fastlib/src/vespa/fastlib/net/socket.cpp
deleted file mode 100644
index aaab1984544..00000000000
--- a/fastlib/src/vespa/fastlib/net/socket.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "socket.h"
-
-Fast_Socket::~Fast_Socket()
-{
-}
-
-bool
-Fast_Socket::Close(void)
-{
- return FastOS_Socket::Close();
-}
-
-ssize_t
-Fast_Socket::Read(void* targetBuffer, size_t bufferSize)
-{
- bool oldReadEventEnabled = _readEventEnabled;
- FastOS_SocketEvent* oldSocketEvent = _socketEvent;
- void* oldEventAttribute = _eventAttribute;
- bool err = false;
- bool eventOcc = false;
- ssize_t rtrn = -1;
-
- errno = 0;
- _lastReadTimedOut = false;
-
- if (_event.GetCreateSuccess() == false)
- return rtrn;
-
- if (SetSocketEvent(&_event) == true)
- {
- EnableReadEvent(true);
- eventOcc = _event.Wait(err, _readTimeout);
- if (eventOcc == true && err == false)
- {
- rtrn = FastOS_Socket::Read(targetBuffer, bufferSize);
- _eof = (rtrn == 0);
- }
- else if(!eventOcc && !err)
- {
- _lastReadTimedOut = true;
- }
- }
-
- SetSocketEvent(oldSocketEvent, oldEventAttribute);
-
- if (oldSocketEvent != 0)
- EnableReadEvent(oldReadEventEnabled);
-
- return rtrn;
-}
-
-void
-Fast_Socket::Interrupt()
-{
- _event.AsyncWakeUp();
-}
-
-ssize_t
-Fast_Socket::Write(const void *sourceBuffer, size_t bufferSize)
-{
- return FastOS_Socket::Write(sourceBuffer, bufferSize);
-}
diff --git a/fastlib/src/vespa/fastlib/net/socket.h b/fastlib/src/vespa/fastlib/net/socket.h
deleted file mode 100644
index 7328d12b25b..00000000000
--- a/fastlib/src/vespa/fastlib/net/socket.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/fastlib/io/inputstream.h>
-#include <vespa/fastlib/io/outputstream.h>
-#include <vespa/fastos/socket.h>
-
-class Fast_Socket : public FastOS_Socket,
- public Fast_InputStream,
- public Fast_OutputStream
-{
-private:
- Fast_Socket(const Fast_Socket&);
- Fast_Socket& operator=(const Fast_Socket&);
-
- FastOS_SocketEvent _event;
- int _readTimeout;
- bool _lastReadTimedOut;
- bool _eof;
-
-public:
-
- /**
- * The Fast_Socket constructor creates a new socket instance
- *
- * @param msReadTimeout Number of milliseconds to wait for an event
- * before timeout. -1 means wait forever.
- */
- Fast_Socket(int msReadTimeout = -1 /* no timeout */)
- : _event(),
- _readTimeout(msReadTimeout),
- _lastReadTimedOut(false),
- _eof(false)
- {
- }
-
- ~Fast_Socket();
-
- ssize_t Write(const void *sourceBuffer, size_t bufferSize) override;
- ssize_t Read(void *targetBuffer, size_t bufferSize) override;
- bool Close() override;
-
- bool LastReadTimedOut() { return _lastReadTimedOut; }
- bool SeenEOF() { return _eof; }
-
- Fast_InputStream &GetInputStream() { return *this; }
- Fast_OutputStream &GetOutputStream() { return *this; }
-
-
- // Implementation of Fast_InputStream and Fast_OutputStream interfaces
-
- void Flush() override { }
- ssize_t Available () override { return 0; }
- ssize_t Skip (size_t skipNBytes) override { (void) skipNBytes; return -1; }
-
- void Interrupt();
-};
diff --git a/fastlib/src/vespa/fastlib/net/tests/.gitignore b/fastlib/src/vespa/fastlib/net/tests/.gitignore
deleted file mode 100644
index 44dc68377da..00000000000
--- a/fastlib/src/vespa/fastlib/net/tests/.gitignore
+++ /dev/null
@@ -1,19 +0,0 @@
-*.So
-*.a
-*.exe
-*.ilk
-*.o
-*.obj
-*.pdb
-.cvsignore
-.depend
-.pure
-Debug
-Makefile
-SunWS_cache
-httpclientperf
-httpclienttest
-httpheaderparsertest
-httpserverbabble
-httpservertest
-fastlib_httpheaderparsertest_app
diff --git a/fastlib/src/vespa/fastlib/net/tests/CMakeLists.txt b/fastlib/src/vespa/fastlib/net/tests/CMakeLists.txt
deleted file mode 100644
index 1c05a2fc5fb..00000000000
--- a/fastlib/src/vespa/fastlib/net/tests/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(fastlib_httpheaderparsertest_app TEST
- SOURCES
- httpheaderparsertest.cpp
- DEPENDS
- fastlib_fast
-)
-vespa_add_test(NAME fastlib_httpheaderparsertest_app NO_VALGRIND COMMAND fastlib_httpheaderparsertest_app ${CMAKE_CURRENT_SOURCE_DIR}/headers.txt)
diff --git a/fastlib/src/vespa/fastlib/net/tests/headers.txt b/fastlib/src/vespa/fastlib/net/tests/headers.txt
deleted file mode 100644
index 4fd2782cfec..00000000000
--- a/fastlib/src/vespa/fastlib/net/tests/headers.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-Normal-header: value
-Header-with-spaces : multiple values
- Invalid-header-with-leading-spaces: bogus values
-Normal-header-CR: value
-Header-with-spaces-CR : multiple values
- Invalid-header-with-leading-spaces-CR: bogus values
-Header-with-multiple-lines: value one,
- value two,
- value three,
- end
-
-
-Text at end.
diff --git a/fastlib/src/vespa/fastlib/net/tests/httpheaderparsertest.cpp b/fastlib/src/vespa/fastlib/net/tests/httpheaderparsertest.cpp
deleted file mode 100644
index 9a0b1450454..00000000000
--- a/fastlib/src/vespa/fastlib/net/tests/httpheaderparsertest.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/fastos/app.h>
-#include <vespa/fastlib/net/httpheaderparser.h>
-#include <vespa/fastlib/io/fileinputstream.h>
-#include <vespa/fastlib/io/bufferedinputstream.h>
-
-class HeaderReaderApp : public FastOS_Application
-{
-public:
- int Main() override
- {
- if (_argc != 2)
- {
- fprintf(stderr, "Usage: %s <header file>\n", _argv[0]);
- return 1;
- }
- Fast_FileInputStream fileinput(_argv[1]);
- Fast_BufferedInputStream input(fileinput, 32768);
- Fast_HTTPHeaderParser headerParser(input);
-
- const char *headerName, *headerValue;
- while (headerParser.ReadHeader(headerName, headerValue))
- {
- printf("Header name: \"%s\"\n", headerName);
- printf("Header value: \"%s\"\n", headerValue);
- printf("\n");
- }
-
- char buffer[1024];
- size_t bytesRead = 0;
- ssize_t lastRead;
- printf("------> Remaining data in file: <------\n");
- while ((lastRead = input.Read(buffer, sizeof(buffer))) > 0)
- {
- fwrite(buffer, 1, lastRead, stdout);
- bytesRead += lastRead;
- }
- printf("------> End of remaining data <--------\n");
- printf("Total remaining data: %u bytes\n",
- static_cast<unsigned int>(bytesRead));
-
- return 0;
- }
-};
-
-
-
-
-int main (int argc, char *argv[])
-{
- HeaderReaderApp app;
-
- return app.Entry(argc, argv);
-}
diff --git a/fastlib/src/vespa/fastlib/net/transport/.gitignore b/fastlib/src/vespa/fastlib/net/transport/.gitignore
deleted file mode 100644
index aa9c3f19188..00000000000
--- a/fastlib/src/vespa/fastlib/net/transport/.gitignore
+++ /dev/null
@@ -1,13 +0,0 @@
-*.So
-*.a
-*.ilk
-*.lib
-*.o
-*.obj
-*.pdb
-.cvsignore
-.depend
-.pure
-Debug
-Makefile
-SunWS_cache
diff --git a/fastlib/src/vespa/fastlib/net/transport/tests/.gitignore b/fastlib/src/vespa/fastlib/net/transport/tests/.gitignore
deleted file mode 100644
index 94be1c783fd..00000000000
--- a/fastlib/src/vespa/fastlib/net/transport/tests/.gitignore
+++ /dev/null
@@ -1,31 +0,0 @@
-*.dsp
-*.ilk
-*.o
-*.obj
-*.pdb
-*.plg
-.depend
-Debug
-Makefile
-destinationmonitor
-destinationmonitor.exe
-multinetworkdestinationmonitor
-multinetworkdestinationmonitor.exe
-multinetworkreceiver
-multinetworkreceiver.exe
-multinetworksender
-multinetworksender.exe
-proxyreceiver
-proxyreceiver.exe
-receiver
-receiver.exe
-sender
-sender.exe
-sequencertest
-sequencertest.exe
-tcpipfttestnode
-tcpipfttestnode.exe
-tcpiptestdaemon
-tcpiptestdaemon.exe
-tcpiptestnode
-tcpiptestnode.exe
diff --git a/fastlib/src/vespa/fastlib/net/url.cpp b/fastlib/src/vespa/fastlib/net/url.cpp
deleted file mode 100644
index 39a49777225..00000000000
--- a/fastlib/src/vespa/fastlib/net/url.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/**
- * This file contains different URL string functions
- *
- * Author: Michael Susæg
- */
-
-
-#include "url.h"
-#include <cstdio>
-
-void
-Fast_URL::decode(const char *encodedURL, char *decodedURL, int bufsize)
-{
- const char *tmpPtr;
- unsigned int charVal;
- char *bufend = decodedURL + bufsize;
-
- tmpPtr = encodedURL;
-
- /* Parse the whole encodedURL */
- while(decodedURL < bufend && *tmpPtr != '\0') {
- /* Check if an encoded character is the next one */
- if(*tmpPtr == '%') {
- tmpPtr++; /* Skip % character */
- sscanf(tmpPtr,"%02X", &charVal);
- *decodedURL = static_cast<char>(charVal);
- tmpPtr += 2;
- }
- else
- {
- *decodedURL = *tmpPtr;
- tmpPtr++;
- }
- decodedURL++;
- }
- if (decodedURL < bufend)
- *decodedURL = '\0';
-}
-
-int Fast_URL::DecodeQueryString(char *queryString)
-{
- int numReplaced = 0;
-
- for(int i=0; queryString[i] != '\0'; i++)
- {
- if (queryString[i] == '+')
- {
- queryString[i] = ' ';
- numReplaced ++;
- }
- }
-
- return numReplaced;
-}
diff --git a/fastlib/src/vespa/fastlib/net/url.h b/fastlib/src/vespa/fastlib/net/url.h
deleted file mode 100644
index 2dd4827b0db..00000000000
--- a/fastlib/src/vespa/fastlib/net/url.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/*
- * Author: Michael Susæg
- */
-
-#pragma once
-
-
-
-class Fast_URL
-{
-public:
- void decode(const char *encodedURL, char *unencodedURL, int bufsize);
- /* bufsize is the length of the unencodedURL buffer */
-
- /* Both methods return the number of chars replaced */
- int DecodeQueryString(char *queryString);
-};
diff --git a/fastlib/src/vespa/packages/CMakeLists.txt b/fastlib/src/vespa/packages/CMakeLists.txt
index aff77cf556c..8dbf405eda9 100644
--- a/fastlib/src/vespa/packages/CMakeLists.txt
+++ b/fastlib/src/vespa/packages/CMakeLists.txt
@@ -1,7 +1,6 @@
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
vespa_add_library(fastlib_fast
SOURCES
- $<TARGET_OBJECTS:fastlib_net>
INSTALL lib64
DEPENDS
fastlib_text